Gettysburg College

CS 111
Computer Science I

Fall 2025

Assignment 8

Due: Thu, Oct 30, by 11:59pm

General Description

The goal of this assignment is to create an app for the popular game MineSweeper. The focus is on nested loops and 2D array (matrix/table) processing.

Write the methods described below. Make sure to test each method carefully before moving on to the next one.

Use nested loops in the methods you write.

Preliminaries

Start DrJava and create a new project named MineSweeperApp in folder cs111/hw . See the Readings List notes on how to create a new project.

For this app the phone should be put in portrait orientation.

Preliminaries (New DrJava)

Download the new version of DrJava:

This DrJava version includes:

Game Description

MineSweeper is a popular game and is available on most computer and phone platforms. Play the game a few times to get familiar with the rules and begin to think about a possible design and implementation.

MineSweeper Online

The rules of the game are fairly simple. It is a one-player game in which the player is shown initially a blank board of square cells:

The player wins when all safe cells are opened and all unsafe cells are marked/flagged. The game is lost when the player opens a hidden mine.

Images and Conventions

Here are the images for the app. Extract the zip file in the app folder MineSweeperApp/res/raw/. Separately, save in the same folder all smiley images (right-click, Save As):

mine imagessmiley images
mines.zip

The images have size 36x36 and you may use this as fixed number.

The names of all images have the following format:

mX.png where X is a number in 0..29

The game board will be represented as 2D array (table) of integers. Here are the possible values that can be stored in a the 2D array (table) and their corresponding meaning

Example ImageExplanation

m7.png
0..8 (hidden cells)

these numbers indicate that the cell has 0 to 8 adjacent mines; the cell has not been revealed to the player

these fuzzy images are used for testing; in the final version we draw hidden.png


m17.png
10..18 (revealed cells)

these numbers indicate that the cell has been revealed; the corresponding image is shown to the player


m27.png
20..28 (flagged cells)

these numbers indicate that the cell has been flagged; the image of a flag is shown to the player

m9.png 9, 19, 29 (mine cells)

these numbers indicate a hidden mine (9) a revealed mine (19) and a flagged mine (29)


hidden.png
this image is displayed in the final version of the game for cells with numbers 0..9 instead of the fuzzy images

Here is the meaning of these numbers from the programmer's point of view:

The player wins when the cells in the field contain only the numbers 10 to 18 (revealed number cells) and 29 (flagged mines).

Game Methods

Write the following methods:

What to turn in

Turn in the Java code for the app in the Assignment 8 dropbox:

Make sure your code is saved. If when you close DrJava it warns you that the file is not saved, save it and re-upload the code.