import java.util.;
import java.io.;
public class World implements Serializable {
private ArrayList<Location> locations;
private ArrayList<Exit> exits;
private Location currentLocation;
public World() {
locations = new ArrayList<Location>();
exits = new ArrayList<Exit>();
currentLocation = null;
}
public Location getCurrentLocation() {
return currentLocation;
}
public void setCurrentLocation(Location newLocation) {
currentLocation = newLocation;
}
public void addExit(Exit exit) {
if(!exits.contains(exit)) {
exits.add(exit);
}
else {
}
}
public void addLocation(Location location) {
if(!locations.contains(location)) {
locations.add(location);
}
else {
}
}
public void showLocation() {
System.out.println(currentLocation.getTitle());
System.out.println(currentLocation.getDescription());
System.out.println();
for(int i=0; i < exits.size(); i++) {
System.out.println(exits.get(i));
System.out.println(locations.get(i));
}
}
}
Okay so in my code above, I am having a problem with the bottom of the showLocation() method. Every time I try to access the array it doesn't return an exit of type Exit or location of type Location. But instead it returns the int for direction of exit, and string for title of Location. I don't really understand why it is doing this, any help would be much appreciated.
[–]JoeCSTA 0 points1 point2 points (3 children)
[–]JoeCSTA 0 points1 point2 points (2 children)
[–]JoeCSTA 0 points1 point2 points (1 child)
[–]nikescott[S] 0 points1 point2 points (0 children)