Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从JAVA游戏玩家那里收集类中的信息_Java_Class_Design Patterns_Save - Fatal编程技术网

从JAVA游戏玩家那里收集类中的信息

从JAVA游戏玩家那里收集类中的信息,java,class,design-patterns,save,Java,Class,Design Patterns,Save,我正在用Java和JavaScript创建一个游戏,我希望在Java方面为每个加入游戏的玩家收集信息。例如姓名、身份证、桩数、硬币数。 我从客户端sidde/JavaScript获得的关于玩家的信息 我用Java创建了一个如下所示的类: public class GamePlayer { private String _name; private Integer _sfsID; private int welche_piles; private int azahl_

我正在用Java和JavaScript创建一个游戏,我希望在Java方面为每个加入游戏的玩家收集信息。例如姓名、身份证、桩数、硬币数。 我从客户端sidde/JavaScript获得的关于玩家的信息

我用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);    
    }
公共类游戏玩家
{
私有字符串\u名称;
私有整数_sfsID;
韦尔切乌私人酒店;
阿扎尔卢杰顿私人酒店;
私人收藏所有游戏玩家;
公共游戏玩家(字符串名称、整数sfs_id、向量welche_桩、向量anzahl_jetons)
{
//TODO自动生成的构造函数存根
//在这里,我将处理这些信息
}
}
//在游戏中
GamePlayer GamePlayer=新玩家(user.get_name()、user.get_sfsID()、桩、硬币);
所有玩家。添加(玩家);
对于(游戏玩家gp:所有游戏玩家)
{
收集信息(gp);
}
我想把所有玩家都保存在一个集合中-->所有玩家。 现在我想知道如何访问我得到的信息。例如,如何获取sfsID为2的用户的名称?事实上,我想获得每个用户的所有信息。
我该怎么做?如何改进类的任何建议?

将所有玩家对象存储在HashMap或GamePlayer的静态字段中,或存储在代表游戏的不同类中


HashMap会很有用,因为它可以让您快速获取玩家。

所有玩家都应该在另一个类中,比如Game,或者标记为静态字段。@SilviuBurcea是的,您是对的!我完全删除了函数“getGamePlayer”,并将“gameplayer”存储在我的“game.class”中,gp位于game.class中,我可以访问我需要的所有信息。这是访问GamePlayer.class中变量的正确方法吗?不要忘记equals/hashCode!