-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
50 lines (47 loc) · 1.58 KB
/
Copy pathGame.java
File metadata and controls
50 lines (47 loc) · 1.58 KB
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
package colorbusterdev;
// Represents the game state and logic
class Game {
private Board board;
private int score;
//Game constructor
public Game(int boardSize) {
this.board = new Board(boardSize);
this.score = 0;
}
//Gets board
public Board getBoard(){
return board;
}
//Starts Game
public void startGame(int boardSize) {
score = 0;
board = new Board(boardSize);
}
//Gets score
public int getScore(){
return score;
}
//Updates Score
public void updateScore(int points) {
score += points;
}
//Check Match Method
public void checkMatches(int row, int col) {
Tile[][] grid = board.getGrid();
int size = board.getSize();
// Get the color of the selected tile
String color = grid[row][col].getColor();
// Check for horizontal matches around the selected tile
if (col >= 2 && color.equals(grid[row][col-1].getColor()) && color.equals(grid[row][col-2].getColor())) {
// Handle matching tiles
// For example, update the score
updateScore(10); // Assuming 10 points per match
}
// Check for vertical matches around the selected tile
if (row < size - 2 && color.equals(grid[row+1][col].getColor()) && color.equals(grid[row+2][col].getColor())) {
// Handle matching tiles
// For example, update the score
updateScore(10); // Assuming 10 points per match
}
}
}