Docsity

Lab 3: Build and Undoable Maze Game Using Builder Pattern | CS 350, Lab Reports of Computer Science

Toggle sidebar
bg1
CS350/SE310 Software Design/Software Architcture I
Lab 3: Build an Undoable Maze Game using Builder Pattern,
Due October 17th, 2008
Goal:
Practice Builder Pattern and Command Pattern
Requirements:
1. Build a maze game with at least 9 rooms
2. Each movement is undoable
3. The user can still select either a Red Maze Game or Blue Maze Game
4. Modify the abstract factory maze game you accomplished in lab 2 to add a builder pattern
5. Compile the new program show red or blue maze games
6. Add on to the builder pattern maze game a Command Pattern so that moves are undoable
7. Compile the new program show red or blue maze games, and each movement can be undone
by typing “u”
Instructions
Note: from this lab, I may not give extremely detailed instructions. For example, you may need to
add methods to find the opposite direction of each direction. Use your own judgment to figure
out where and how to add these methods.
This lab has the following two parts: in the first part, the students will need to extend the Abstract
Factory Pattern built in lab 2 to add a builder pattern. In the second part, the students will add a
command pattern to support “undo moves”, without modifying the code for the builder maze game.
Stage 1: Using the Builder Pattern.
1. Select a working directory
2. Copy and paste the abstract factory maze game in lab 2 to the working directory
3. Clean the bin directory
4. Modify the abstract factory maze game according to the builder pattern, for example:
a. Add an abstract MazeBuilder Interface,
b. Add a ConcreteMazeBuilderFactory class that extends the MazeBuilder interface and
takes MazeFactory as a parameter.
c. Implement the ConcreteMazeBuilderFactory class, where you may need to complete
methods like buildRoom(), and addDoor(), as we talked in class: to build a door, you
pf3
pf4
pf5

Partial preview of the text

Download Lab 3: Build and Undoable Maze Game Using Builder Pattern | CS 350 and more Lab Reports Computer Science in PDF only on Docsity!

CS350/SE310 Software Design/Software Architcture I

Lab 3: Build an Undoable Maze Game using Builder Pattern,

Due October 17th, 2008

Goal:

Practice Builder Pattern and Command Pattern

Requirements:

  1. Build a maze game with at least 9 rooms
  2. Each movement is undoable
  3. The user can still select either a Red Maze Game or Blue Maze Game
  4. Modify the abstract factory maze game you accomplished in lab 2 to add a builder pattern
  5. Compile the new program show red or blue maze games
  6. Add on to the builder pattern maze game a Command Pattern so that moves are undoable
  7. Compile the new program show red or blue maze games, and each movement can be undone by typing “u”

Instructions

Note: from this lab, I may not give extremely detailed instructions. For example, you may need to add methods to find the opposite direction of each direction. Use your own judgment to figure out where and how to add these methods.

This lab has the following two parts: in the first part, the students will need to extend the Abstract Factory Pattern built in lab 2 to add a builder pattern. In the second part, the students will add a command pattern to support “undo moves”, without modifying the code for the builder maze game.

Stage 1: Using the Builder Pattern.

  1. Select a working directory
  2. Copy and paste the abstract factory maze game in lab 2 to the working directory
  3. Clean the bin directory
  4. Modify the abstract factory maze game according to the builder pattern, for example: a. Add an abstract MazeBuilder Interface, b. Add a ConcreteMazeBuilderFactory class that extends the MazeBuilder interface and takes MazeFactory as a parameter. c. Implement the ConcreteMazeBuilderFactory class, where you may need to complete methods like buildRoom(), and addDoor(), as we talked in class: to build a door, you

need to build walls on each direction; to make a door, you need to decide the rooms that are connected by a door, the directions, and if the door is open. d. Change the controller (main) accordingly, e.g. to configure builders and factories, and change the createMaze() method to build at least 9 rooms. e. Run the new program Note that so far we are almost following the open-close principle: classes are added for new patterns, and only the main controller class was modified to 1) configure the builder and factory 2) change the way the createMaze() method build the maze

Stage 2: Make the Maze movements Undoable.

Note, a new maze-gui Jar file will be provided (in BbVista, the lab3 folder). We changed the gui part slightly to accept and respond to the “u” key press.

  1. Select a working directory
  2. Copy and paste the builder maze game you created in step 1 to the working directory
  3. Clean the bin directory
  4. Replace the original maze-ui.jar with the given new jar file.
  5. Create the following classes/interfaces according to Command pattern UML class diagram (you will need to create all the methods and attributes as shown in the UML diagram) a. The Command interface, which only has one method. b. The UndoableCommand interface, which extends the Command interface and add only one undo() method c. The MazeMoveCommand class, which implements the UndoableCommand interface. Hint: this class wraps a move in a maze into a Command; a maze object and a direction are passed in as parameters. So you need to (1) Create a private move method as follows (we provide this class to avoid the difficulty caused by Java syntax): private void move(Direction dir) { Room curRoom = maze.getCurrentRoom(); MapSite side = curRoom.getSide(dir); side.enter(); if (side instanceof Room) maze.setCurrentRoom((Room)side); else if (side instanceof Door) { maze.setCurrentRoom(((Door)side).getOtherSide(curRoom)); maze.getCurrentRoom().enter(); } } (2 ) implement the execute() method, that is, move to the direction passed to this command

Appendix A: Maze Game Builder Pattern

+Enter()

MapSite

+Enter() +GetSide() +SetSide()

-roomNumber

Room

+Enter()

Wall

+Enter()

-isOpen -room -room

Door

+AddRoom() +RoomNo() : Room

-roomNumber

Maze

+MakeMaze() : Maze +MakeWall() : Wall +MakeDoor() : Door +MakeRoom() : Room

MazeFactory

-rooms

1 *

-mapsites 1

EnchantedRoom DoorNeedingSpell

+MakeMaze() : Maze +MakeWall() : Wall +MakeDoor() : Door +MakeRoom() : Room

EnchantedMazeFactory

ConcreteMazeFactoryBuilder

+MakeMaze() : Maze +MakeWall() : Wall +MakeDoor() : Door +MakeRoom() : Room

BombedMazeFactory

BombedRoom BombedWall

+buildMaze() +getMaze() : Maze +addDoor(in room1 : int, in room2 : int, in direction, in open : bool) +buildRoom(in roomNo. : int)

MazeBuilder

MazeGameBuilder(main)

Appendix B: Maze Game Command Pattern

+moveEast() +moveWest() +moveNorth() +moveSouth() +undoMove()

-Stack moves

MazeMover

+execute()

«interface» Command

+undo()

«interface» UndoableCommand

-move(in dir)

-Maze maze -Direction dir

MazeMoveCommand