-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameBoard.pde
111 lines (86 loc) · 2.19 KB
/
GameBoard.pde
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
class GameBoard {
int boardWidth;
int boardHeight;
int currentScore = 0;
GameBoard(int w, int h) {
boardWidth = w;
boardHeight = h;
}
void update() {
// Check line whether it is full
for (int i = 0; i < boardBlocks02.length; i++) {
int lineCount = 0;
for (int j = 0; j < boardBlocks02[i].length; j++) {
if (boardBlocks02[i][j] == 1) {
lineCount++;
rowCount[i] = lineCount;
}
}
}
// Remove line if it is full
for (int i = 0; i < rowCount.length; i++) {
if (rowCount[i] == 10) {
for (int j = 0; j < boardBlocks02[i].length; j++) {
boardBlocks02[i][j] = 0;
rowCount[i] = 0;
}
// Lower the blocks once the line is removed underneath
lowerBlocks(i);
}
}
}
void lowerBlocks(int i) {
for (int j = i; j > 0; j--) {
for (int k = 0; k < boardBlocks02[j].length; k++) {
boardBlocks02[j][k] = boardBlocks02[j-1][k];
}
}
score++;
b.currentScore++;
}
void level() {
if (currentScore == 5) {
level++;
frameSpeed++;
currentScore = 0;
}
}
void render() {
stroke(theme.blockStroke);
fill(theme.block);
for (int i = 0; i < boardBlocks02.length; i++) {
for (int j = 0; j < boardBlocks02[i].length; j++) {
if (boardBlocks02[i][j] == 1) {
rect(j*scl, i*scl, scl, scl);
}
}
}
}
void death() {
if (rowCount[0] > 1) {
gameOver();
}
}
void gameOver() {
fill(255, 0, 0);
textSize(30);
textAlign(CENTER);
text("GAME OVER", b.boardWidth/2*scl, b.boardHeight/2*scl);
textAlign(CENTER, TOP);
text("PRESS 'R' TO RESTART", b.boardWidth/2*scl, b.boardHeight/2*scl);
blocks.clear();
sideTest.clear();
bottomTest.clear();
for (int i = 0; i < boardBlocks02.length; i++) {
for (int j = 0; j < boardBlocks02[i].length; j++) {
boardBlocks02[i][j] = 0;
}
rowCount[i] = 0;
}
noLoop();
if (score > highScore) {
highScore = score;
}
level = 0;
}
}