public class Game
{
private Parser parser;
private Room currentRoom;
private Person person;
private Items item;
public Game()
{
createRooms();
createItems();
parser = new Parser();
}
private void createRooms()
{
Room outside, theater, pub, lab, office;
outside = new Room("outside the main entrance of the university");
theater = new Room("in a lecture theater");
pub = new Room("in the campus pub");
lab = new Room("in a computing lab");
office = new Room("in the computing admin office");
outside.setExit("east", theater);
outside.setExit("south", lab);
outside.setExit("west", pub);
theater.setExit("west", outside);
pub.setExit("east", outside);
lab.setExit("north", outside);
lab.setExit("east", office);
office.setExit("west", lab);
Items book, pencilcase, pen, laptop;
book = new Items("book");
pencilcase = new Items("pencilcase");
pen = new Items("pen");
laptop = new Items("laptop");
theater.setItem("book", book);
pub.setItem("pencilcase", pencilcase);
lab.setItem("pen", pen);
office.setItem("laptop", laptop);
currentItem = null;
currentRoom = outside;
}
----------------------------------------------------------------------------------
import java.util.Set;
import java.util.HashMap;
import java.util.Iterator;
public class Items
{
private String description;
private HashMap<string,> item;
public Items(String description)
{
this.description = description;
item = new HashMap<string,>();
}
public void setItem(String description, Items thing)
{
item.put(description, thing);
}
public String getDescription()
{
return description;
}
public String getLongDescription()
{
return "There is " + description + ".\n" + getItemString();
}
private String getItemString()
{
String returnString = "Item:";
Set<string> keys = item.keySet();
for(String item : keys) {
returnString += " " + item;
}
return returnString;
}
public Items getItem(String i)
{
return item.get(i);
}
}
-----------------------------------------------------------------------------
public class Room
{
private String description;
private HashMap<string,> exits;
public Room(String description)
{
this.description = description;
exits = new HashMap<string,>();
}
public void setExit(String direction, Room neighbor)
{
exits.put(direction, neighbor);
}
public String getShortDescription()
{
return description;
}
public String getLongDescription()
{
return "You are " + description + ".\n" + getExitString();
}
private String getExitString()
{
String returnString = "Exits:";
Set<string> keys = exits.keySet();
for(String exit : keys) {
returnString += " " + exit;
}
return returnString;
}
public Room getExit(String direction)
{
return exits.get(direction);
}
}
--------------------------------------------------------
the error appears in the setItem for the Items class but it has the same concept of the Room class and it does not show the error can someone tell me how to fix this? i want to add the items to the rooms so when room is created the item is created as well but i dont want to use arraylist.