|
-
Jan 7th, 2011, 06:42 PM
#1
Thread Starter
Member
-
Jan 7th, 2011, 08:55 PM
#2
Re: arraylist in array/arraylist
So lets assume you have an object where you store the coordinates.
The arraylist declaration would look something like this:
Code:
ArrayList<ArrayList<CoordinatesObject>> playerLand = new ArrayList<new ArrayList<CoordinatesObject>()>();
I'll check tomorrow if this actually works, but syntactically it should be correct.
Delete it. They just clutter threads anyway.
-
Jan 8th, 2011, 05:04 AM
#3
Thread Starter
Member
Re: arraylist in array/arraylist
why an object ?
also if there are easyer ways to store this date (to store the coordinates for each player but easly to add coordinates to a player) pleas tell me
Last edited by bmwsmurf; Jan 8th, 2011 at 05:18 AM.
-
Jan 8th, 2011, 05:20 AM
#4
Re: arraylist in array/arraylist
Well, you need two coordinates per block per person, right?
You can build a very simple class to hold those coordinates in a block list in a playerlist.
Delete it. They just clutter threads anyway.
-
Jan 8th, 2011, 10:02 AM
#5
Thread Starter
Member
Re: arraylist in array/arraylist
ye 2 coordinates each player only the players can add coordinates so it could look like
playername: x z : x z : x z : x z:
playername2: x z : x z : x z : x z:
playername1: x z : x z : x z : x z:
-
Feb 2nd, 2011, 05:31 PM
#6
Hyperactive Member
Re: arraylist in array/arraylist
In my opinion what you are looking for is a map ...
Code:
Map map = new HashMap();
List list1 = new ArrayList();
map.put("player1", list1);
List list2 = new ArrayList();
map.put("player2", list2);
// later when you want the list of a certain player you can get it as follows:
List list = map.get("player1");
____________________________________________
Please rate my messages. Thank you!
____________________________________________
Bram Vandenbon
http://www.bramvandenbon.com
-
Feb 2nd, 2011, 05:34 PM
#7
Thread Starter
Member
Re: arraylist in array/arraylist
Here is the problem
i dont know how many players there will be i dont want to work in the code later
-
Feb 2nd, 2011, 06:25 PM
#8
Hyperactive Member
Re: arraylist in array/arraylist
My previous example of course was only to demonstrate how maps work.
Of course you don't have to hard-code the player names.
If you use a list or a map, in both cases the names have to come from somewhere, in my examples I can only type them as strings, but of course in reality they should come from user input or a configuration file , or whatever that speaks for itself.
A map is pretty much like an array list. It has no maximum number of items, and you can loop through it as follows:
Code:
String playerName;
List list;
Iterator iterator = map.keySet().iterator();
while (iterator.hasNext())
{
playerName = (String) iterator.next();
list = (List) map.get(playerName);
}
Alternative solution
But hey, on the other side, have you concidered keeping a list of players while storing their properties within the player objects? It seems to me that the lands of a player could perfectly be regarded as a property of the players themself.
List playerList = new ArrayList();
and then just fill it with objects that look like this:
Code:
public class Player
{
private List bpList = new ArrayList();
public List getBpList()
{
return bpList;
}
}
I just don't see an arraylist in an arraylist as a good data model it's bad design on so many levels.
By the way, I do agree that coordinates are best stored as objects. I assumed that was wat the bp in your original post was supposed to be. bp is an instance of a class BlockPoint or something, right?
Last edited by BramVandenbon; Feb 2nd, 2011 at 06:33 PM.
____________________________________________
Please rate my messages. Thank you!
____________________________________________
Bram Vandenbon
http://www.bramvandenbon.com
-
Feb 3rd, 2011, 12:28 PM
#9
Thread Starter
Member
Re: arraylist in array/arraylist
bp is an object or i think
so i can do:
bp.getx();
bp.getz();
those to have to be combined and put away when asked to... the player can have multiplyed [x,z] coords
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|