The game of Minesweeper requires a player to determine the location of “mines” hidden randomly throughout a two dimensional grid i.e. “minefield”. Each of the grid locations is initially covered by a tile. The player may open a tile, flag a tile as a mine location, or set a tile as a question mark. Clues describing the number of adjacent mines to a tile are displayed when the player opens a tile. A player “wins” by opening all of the non-mine tiles. A player loses when they open a tile containing a mine.
range of topics can be covered with this assignment. It can be
used to demonstrate two-dimensional
array processing including passing
arrays to functions/procedures/methods, object-oriented design and programming,
and GUI design and programming,
for CS1, CS2, a course that covers OOP, or programming of GUI's.
I have used variations of the assignment in CS1 (more like CS1.5) class using Java. I have also used the problem in a post CS2 course focusing on Visual BASIC programming.
assignment is "nifty" because it can cover and integrate a wide range of programming topics.
The problem can be used in a sequence of assignments covering array
processing, OOP, and GUI"s. Subsets of the problem can
also be chosen such as such as array processing or recursion. The
assignment is platform independent.
The application concept takes little explanation as students are quite
familiar with the game. There are also many opportunities to take the
assignment "above and beyond".
sometimes hard for
students to visualize the minesweeper problem in discrete
components. It is important to clearly outline expectations.
A full GUI interactive version can be fairly complicated.
the use of arrays and methods. Option #2 requires OOP. Option #3
requires GUI components. When
implementing the full GUI application, the degree of difficulty may
vary based on the GUI toolkits available.
||Option #1 - Static Methods and Array
The assignment can be used as two-dimensional array processing assignment, passing arrays to functions/procedures/methods. Note: Objects-First people goto option #2
Sample Assignment - Option #1 - Static Methods and Array Processing
|Option #2 - OOP
The assignment can be used as an object-oriented design and programming assignment. Students can build a class design based on the instructors choice of data and methods or be asked to design their own classes. Instructors may choose to use Option #1 for a comparison between OOP and non-OOP program design.
Sample Assignment - Option #2 - OOP
|Option #3 - GUI
The assignment can be used for GUI design and programming. The GUI can use the minesweeper class developed in Option #2.
Sample Assignment - Option #3 - GUI
Options #1 & #2 can require the use of recursion. When the user opens a blank tile all adjacent tiles should be opened. A recursive algorithm can be used to solve this problem. Instructors may want to provide an overview of this approach.