From 53c427ff3289bd31ba62898162fa68b0834f4719 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 23 Feb 2014 15:59:03 +0100 Subject: Make exit attributes private --- src/esieequest/Game.java | 19 +------------------ src/esieequest/Room.java | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java index 7da57e9..95eaa4a 100644 --- a/src/esieequest/Game.java +++ b/src/esieequest/Game.java @@ -132,24 +132,7 @@ public class Game { return; } - Room vNextRoom; - switch (pCommand.getSecondWord()) { - case "north": - vNextRoom = this.aCurrentRoom.aNorthExit; - break; - case "south": - vNextRoom = this.aCurrentRoom.aSouthExit; - break; - case "east": - vNextRoom = this.aCurrentRoom.aEastExit; - break; - case "west": - vNextRoom = this.aCurrentRoom.aWestExit; - break; - default: - System.out.println("Go where ?"); - return; - } + Room vNextRoom = aCurrentRoom.getExit(pCommand.getSecondWord()); if (vNextRoom == null) { System.out.println("There is no door!"); diff --git a/src/esieequest/Room.java b/src/esieequest/Room.java index 0a16e33..d9235cf 100644 --- a/src/esieequest/Room.java +++ b/src/esieequest/Room.java @@ -11,10 +11,10 @@ package esieequest; public class Room { private String aDescription; - public Room aNorthExit; - public Room aSouthExit; - public Room aEastExit; - public Room aWestExit; + private Room aNorthExit; + private Room aSouthExit; + private Room aEastExit; + private Room aWestExit; public Room(final String pDescription) { this.aDescription = pDescription; @@ -33,4 +33,18 @@ public class Room { this.aEastExit = pEastExit; this.aWestExit = pWestExit; } + + public Room getExit(String pDirection) { + switch (pDirection) { + case "north": + return this.aNorthExit; + case "south": + return this.aSouthExit; + case "east": + return this.aEastExit; + case "west": + return this.aWestExit; + } + return null; + } } -- cgit v1.2.3