General Description of Code
Assumptions:
- The user knows how to turn on the Proteus and use a stylus to operate the touch screen display.
- The user is able to accurately touch the screen with the stylus to select small boxes.
- The Proteus is working properly and is charged.
- This program is to only be used on the Proteus hardware
MineSweeper Code Variable List
Description of Main Function
In the main function, the title screen is displayed for a few seconds before the menu interface is displayed. The options for the menu are displayed in the center of the screen. These options include viewing the rules, playing easy mode, hard mode, viewing statistics, and credits. If the screen is touched at the location of one of the menu items, the screen is cleared and goes to the respective option. The rule option displays the rules on 3 pages, the program waits until the screen is touched to go to the next page and return back to the menu after all three pages have been touched. The easy option calls the easygame function (described below) and after the function executes the program returns to the menu interface. The hard option calls the hardgame function (described below) and after the function executes the program returns to the menu interface. The view statistics prints the number of wins and losses for easy mode and hard mode. The number of wins and losses are stored in the wins, losses, hardwins, and hardlosses variables that are incremented in the easygame and hardgame functions. The program returns to the menu once the screen is touched. The credit option displays the makers of the game and any references they used, the program returns to the menu interface when the screen is touched.
Function Descriptions
void easygame( *wins, *losses)
This function has two pointers two pointers to the wins and losses variables. This function draws a 7×7 grid and generates a 7×7 array filled with zeroes that represents the graphical display grid. The function then generates 12 randomly placed bombs within the grid by generating 12 random row and column numbers and replacing a zero with a one at that location. When the player touches the screen, the function translates the location of the touch to a row and column number. This row and column number are then checked to see whether there is a 1 or a 0 in that section of the array. If there is a one then the function writes “BOOM” to the screen, increments the number of wins by using the pointer to the win variable, and ends the function (which returns to the menu in the main function). If there is a zero, the function checks all the squares around the selected square for bombs. Different if statements are required for each corner piece, the different sides, and the center box because there are a different number of squares adjacent to those sections. The number of bombs is then printed to the square of the grid that was touched. The function then turns that location in the array to a 2 so that if the same square is selected nothing will happen and so that the array can be summed to see if someone wins. The array is then summed to see if the number there are only 2s and 1s left and if that is the case then the pointer to the win variable is used to increment wins, “YOU WIN” is printed to the screen, and the function exits to the main function to the menu.
void hardgame( *hardwins, *hardlosses)
This function has two pointers two pointers to the hardwins and hardlosses variables. This function draws a 9×9 grid and generates a 9×9 array filled with zeroes that represent the graphical display grid. The function then generates 18 randomly placed bombs within the grid by generating 18 random row and column numbers and replacing a zero with a one at that location. When the player touches the screen, the function translates the location of the touch to a row and column number. This row and column number are then checked to see whether there is a 1 or a 0 in that section of the array. If there is a one then the function writes “BOOM” to the screen, increments the number of wins by using the pointer to the win variable, and ends the function (which returns to the menu in the main function). If there is a zero, the function checks all the squares around the selected square for bombs. Different if statements are required for each corner piece, the different sides, and the center box because there are a different number of squares adjacent to those sections. The number of bombs is then printed to the square of the grid that was touched. The function then turns that location in the array to a value of 2 so that if the same square is selected nothing will happen and so that the array can be summed to see if someone wins. The array is then summed to see if the number there are only 2s and 1s left and if that is the case then the pointer to the win variable is used to increment wins, “YOU WIN” is printed to the screen, and the function exits to the main function to the menu.
Beta Test Feedback
What I liked:
The game works! (Job well done!) I especially like the BOOM screen.
Improve:
You could change the grids to not go off of the edge of the screen.
Overall Opinion:
I was very impressed. Again, good job. The game is everything one could want in handheld minesweeper!
-Joanne E. Ash & Sameer Goyal
This feedback was taken into serious consideration. The grid lines for the game boards were adjusted to try and fit completely on the screen. Additionally, adjustment ot the random bomb generation was made to remove bombs from being placed in the same square at the start of this game. This problem disallowed the user from winning as the sum of the array compnents would not equal the previously determined amount. This was fixed by adjusting the for loop that paced the bombs to ensure bombs could not be placed in the same place.