001    
002    /**
003     * This class represents players in the game. Each player has 
004     * a current location.
005     * 
006     * @author Michael Kolling and David J. Barnes
007     * @version 2011.07.31
008     */
009    public class Player
010    {
011        private Room currentRoom;
012    
013        /**
014         * Constructor for objects of class Player
015         */
016        public Player()
017        {
018            currentRoom = null;
019        }
020    
021        /**
022         * Return the current room for this player.
023         */
024        public Room getCurrentRoom()
025        {
026            return currentRoom;
027        }
028        
029        /**
030         * Set the current room for this player.
031         */
032        public void setCurrentRoom(Room room)
033        {
034            currentRoom = room;
035        }
036        
037        /**
038         * Try to walk in a given direction. If there is a door
039         * this will change the player's location.
040         */
041        public void walk(String direction)
042        {
043            // Try to leave current room.
044            Room nextRoom = currentRoom.getExit(direction);
045     
046            if (nextRoom == null) {
047                System.out.println("There is no door!");
048            }
049            else {
050                setCurrentRoom(nextRoom);
051                System.out.println(nextRoom.getLongDescription());
052            }
053        }
054    }