Java 在2d垄断游戏阵列中移动玩家

Java 在2d垄断游戏阵列中移动玩家,java,arrays,Java,Arrays,我正在为垄断棋盘游戏创建玩家类。我不太清楚如何让球员在棋盘上移动,然后储存球员的位置。我使用 BoardSquare[] square = new BoardSquare[40]; 我已经创建了两个模具 BoardSquare[] square = new BoardSquare[40]; diceOne=1+(int)(Math.random()*6); diceTwo=1+(int)(Math.random()*6); roll=diceOne+

我正在为垄断棋盘游戏创建玩家类。我不太清楚如何让球员在棋盘上移动,然后储存球员的位置。我使用

    BoardSquare[] square = new BoardSquare[40];
我已经创建了两个模具

    BoardSquare[] square = new BoardSquare[40];
    diceOne=1+(int)(Math.random()*6);
    diceTwo=1+(int)(Math.random()*6);

    roll=diceOne+diceTwo;
这是到目前为止我的player类的代码

    BoardSquare[] square = new BoardSquare[40];
class Player
{
private String name;
private String token;
private int location;
private int balance;

public Player()

{
        name = "";
        token = "";
        location = 0;
        balance = 1500;
        player = (name+token+location+balance);

} 


public Player(String name, String token, int location, int balance)

{
        this.name = name;
        this.token = token;
        this.location = location;
        this.balance = balance;
}
我意识到我需要将一个玩家初始化为零,然后将滚动骰子的值相加,以使plahyer在棋盘上占据一个位置。然而,我真的不知道当空间用完时会发生什么,如何正确地开发for循环,等等。我看了一些例子,但我真的不确定如何正确地开发棋盘游戏的逻辑。任何不在本问题范围内的关于棋盘游戏开发的建议都是非常受欢迎的。thx.

您可以使用来环绕位置,例如:

    BoardSquare[] square = new BoardSquare[40];
int newPosition = (oldPosition + diceRoll) % 40;

至于传球,你有很多选择。如果将Go定义为索引0,则最简单。您可以计算模40之前的位置,并检查其是否大于40(意味着其即将环绕)。您还可以检查新位置是否小于旧位置(假定您永远无法掷骰子>=40即可工作)。

在更新玩家的新位置之前,请执行以下检查:

    BoardSquare[] square = new BoardSquare[40];
if(position>40)
{
position=position-40
}

用金钱的细节更新变更后的头寸

Ok听起来不错。但我真的不知道如何从第一轮开始初始化玩家在数组中的位置。垄断规则规定所有玩家都开始行动。将Go定义为索引0,然后,正如规则所说,将每个人都从0开始(看起来您已经这样做了)。
    BoardSquare[] square = new BoardSquare[40];