示例#1
0
 // Turns the fountain on if the player is in the room with the fountain. Otherwise, nothing happens.
 public void Execute(FountainOfObjectsGame game)
 {
     if (game.Map.GetRoomTypeAtLocation(game.Player.Location) == RoomType.Fountain)
     {
         game.IsFountainOn = true;
     }
     else
     {
         ConsoleHelper.WriteLine("The fountain is not in this room. There was no effect.", ConsoleColor.Red);
     }
 }
示例#2
0
 // Displays the appropriate message depending on whether the fountain is enabled or disabled.
 public void DisplaySense(FountainOfObjectsGame game)
 {
     if (game.IsFountainOn)
     {
         ConsoleHelper.WriteLine("You hear the rushing waters from the Fountain of Objects. It has been reactivated!", ConsoleColor.DarkCyan);
     }
     else
     {
         ConsoleHelper.WriteLine("You hear water dripping in this room. The Fountain of Objects is here!", ConsoleColor.DarkCyan);
     }
 }
    // Causes the player's position to be updated with a new position, shifted in the intended direction,
    // but only if the destination stays on the map. Otherwise, nothing happens.
    public void Execute(FountainOfObjectsGame game)
    {
        Location currentLocation = game.Player.Location;
        Location newLocation     = Direction switch
        {
            Direction.North => new Location(currentLocation.Row - 1, currentLocation.Column),
            Direction.South => new Location(currentLocation.Row + 1, currentLocation.Column),
            Direction.West => new Location(currentLocation.Row, currentLocation.Column - 1),
            Direction.East => new Location(currentLocation.Row, currentLocation.Column + 1)
        };

        if (game.Map.IsOnMap(newLocation))
        {
            game.Player.Location = newLocation;
        }
        else
        {
            ConsoleHelper.WriteLine("There is a wall there.", ConsoleColor.Red);
        }
    }
}
示例#4
0
 // Displays the appropriate message if the player can see the light from outside the caverns.
 public void DisplaySense(FountainOfObjectsGame game) => ConsoleHelper.WriteLine("You see light in this room coming from outside the cavern. This is the entrance.", ConsoleColor.Yellow);
示例#5
0
 // Returns `true` if the player is in the entrance room.
 public bool CanSense(FountainOfObjectsGame game) => game.Map.GetRoomTypeAtLocation(game.Player.Location) == RoomType.Entrance;
        public static void Main(string[] args)
        {
            FountainOfObjectsGame game = CreateSmallGame();

            game.Run();
        }