• Post Reply Bookmark Topic Watch Topic
  • New Topic

Working with multiple arraylists  RSS feed

 
Russell Taylor
Greenhorn
Posts: 3
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am slowly teaching myself how to code, and I have come across an issue with arraylists. I am writing a text based RPG game as something to start with and to get my head wrapped round how to code.

Initally I had a single zone which was all stored in an arraylist and everything was working in regards to the player moving around. The problem I now have is how to add further zones to my game. Ideally I would like an arraylist for each zone, and would use the below to create each arraylist



The problem I now have is how to handle the player moving, initially with a single zone/arraylist I could reference that arraylist directly



My intial thought was to use a getter/setter to remove the reference of castleMap from my movement code in order to access different arraylists, however this is where things have fallen over, I can't seem to work out how to get the arraylist name to change, depending on the outcome of the setZoneMap() method.

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

I don't understand what you mean by "how to get the arraylist name to change, depending on the outcome of the setZoneMap() method." - setZoneMap does alter the "zoneMap" reference, so it variously points at different maps - isn't that what you want? If not, what do you want to change instead?
 
Russell Taylor
Greenhorn
Posts: 3
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I probably should have put more information in there then I actually did

The issue I am having is that in the findRoomCoords method an error is being thrown out that the .get.roomID, roomZone, roomX etc cannot be found, I am suspecting that it has something to do with how I am declaring the zoneMap variable, which I am doing as private ArrayList zoneMap;

exact error is
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that error message was needed for it to make sense :-)

I am suspecting that it has something to do with how I am declaring the zoneMap variable, which I am doing as private ArrayList zoneMap

Indeed, you need to declare it as "ArrayList<RoomsClass>", and also return that type from getZoneMap. Only then can the compiler make assumptions about the objects in the list, like which fields they have.
 
Russell Taylor
Greenhorn
Posts: 3
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fantastic! I suspected it would be something simple like that

Thank you loads for the help
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!