-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
57 lines (46 loc) · 955 Bytes
/
Copy pathBlock.java
File metadata and controls
57 lines (46 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.example.tetris2;
import java.util.Arrays;
public class Block {
private int[][] mBlock;
public Block(){
mBlock=new int[TetrisView.XCOUNT][TetrisView.YCOUNT];
}
public int get(int x,int y){
return mBlock[x][y];
}
public void set(int color,int x,int y){
mBlock[x][y]=color;
}
private boolean isFull(int position){
int value=1;
for(int i=0;i<TetrisView.YCOUNT;i++){
value&=mBlock[position][i];
if(value==0)
return false;
}
return true;
}
private void fallDown(int position){
int[] tmp=mBlock[position];
Arrays.fill(tmp, 0);
for(int i=position;i>0;i--){
mBlock[i]=mBlock[i-1];
}
mBlock[0]=tmp;
}
public void check(int position){
for(int i=0;i<4;i++){
if(isFull(position))
fallDown(position);
else{
position--;
}
}
}
public void clear() {
// TODO Auto-generated method stub
for(int i=0;i<TetrisView.XCOUNT;i++){
Arrays.fill(mBlock[i], 0);
}
}
}