- Complete Exercise 6e: 8.4 .
- Create a map of your game scenario in any common electronic format (such as .pdf, .doc, .pptx, .jpg, etc.).
- Update the source code of your zuul project to create the rooms and connections as you designed them.
- Update the welcome and help messages to match your scenario.
- The rooms created in your zuul project and the connections from one room to another should match your map.
- Make sure the connections between rooms are clear in your map. I will assume that connections between rooms are bidirectional unless you indicate otherwise (e.g., with arrowheads).
- Test your program.
- Document your changes.
- Adjust the comment block at the top of the file to include a 1-2 sentence description of your specific game scenario.
public class Room Code 8.4 Using an accessor method to decrease coupling private String description; private Room northExit; private Room southExit; private Room eastExit; private Room westExit; Existing methods unchanged. public Room getExit(String direction) if(direction.equals("north")) { return northExit; if(direction.equals("east")) { return eastExit; if(direction.equals("south")) { return southExit; } if(direction.equals("west")) { return westExit; return null; Having made this change to the Room class, we need to change the Game class as well. Wherever an exit variable was accessed, we now use the accessor method. For example, instead of writing nextRoom = current Room. east Exit; we now write next Room = current Room.getExit ("east"); This makes coding one section in the Game class much easier as well. In the go Room method, the replacement suggested here will result in the following code segment: Room next Room = null; if(direction.equals("north")) { nextRoom = current Room.getExit("north"): if(direction.equals("east")) { nextRoom = current Room.getExit("east"); if(direction.equals("south")) { nextRoom = currentRoom.getExit("south"); 296 Chapter 8 Designing Classes if(direction.equals("west")) { nextRoom = currentRoom.getExit("west"); Instead, this whole code segment can now be replaced with: Room next Room = currentRoom.getExit(direction); public class Room Code 8.4 Using an accessor method to decrease coupling private String description; private Room northExit; private Room southExit; private Room eastExit; private Room westExit; Existing methods unchanged. public Room getExit(String direction) if(direction.equals("north")) { return northExit; if(direction.equals("east")) { return eastExit; if(direction.equals("south")) { return southExit; } if(direction.equals("west")) { return westExit; return null; Having made this change to the Room class, we need to change the Game class as well. Wherever an exit variable was accessed, we now use the accessor method. For example, instead of writing nextRoom = current Room. east Exit; we now write next Room = current Room.getExit ("east"); This makes coding one section in the Game class much easier as well. In the go Room method, the replacement suggested here will result in the following code segment: Room next Room = null; if(direction.equals("north")) { nextRoom = current Room.getExit("north"): if(direction.equals("east")) { nextRoom = current Room.getExit("east"); if(direction.equals("south")) { nextRoom = currentRoom.getExit("south"); 296 Chapter 8 Designing Classes if(direction.equals("west")) { nextRoom = currentRoom.getExit("west"); Instead, this whole code segment can now be replaced with: Room next Room = currentRoom.getExit(direction)