私のプログラミングの授業では、部屋にアイテムがあるゲームを作成する必要があります。
これらのアイテムを作成するために配列リストを作成したいのですが、この問題が何度も発生し、修正方法がわかりません。
それは述べ続けます:
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;
}
}