Final project for the course 项目实践 in 2020 spring.
Team Member: 汪能志 周瀛 马明慧 杨雨薇
This project was designed based on the requirements of PracticeOfComputingUsingPython/08_ClassDesign/Minesweeper from http://www.cse.msu.edu/~cse231/PracticeOfComputingUsingPython/.
We completed the main algorithms of minesweeper, and implemented a simple graphical user interface by tkinter
.
The project has a unit test file to test key algorithms. The unit testing process is done primarily through GitHub and Travis CI.
We created a class called Mine_Map
for minesweeper in the file './Mine_Map.py'. It contains data structures for storing map data and provides the following functions.
-
Based on the first selected grid, mines are randomly placed on the map and the number of mines around each grid is calculated.
-
If the player clicks a unknown grid, the number is now visible to the player.
-
If the player clicks a grid without mine, ripple effect takes place uncovering all the blanks in the neighborhood until either the grid boundary is reached or a number is reached along its path. The ripple effect is implemented by recursion. . On larger maps, the following errors may occur
RecursionError: maximum recursion depth exceeded in comparison
due to the limitation ofsys.setrecursionlimit()
-
If the player clicks a grid with mine, the game is over.
-
If the player clicks a not unknown grid, and the number of flags nearby equal to the number of mines nearby, all unknown grids nearby will be shown automatically. If there is a wrong flag, the game is over.
-
Player can mark a grid or unmark a grid.
-
When the player marks all the mines, the game is won.
-
Automatically finish a game.
-
Clear all operations except setting mines.
In file './Mine_GUI.py', we described the layout of the graphical user interface and defined event function in GUI.
Class Mine_GUI
have a object of Class Mine_Map
.
Actions on GUI controls trigger event functions and call the functions of the Mine_Map
object. Subsequently, the GUI will change the displayed content according to the change of the data in the Mine_Map
object.
File './unit_test.py' includes four unit test.
-
Win the game
-
Game Over
-
Automatically finish a game
-
Clear all operations except setting mines
- Mine_Map.py
Class for data structures and algorithms
- Mine_GUI.py
Class for GUI
- minesweeper_CLI.py
Play and print the data of minesweeper in the command-line interface.
- minesweeper_GUI.py
Play the minesweeper in GUI.
- unit_test.py
Unit test.
- CLI
- GUI
- Auto Play
- Local Unit Test
- Travis CI