



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Practice Builder Pattern and Command Pattern
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.
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.
+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)
+moveEast() +moveWest() +moveNorth() +moveSouth() +undoMove()
-Stack
MazeMover
+execute()
«interface» Command
+undo()
«interface» UndoableCommand
-move(in dir)
-Maze maze -Direction dir
MazeMoveCommand