14
MAZE GAME DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

Embed Size (px)

Citation preview

Page 1: DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

MAZE GAMEDATA STRUCTURE AND ALGORITHM PROJECT

Fall2011

Group Members:

Asma RafiBS-3

Fatima Saleem BS-3

Page 2: DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

INTRODUCTION:

The object of the game is for the player to find their way to the end of the maze.

The program is based on the 2-D array and the graphics(mainly drawLine), represented using Applet.

Page 3: DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

GOAL:

o The goal of our project is to learn the implementation of a Data structure (2-D array).

o To learn the inco-opertion of graphics and applets with the code.

Page 4: DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

PROGRAMMING TOOLS:

BUILT-IN CLASSES USED:

java.applet.Applet;java.awt.Graphics;java.awt.event.KeyListener;java.swing.*

2-D array for creation of Maze.drawLine() method for walls.fillOval() method for player.

Page 5: DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

ALGORITHM:

CREATION OF MAZE:I. Create a Boolean 2-D array for horizontal and vertical walls

of the maze

II. Set True for open walls and False for closed walls

III. Draw lines using loop where walls are closed.IV. Draw a player.

0 1 2

3 4 5

6 7 8

FALSE FALSE FALSE

FALSE FALSE FALSE

FAL

SE

FAL

SE

FAL

SE

FALS

EFA

LSE

FAL

SE

TRUE

FALS

E

FALS

EFA

LSEFALSE

TRUE TRUE

TRUE TRUE

TR

UE

TR

UE

TR

UE

Page 6: DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

I. Use keyListener to move the player(Up, Down Left and Right).

II. Detect Collision of player with the walls and block using correct positions.

RIGHT ARROW KEY: While pressing the right arrow key, if player’s horizontal position is greater than the coordinates of the closed wall, then assign players position to that particular value.

LEFT ARROW KEY: While pressing the left arrow key, if player’s horizontal position is less than the coordinates of the closed wall, then assign players position to that particular value.

Page 7: DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

UP ARROW KEY: While pressing the up arrow key, if player’s vertical position is less

than the coordinates of the closed wall, then assign players position to that particular value.

DOWN ARROW KEY: While pressing the down arrow key, if player’s vertical position is greater

than the coordinates of the closed wall, then assign players position to that particular value.

Page 8: DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

HOW IT WORKS:

The ball starts from the top left corner of the maze.

It moves along the open walls, using the arrow keys, the closed walls block the ball from going through.

Finally reaches the end of the Maze and thus the maze is solved.

Page 9: DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

STARTING POSITION:

At player X position(SQ)=26

At player Y position(SL) = 26

Page 10: DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

BLOCKING OF WALL:

At player X position(SQ)=186

At player Y position(SL) = 26

Page 11: DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

At player X position(SQ)= 178

At player Y position(SL) = 230

Page 12: DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

END OF THE GAME:

Page 13: DATA STRUCTURE AND ALGORITHM PROJECT Fall2011 Group Members: Asma Rafi BS-3 Fatima Saleem BS-3

LEARNING:

From this project we learned:

I. Key event handling.II. Implementation of 2-D array.III. Collision Detection.IV. Tried different algorithm techniques

for creation of the maze(DFS, Tiles, fillRect()).

V. Use of Graphics and Applet.