C. Program Description for Developers

The program is divided into six sections:
A.Creating the board
To construct the game board, we used the “figure” function to set up a ten by ten grid and used “gininput” to get the x and y position of where the mouse clicks.

B.Initialized tiles and generating bombs:
By introducing a 2-D array, or cell, we were able to create a ten by ten matrix representing each tile on the game board, with each cell having its individual properties such as position, if it’s revealed, or if it’s a mine.

We then used “randi” function and a while loop to generate x, y coordinates randomly until 16 mines are all created without overlapping.

C. Count surrounding mines
To assign each tile with a number of how many mines are surrounding it, we used a nested for-loop to count the number of mines surrounded. However, for the tiles on the edge of the gameboard, fewer tiles are surrounding. So we also have to consider these exceptional cases by using if-else statements to check if the tiles selected are on edge.

 

D.Reveal the clicked tile:
After getting the mouse-clicked-coordinate, the “reveal” function will check for the “revealed property” and the “mine property” of the clicked tile. If the tile is not a mine, then display the number of mines surrounding the tile, set “revealed” to true. If the clicked tile is a mine, you lose.

E.Reveal the surrounding tiles if the clicked tile has no mine near it.
To reveal all the surrounding tiles, we used a technique known as recursion.
In the “revealSurroundings” function, if the clicked tile has 0 mines surrounding it and is not revealed, check for the tile on its left. If the tile on the left has a number less than 9(with greater than or equal to 9 representing a mine), call the “revealSurroundings” again. Do the same procedure for all four directions. By using recursion, or a function calling itself, we were able to achieve the goal of revealing all non-mine tiles surrounding the clicked tile while not skipping on an unrevealed tile.

F.Deciding winning or losing:
all the components introduced above except board and cell initialization are incorporated in a while loop, with an initial boolean variable “gameOver” set to false as the condition. For the while loop, if the game is not over, get the clicked mouse coordinate, reveal the tile, and reveal the surrounding tiles. If the user clicks on a mine tile, the “gameover” will be set to true, hence breaks the while loop. A “you lost” alert window will then show up. After all tiles that are not mine have been revealed(the only ones left are all mines), gameover will be set to true, a “you won” alert window will then show up.