player.java

来自「Java based Snakes and Ladders game.」· Java 代码 · 共 51 行

JAVA
51
字号
// Description: This class is for the actual "pawn" of the game, the player.public class Player{    // Variables Of class Player.        private String playername;        private int PlayerSquare;          private Dice dice;     // The Constructor of class Player.    public Player(String name){        // Used for getting the dice roll.        dice = new Dice();        // Settings variables.        PlayerSquare = 1;        playername = name;    }        // Method for getting an updated player possition.    public int playerRoll(){                this.dice = dice;        int dicerollreturn = dice.rollDice();        PlayerSquare = PlayerSquare + dicerollreturn;        // Make sure player cant go past the end of board.        if (PlayerSquare >= 49) {            PlayerSquare = 49;        }                  // Used for Debugging Only.        System.out.println("Dice Roll : "+ dicerollreturn);                return PlayerSquare;    }        // Method for getting the player possition.    public int getPlayerPos(){        return PlayerSquare;    }        // Method for settings the player possition.    public void writePlayerPos(int newPosition)    {        PlayerSquare = newPosition;    }        // Method of returning the PlayerName.    public String getPlayerName(){        return playername;    }            }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?