public class MyBombGame extends BombGame {
// ***************** consider this part as read-only! *************************
/**
* main
* initializes the game data structures, communicates with the gamer,
* hosts the main game loop, updates the GUI and ends the game!
*/
public static void main(String[] args) {
int width = 8, length = 8;
// Board (width x length) is filled with bombs (0) and rest is covered (-1)
int[][] board = generateBoard(width,length);
// Board is given to GUI
initBombgame(board);
// Fetch coordinates of mouse-click
int[] xy = mouseCoordinates();
// Repeat main loop while clicks are performed
while (xy != null) {
// Uncover field at coordinates (xy[0]/xy[1])
if (uncover(board, xy[0], xy[1])){
// no bomb -> transmit new board to GUI
updateGraphics(board);
// fetch next mouse-click
xy = mouseCoordinates();
}
else {
// bomb! -> end loop and exit game!
xy = null;
// informs the gamer, that (s)he has stepped into a bomb
alert();
}
}
}
/**
* neighbourBombs
* is called from the GUI
* @param board contains all bombs (0), covered (-1) and uncovered (1) fields
* @param x is the x-coordinate of the field in board for which to compute the number of neighbours
* @param y is the y-coordinate of the field in board for which to compute the number of neighbours
* @return the number of vertical, horizontal and diagonal adjacent bombs
*/
public static int neighbourBombs(int[][] board, int x, int y) {
// compute the number of bombs, vertically, horizontally and diagonally adjacent to x/y within board
return countNeighbourBombs(board,x,y);
}
// ******************* start editing here! ***********************************
}