1

对于我的编程课程,我必须创建一个房间里有物品的游戏。
要创建这些项目,我想制作一个数组列表,但我一直遇到这个问题,我不知道如何解决它。

它一直在说:

Error: <identifier> expected.
(哦,当我尝试复制粘贴代码时,其中一些超出了下面的灰色内容)

截止日期是星期三,所以我非常感谢一些反馈!

`enter code here` public class Game   {
private Parser parser;
private Player thePlayer;
private Room currentRoom;
private ArrayList<Item>;

private Item louisVuitton;
private Item iPhone;
private Item gucciGlasses;
private Item pradaShoes;
private Item clothes;
private Item towel;

/**
 * Create the game and initialise its internal map.
 */
public Game() 
{
    thePlayer = new Player();
    createRooms();
    belongings = new ArrayList<Item>(6);
    parser = new Parser();

    louisVuitton = new Item("Louis Vuitton hand bag", 2);
    iPhone = new Item("iPhone", 1);
    gucciGlasses = new Item("Gucci sunglasses", 1);
    pradaShoes = new Item("Prada sandals", 3);
    clothes = new Item("clothes", 2);
    towel = new Item("towel", 1);

}

/**
 * Create all the rooms and link their exits together. And adding items
 */
private void createRooms()
{
    Room backgarden, frontgarden, 
    street, hallway, hallway2, diningroom, livingroom, bedroom, kitchen,
    bathroom, mancave;

    // create the rooms
    backgarden = new Room("in the back garden");
    frontgarden = new Room("front garden");
    street = new Room ("in the street");
    hallway = new Room("at the start of the hallway");
    hallway2 = new Room("at the end of the hallway");
    diningroom = new Room("in the dining room");
    livingroom = new Room("in the living room");
    bedroom = new Room("in the bedroom");
    kitchen = new Room("in the kitchen");
    bathroom = new Room("in the bathroom");
    mancave = new Room("in the man cave");


    // initialise room exits
    frontgarden.setExit("north", hallway);
    frontgarden.setExit("south", street);

    street.setExit("north", frontgarden);

    hallway.setExit("north", hallway2);
    hallway.setExit("south", frontgarden);
    hallway.setExit("east", diningroom);
    hallway.setExit("west", livingroom);

    hallway2.setExit("north", bathroom);
    hallway2.setExit("south", hallway);
    hallway2.setExit("east", bedroom);
    hallway2.setExit("west", kitchen);

    diningroom.setExit("west", hallway);
    bedroom.setExit("west", hallway2);
    bathroom.setExit("south", hallway2);
    kitchen.setExit("east", hallway2);
    kitchen.setExit("south", livingroom);
    livingroom.setExit("north", kitchen);
    livingroom.setExit("south", mancave);
    livingroom.setExit("east", hallway);
    livingroom.setExit("west", backgarden);
    mancave.setExit("north", livingroom);

    //add items
    diningroom.addItem(gucciGlasses); 
    kitchen.addItem(iPhone); 
    bathroom.addItem(towel); 
    bedroom.addItem(louisVuitton); 
    backgarden.addItem(pradaShoes); 
    livingroom.addItem(clothes); 


    thePlayer.setRoom(hallway);  // start game in the hallway
}

import java.util.HashMap;
import java.util.Iterator;
import java.util.ArrayList;

public class Item{
private String itemName;

public Item(String itemName){
this.itemName = itemName;

}

public String getItemName(){
return itemName;
}
}
4

0 回答 0