mardi 4 août 2015

Accessing an ArrayList method, when the ArrayList is inside an object

I am trying to design a text based game.

The game will have a feature in which, if the user inputs get all, all the objects in the room must be added to the player's inventory.

The inventory of the player is an ArrayList of objects and so is the room's object "sack"

The code that i have written is as follows:

public void getAll(Room room, Player player)
  {
      for(int i = 0; i < room.objectNames.size(); i ++)
      {
          player.inventoryObjects.add(room.objects.get(i));
      }
  }

This method is inside the main class, i.e , the class which has the main method.

The arraylists are declared as:

public ArrayList<Objects> inventoryObjects = new ArrayList<Objects>();
//this is in the Player Class

public ArrayList<Objects> objects = new ArrayList<Objects>();
//this is in the Room Class

Can you tell me an alternative to line: 3 in the first piece of code that i have typed(the one with the loop) ?

-Thanks in advance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire