// Copyright (c) James Raftery , 1997-2000 2002. // a class to represent a player of the Snakes and Ladders applet public class Player { // two attributes: private int location; private String name; // constructor, initialse a new player, starting at location 0 // with supplied name public Player (String s) { location = 0; name = s; } // return the player's location on the board public int getLocation () { return location; } // set the player's location to an arbitrary value public void setLocation (int newLocation) { location = newLocation; // ensure player doesn't drop off the end of the board if (location >= 24) { location = 24; } } // move the player forward by specified number of squares public void advanceBy (int diceRoll) { location += diceRoll; // ensure player doesn't drop off the end of the board if (location >= 24) { location = 24; } } // return the player's name public String getName () { return name; } }