[Week 7] Midterm project – Minehunter

For the midterm, as per the last update, I work on the game Minehunter.

All the code and the files can be found here. Do be mindful of the folders in which the files are organized. The program will not run if the files are not in the correct folders with correct names. A zip file can also be found at the end of the post.

The game includes an 8×8 game board containing 8 mines scattered randomly across the board. The goal for the player is to uncover all of these hidden mines while maximizing their points. The player can move their character around the board using arrow keys (the current position is highlighted for better visibility). If the player thinks a cell has a mine, they can flag that cell by navigating to the cell then pressing the ‘F’ button. If the player changes their mind, they can press the ‘F’ button again to un-flag the cell. Otherwise, if they thinks a cell is safe, they can reveal the cell using the space bar. Once a safe cell is revealed, the cell shows a number representing how many of its neighbor cells have mines. ‘Neighbor cells’ are defined to be adjacent cells horizontally, vertically, and diagonally. These numbers are visible only when the player is in that cell. Each safe cell uncovered earns the player 2 points. There is also a Hint button that the player can click on to uncover a random safe cell, which costs 10 points.

The player either wins by successfully flagging all cells with mines, or loses by revealing a cell with a mine.

My main goal for this game is to increase player interactions. The rules of the game requires the player to navigate their character across the game board consistently to reveal or flag a cell and to revisit revealed cells, since numbers of neighbor mines are only visible for the current cell. More player movements are also required by the two goals of the game: to flag all mines, and to achieve higher points by revealing more safe cells.

Here is a short demo of my game (excuse my bad playing for the sake of the demo):

Breakdown of classes


This is the class for the entire game session. The most important attributes of this class are the various ArrayLists of PVectors. They store the coordinates of various cells for different purposes as specified by the names of the ArrayLists. I choose to use ArrayLists extensively because they support a wide range of functions suitable for my intentions: add() and size() can be used to quickly add new elements to the arrays and get their sizes without me having to manually keep track of array sizes; contains() can be used to check whether a certain object is included in an array instead of iterating through each element and making comparison and similarly with remove() for removing an object without knowing the specific index; clear() can be used to quickly remove all elements from the arrays, which is useful for resetting the game.

The Minehunter class also contains a range of functions for displaying the various screens, including the welcome screen, instruction screen, as well as win/loss screen. The core operation of these displaying functions is changing the global variable screen to reflect the current screen state, which is used in the switch statement in the main program to display the correct screen. Additionally, the class has a number of functions for different player actions like planting flags, revealing cells, getting hints, etc. and for resetting the game.


This is the class for the player which displays and moves the player’s character around the game board. The class is also used to display the animated character in the welcome screen which moves automatically instead of waiting for keyboard signals like the player’s character during the game. The implementation of the Player class reuses the code from the lecture on images and sprite sheets.


This is a simple class for keeping track, updating, and displaying the player’s points.


My main issue is with the design of the game. I wanted to make the graphics more in the style of 8-bit games, but using 8-bit arts as the background for the game board, for some reason, slows down the game significantly. I left the function for displaying the background in the code but I didn’t use it, since I tried it on my laptop and the character’s movement slowed down as if the frame rate were changed. So in the end I settled with a amalgamation of 8-bit design and flat design.

Another problem I had was with the choice of fonts. The majority of texts in the game use a pixel game style font, but I figured the font does not look very legible when the texts are packed, or when uppercase and lowercase letters stand next to each other. So for the instruction screen, I used a different font for the sake of legibility.

One of the most important requirements for the program is to be able to store coordinates in the form (i, j). I initially intended to use the tuple data type, but apparently Processing does not support tuples in Java (it does in Python). My second plan was encoding the coordinates into strings of the form "ij" using the formula i*10+j and later on reverse the encoding using the / and % operations. Then there came the lecture on PVector which was exactly what I needed, and so I switched to use PVectors throughout my program. It was really useful and saved me a lot of time and effort.


The implementation of the Player class reuses the code from the lecture on images and sprite sheets.

Some of the underlying game logics and operations are reused from an assignment I did for another course.



Leave a Reply