collections - Getting an item from an ArrayList, within another ArrayList in Java?(Board wants to get a player within a location) -


its monopoly type game in java. want know how can specific player id, goes through array list of locations on board, checks each one's arraylist particular player.

public class board    private arraylist<location> alllocations = new arraylist<location>(); public player getplayer(int pl){ int index = 0;      for(location temp : alllocations)     {         if(temp.getplayerid() == pl)         {return temp;}     }      return null;  } } 

public abstract class location { private arraylist<player> players = new arraylist<player>();  public player getplayerid (int id) {      int index = 0;      for(player temp : players)     {         if(temp.getid() == id)         {return temp;}         else         {return null;}     }      return null; }   } 

public class player {  public int getid() {      return playerid; }  }  

i want can find out player id 1, example, on board.

rather have list of location , having search players based on id. add location variable player object player knowns located.

unrelated, using temp variable name in loops makes code hard read. suggest more descriptive name 'player' or 'location'.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -