Example #1
0
        // This method will handle the room traversal. Find the chosen room, check it to
        // see if it's close to the current. Check for locks, monsters, is it final, etc.
        // At last remove 5 health from the user.
        public void GoRoom(string room)
        {
            Room desiredLocation = (Room)CurrentMaze.GetRoom(room);

            if (desiredLocation != null)
            {
                if (CurrentMaze.IsNeighbor(desiredLocation, (Room)CurrentLocation))
                {
                    if (desiredLocation.IsLocked == true)
                    {
                        Console.WriteLine("--------------LOCKED----------------");
                        Console.WriteLine("Room is locked. You need a key to enter.");
                        Console.WriteLine("--------------LOCKED----------------");
                        return;
                    }
                    this.Health -= 5;
                    if (this.Health <= 0)
                    {
                        this.Die();
                        return;
                    }
                    CurrentLocation = desiredLocation;
                    if (CurrentLocation.HasMonster)
                    {
                        this.Fight();
                    }
                    this.ShowLocation();

                    if (CurrentLocation.IsFinalRoom) // Check for potential win.
                    {
                        CurrentMaze.LevelPassed();
                    }
                    return;
                }
                else
                {
                    Console.WriteLine("You can't walk through walls.");
                    return;
                }
            }
            Console.WriteLine("Invalid location.");
        }
Example #2
0
        // Try to unlock the chosen room. User needs a key.
        public void Unlock(string roomName)
        {
            var chosenRoom = CurrentMaze.GetRoom(roomName);

            if (chosenRoom == null)
            {
                Console.WriteLine("No such room");
                return;
            }
            if (!CurrentMaze.IsNeighbor(chosenRoom, this.CurrentLocation))
            {
                Console.WriteLine("You can't walk through walls");
            }
            else
            {
                if (chosenRoom.IsLocked)
                {
                    foreach (var item in this.Bag)
                    {
                        if (item is ISpecial)
                        {
                            chosenRoom.IsLocked = false;
                            this.Bag.Remove(item);
                            Console.WriteLine("--------------UNLOCKED----------------");
                            Console.WriteLine("Room unlocked.");
                            Console.WriteLine("--------------UNLOCKED----------------");
                            return;
                        }
                    }
                    Console.WriteLine("You don't have a key.");
                }
                else
                {
                    Console.WriteLine("Room is not locked.");
                }
            }
        }