Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Report Dsa

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

Data Structures and Algorithms Game

Project Report
Minesweeper

Team members:
Le Do Huy Du - ITITIU18027

Chu Vĩnh Tiến - ITITSB18007

Nguyễn Duy Hải - ITITIU20005

Vũ Hồng Tân - ITITIU18242

Nguyễn Trần Duy Thanh - ITITIU18220


Abstract
The goal of our game project is to design a simple computer game using Java.
For our project, we design a 2D puzzle game where the goal of the game is to
sweep all the bombs from a 16x16 mine field. In our project, we have
implemented an “undo” features using stack techniques as taught in the DSA
course. In addition, our game have two type of mode that change the number
of bombs (10 or 20 in total) and we have implemented a function to saving
game status in a text file.

Table of Contents

1. INTRODUCTION
2. GAME OVERVIEW
2.1. Game description
2.2. Goal and game rules
2.3. Game assets

3. GAME DESIGN
3.1. Game layout
3.1.1. Board

● Initialies game board


● Set up values of game board
● 2D Array
● Randomly bomb cells & Checking Neighbour cells

3.1.2. Cell

● BombCell
● NeighborOfBombCell
● EmptyCell

3.2. Gameplay
3.2.1. Operation

● Left click
● Right click
● Recursion
● Undo
● Game mode
● Saving game status

3.3. GUI
3.3.1. Game GUI

3.3.2. Images

3.3.3 CellType and ImageName

4. CONCLUSION
5. FUTURE WORK
1.INTRODUCTION
This report will show the process involved in the making of a Tetris game
with a few added features coded using the python programming language.
Making use of the JAVA, we created a Minesweeper game where the
controls are reversed after the third game round.

This report describes the overview of the game, including the background
and the game rounds

2.Game overview
2.1 Game description
Minesweeper is single-player logic-based computer game played on
rectangular board whose object is to locate a predetermined number of
randomly-placed "mines" in the shortest possible time by clicking on "safe"
squares while avoiding the squares with mines. If the player clicks on a mine,
the game ends.To win the game, players must open all non-mine cells while
not opening any mines. Therefore, finding a square containing "8" indicated
that all eight adjacent squares contain mines, while if a zero (displayed as a
blank) is uncovered, there are no mines in the surrounding squares. A square
suspected of containing a mine may be marked with flag.

2.2 Goal and game rules


_ In our game, the goal is find all the bomb. Depending on the game
mode, there 10 to 20 in total.

_ Left click on the cell to find what type of cells it is (bomb or empty or
neighbor). Right click on the cell to flag it. Depending on the game
mode, there are 10 to 20 total flag with a count in the bottom corner.
Player can unflag a cell by right click on the flagged cell to make the
flag disapear.
_ The game is won when player flagged all the bomb cells

_The game is lost if player left click on the bomb cells


_ Player can start a new game by left click anywhere on the board

2.2 Game assets


● Block:
● Bomb:
● Covered:
● Empty:
● Flag:
● Main game interface:
3. GAME DESIGN
Class Diagram
3.1. Game layout
3.1.1. Board

_Board.java class is in control of how player input have all images


from resources folder display on screen.

● Initializes the game board for everytime a new game is start

● Setting up the value of game board after initBoard() is


called with newGame() function
● The 2D Array of “Cell” objects is a function in Board.java
that will represent the grid to store the state of each cell in
the grid (which cell contain bomb or empty or neighbour of
bomb cell). This function is used whenever newGame() in
Board.java was called. The 2D Array would random filled
it bomb cells, neighbour(or number) cells, empty cells.
● Setting up the grid to random placing bomb cells and
checking neighbour cell

3.1.2 Cell

_ Cell.java class stores all the properties of each cell like whether it;s
being covered, flagged. Depending on each type of cell, Cell.java will
handling it behavior differing. Cell.java getting the image
corresponding to the name of cell, changing its stated of being flagged
_ Cell.java have three subclass:

● BombCell
● NeighborOfBombCell
● EmptyCell

3.2. Gameplay
3.2.1. Operation

● Left click:
○ Nothing happens if player left clicks on flagged cell.

○ Left clicks on cover cell will remove a cover from


cell and depending on what type of cell:
■ If player click on mine, the game will over.

■ If player clicks on empty cell, it will call


find_empty_cell function

● find_empty_cells() function is a recursion to revel and


clear a no-bomb region of cells when player clicks on a
cell that has no bomb with neighbor cells ⇒ The
neighbor cells automatically cleared until the region
with no-bomb cell is revealed up until the cell that is
connected to a bomb:
● Right click:
○ Nothing happens if player right click on number cell

○ Flag cell if player right click on unflag cell and in


addition will push() to the stack the steps
○ Remove the flag if player right click on flagged cell
and increase the number of cells to be flagged
● Game mode: mode10 and mode20 is to set the number of
mines for the next game section, also know as difficulty.

The function only reinitialize the number of mines for the


newGame() function to set up a different number of mines
for the next initialization of the game

The two game modes will be implemented as 2 button


options in the game UI for the player to choose game mode

● Undo: When click on “Undo” button, player can undo their


moves if that moves not the bomb cell. Using stack, by
“push()” the add steps to the stack whenever player
left/right click on the cell (except bomb cell) to represents
the player’s most recent move. And by “pop()” the most
recent move out of the stack and returning the values of
player last left and right click cell (except bomb cells). If a
bomb cell is clicked, the stack will be clearing and the
“Undo” function will not working.
● Saving game status: This operation will go through the
entire game board to records the state of each cell then
writes those in a text file. The game status is automatically
saved when player exit out the window
3.3. GUI
3.3.1. Game GUI

_ Game.java is the UI design class of the game. It implements the


layout of the UI from Java Swing
3.3.2 Images

_ When the initBoard() function inside Board.java class is called,


it will get image from the resources folder.

3.3.3 CellType and ImageName

_ These class is an enums used to represent the different types of


cells and image in a more clear, more readable way

4. CONCLUSION
In the project, we have implemented a traditional Minesweeper game with
some features such as undo, choosing game mod, saving game status. The
key feature of our project is saving game status features.
By joining this code, we have learned about many things that can help us in
this project to make this game.

First, we use recursion in find_empty_cell() function as you can see from the
code.

Another use of dsa, we use gameSteps as a Stack to create undo() function to


allow user to undo moves
5. FUTURE WORK

We hope to implemented a function to load the previous status of our game


when reopened in future.

You might also like