Greetings
i have created the above class to create rooms and exits of the rooms. That way every room is linked to another room and i can move between them. Now what i want to do is to add an image to every room that is stored inside the class.
I suppose i must use the swing class but how do i store an image with every room i create? I suppose i should make a function that stores the path to the file system of the image inside the room class and i call that function through my main to define that argument for a specific object?
public class Room
{
private String description;
private HashMap <String, Room> exits; // stores exits of this room.
/**
* Create a room described "description" with a given image.
* Initially, it has no exits. "description" is something like
* "in a kitchen" or "in an open court yard".
*/
public Room(String description)
{
this.description = description;
exits = new HashMap <String, Room> ();
}
/**
* Define an exit from this room.
*/
public void setExit(String direction, Room neighbor)
{
exits.put(direction, neighbor);
}
/**
* Return the description of the room (the one that was defined in the
* constructor).
*/
public String getShortDescription()
{
return description;
}
/**
* Return a long description of this room, in the form:
* You are in the kitchen.
* Exits: north west
*/
public String getLongDescription()
{
return "You are " + description + ".\n" + getExitString();
}
/**
* Return a string describing the room's exits, for example
* "Exits: north west".
*/
private String getExitString()
{
String returnString = "Exits:";
for (Object key : exits.keySet()) {
returnString += " " + key;
}
return returnString;
}
/**
* Return the room that is reached if we go from this room in direction
* "direction". If there is no room in that direction, return null.
*/
public Room getExit(String direction)
{
return (Room)exits.get(direction);
}
}