Hello, all!
Trying my hand at making a text-based RPG in Java. Just working on getting the framework set up and I’m running into a slight problem.
I’m trying to create a method of a Location class that returns whether or not a room contains a specific exit. My “map” (or list of connected rooms, rather) is stored as a hashmap. Each room/Location object has one that stores the connected rooms in the format ( Direction of Exit, Connected Room).
My method to pull whether or not the room contains a specified exit doesn’t work, and I’m not sure where I need to head to be on the right track, here.
This is the method:
public Boolean containsExit( String exit ){
switch (exit.toUpperCase()){
case "N":
if (linkedRooms.containsKey("N"))
return true;
break;
case "S":
if (linkedRooms.containsKey("S"))
return true;
break;
case "E":
if (linkedRooms.containsKey("E"))
return true;
break;
case "W":
if (linkedRooms.containsKey("W"))
return true;
break;
case "U":
if (linkedRooms.containsKey("U"))
return true;
break;
case "D":
if (linkedRooms.containsKey("D"))
return true;
break;
default:
return false;
break;
}
Likewise, in my main class I’m calling the method as such:
private void moveNorth(){
if (currentLocation.containsExit("N").equals(true)){
}
}
My method is informing me that I have an unreachable statement, and that I’m not returning anything (and should be).
Any help would be excellent!
Thanks in advance.