Mine sweeper

18

Click here to load reader

Transcript of Mine sweeper

Page 1: Mine sweeper
Page 2: Mine sweeper

Submission Details

Submitted by:Iffat AnjumRoll: 16.Md. Maruful HaqueRoll: 37. Submitted to:Abdullah Al-Matin Ishmat Rahman

Roll: 23. LecturerSession: 09-10. Mitra KabirDate: 30/03/2011. Lecturer

Page 3: Mine sweeper

Introduction

Minesweeper is a single-player video game.

The objective of the game is to clear an abstract minefield without detonating a mine.

The player is initially presented with a grid of undistinguished squares. Some randomly selected squares, unknown to the player, are designated to contain mines.

Page 4: Mine sweeper

Introduction If a square containing a mine is revealed, the

player loses the game.

Otherwise, a digit is revealed in the square, indicating the number of adjacent squares (typically, out of the possible eight) that contain mines.

In typical implementations, if this number is zero then the square appears blank, and the surrounding squares are automatically also revealed.

Page 5: Mine sweeper

Instruction set To set screen mode we have used :

ah=0,it sets the screen mode al=mode number.(we have used 12h).

int 10h To draw a pixel we use int 10h with:

ah=0ch al=pixel value. bl=page number. cx=coloum number. dx=row number.

Page 6: Mine sweeper

Instruction set To draw a character we have used int 10h with:

ah=9bh=page numberal=ascii code of charactercx=number of time to write characterbl=attribute of character.

To set cursor we have used int 10h with: ah=2

dh=new cursor rowdl=new cursor coloumbh=page number.

Page 7: Mine sweeper

Instruction set To read from key board we use:

mov ah,0int 16h.

we will get the ascci value of the key pressed in al.

To exit from screen mode we have used: mov ax,3

int 10h To return to DOS we have used:

mov ah,04ch int 21h

Page 8: Mine sweeper

Color table

We have used five colors in our project:

Color Code

Black 0

Red 4

Green 2

Purple 5

Light Blue 9

Page 9: Mine sweeper

Keyboard Inputs

We have used 6 keys from keyboard in our project:

Key name ASCII value

Escape 1bh

Carriage return 13

Up arrow 72

Down arrow 80

Left arrow 75

Right arrow 77

Page 10: Mine sweeper

Discussion on Code

To show a text in display we are using an array called num[] to hold the string.

To write the text in the display we have to know the cursor position of first letter (al, bl).al has the position in x-axis and bl has the position in y-axis.

Then we call the method of showing the letter and proceed to next one , and also increase al.

Page 11: Mine sweeper

Discussion on Code To maintain which number or mine to give in

which squares , we using an to dimensional array called mat[m][n] .where,

m=coloum no(in our grid of squares) * 9.n=row no.

To indicate which square has revealed and which not we have use an array ckd[m] ,if it has zero value then the square has not revealed, 1 indicates revealed . Here,

m=(coloum no * 9)+row.

Page 12: Mine sweeper

Discussion on Code

First of all we have to draw the main rectangle , then draw the small squares, then draw the corresponding number in them if it has revealed or fill the rectangle.

Page 13: Mine sweeper

Discussion on Code To draw any rectangle we have to know the upper

left corner’s pixel position (x1,y1) and lower right corner’s pixel position (x2,y2) :

First we starts from (x1, y1) pixel position, and go to (x2, y1) pixel position by increasing x1 , and repeatedly call “draw_pixel”to draw one pixel in every position in that way.

Next we will go from (x2, y1) to (x2, y2) and follow the same procedure.

Then from (x2, y2) to (x1, y2) and from (x1, y2) to (x1, x1).

Page 14: Mine sweeper

Discussion on Code

To fill any square we to know the upper left corner’s pixel position (x1,y1) and lower right corner’s pixel position (x2,y2) :

we have to start from (x1,y1) position and go to (x2,y1) pixel by pixel and draw a pixel in every position in that way.

Then we have to go to the next row of pixels by increasing y1 and follow the same procedure. We will continue until we get y2 number row.

Page 15: Mine sweeper

Discussion on Code

Flood fill or when we fin a zero in any square then we have to do several job:

First we have to search it’s conjugative all positions in every direction to find any nonzero numbers and then it will reveal all conjugative the zero positioned squares and also the first non zero number.

For searching every direction we have to use stack , pushed every position in it, and popped and checked.

Page 16: Mine sweeper

Discussion on Code

When we reveal a ‘*’ in any square then we have to stop the game as the ‘*’ indicates the ‘mine’.

Here after mine has revealed then we have shown a text , and we can return to play again by pressing ‘Enter’ or exit by ‘Esc’.

If one win the game ,means one has revealed allall the non ‘*’ rectangles.

Then we show the text ’You have won’ ,and we can return to play again by pressing ‘Enter’ or exit by ‘Esc’.

Page 17: Mine sweeper

Limitation

The numbers and the bomb are not random in rectangle, for this we would have to write a random function, which is one of our limitations in this code.

There is only one difficulty level & the number of rectangles are also fixed.

Page 18: Mine sweeper