示例#1
0
        /**
         * Try to go to one direction. If there is an exit, enter the new
         * room, otherwise print an error message.
         */
        private void GoRoom(Command command)
        {
            if (!command.HasSecondWord())
            {
                // if there is no second word, we don't know where to go...
                TextEffects.ColoredMessage("Go where?\n", "DarkRed");
                return;
            }

            string direction = command.SecondWord;

            // Try to leave current room.
            Room nextRoom = player.CurrentRoom.GetExit(direction);

            if (direction.ToLower() == "back")
            {
                nextRoom = player.LastRoom;
            }

            if (nextRoom == null)
            {
                TextEffects.ColoredMessage("There is no door to " + direction + "!\n", "DarkRed");
            }
            else if (nextRoom.IsLocked())
            {
                TextEffects.ColoredMessage("This door is locked.\n", "DarkRed");
            }
            else
            {
                if (nextRoom.Enemies.Count > 0)
                {
                    InitiateCombat(nextRoom);
                }
                player.LastRoom    = player.CurrentRoom;
                player.CurrentRoom = nextRoom;
                Console.WriteLine(player.CurrentRoom.GetLongDescription());
            }
        }