我正在用Java和JavaScript創建遊戲,我希望在Java方面爲每個參與遊戲的玩家收集信息。例如名稱,ID,堆數,硬幣數量。 關於我從客戶端sidde/JavaScript獲得的玩家的信息。從遊戲玩家處收集信息JAVA
我在Java中創建一個類,它看起來像這樣:
public class GamePlayer
{
private String _name;
private Integer _sfsID;
private int welche_piles;
private int azahl_jetons;
private Collection<GamePlayer> AllGamePlayers;
public GamePlayer(String name, Integer sfs_id, Vector<Integer> welche_piles, Vector<Integer> anzahl_jetons)
{
// TODO Auto-generated constructor stub
//here I will do stuff with the information
}
}
//in the game.class
GamePlayer gameplayer = new GamePlayer(user.get_name(), user.get_sfsID(),piles,coins);
AllGamePlayers.add(gameplayer);
for(GamePlayer gp : AllGamePlayers)
{
gp.gatherInformation(gp);
}
我想保存在收集每一個球員 - > AllGamePlayers。 現在我想知道如何訪問我得到的信息。例如如何使用sfsID 2獲取用戶的名稱?實際上,我想獲取有關每個用戶的所有信息。 我該怎麼做?任何建議如何改善班級?
AllGamePlayers應該在另一個類中,比如Game,或者標記爲靜態字段。 –
Arraylist.get(ID)? –
@SilviuBurcea是的,你是對的!我完全刪除了「getGamePlayer」函數,並在Game.class中使用gp在我的「game.class」 – CMS