Example #1
0
        public string TryGoNextRoom(string door, Player player)
        {
            foreach (var d in Doors)
            {
                if (door != d.DoorColor.ToString().ToLower() || !d.DoorOpen)
                {
                    continue;
                }

                if ((int)d.DoorColor == player.Position)
                {
                    player.Position++;
                    return($"You went through the {d.DoorColor.ToString().ToLower()} door");
                }
                if ((int)d.DoorColor + 1 == player.Position)
                {
                    player.Position--;
                    return($"You went through the {d.DoorColor.ToString().ToLower()} door");
                }
            }

            bool doorInRoom = Doors.Any(d => d.DoorColor.ToString().ToLower() == door);

            return(doorInRoom ? "Door is closed" : "Door is not in this room");
        }
Example #2
0
        public string TryOpenDoor(string door, Key[] inventory)
        {
            for (int i = 0; i < Doors.Length; i++)
            {
                if (Doors[i].DoorOpen || door != Doors[i].DoorColor.ToString().ToLower() || inventory[i] == Key.None)
                {
                    continue;
                }
                Doors[i].DoorOpen = true;
                return($"   You opened the {Doors[i].DoorColor.ToString().ToLower()} door");
            }

            bool doorInRoom = Doors.Any(d => d.DoorColor.ToString().ToLower() == door);

            return(doorInRoom ? "   You don't have the key to this door" : "   Door is not in this room");
        }
 /// <summary>
 /// Whether this room contains a door facing the given direction.
 /// </summary>
 /// <param name="direction">The direction to look for</param>
 /// <returns>Returns true if the room contains a door facing the given direction, otherwise false.</returns>
 public bool HasDoorFacing(Direction direction)
 {
     return(Doors.Any(door => door.Direction == direction));
 }