Exemplo n.º 1
0
        /**
         *  Main play routine.  Loops until end of play.
         */
        public void play()
        {
            printWelcome();

            // Enter the main command loop.  Here we repeatedly read commands and
            // execute them until the game is over.
            bool finished = false;

            while (!finished && player.IsAlive())
            {
                Command command = parser.getCommand();
                finished = processCommand(command);
            }
            if (!player.IsAlive())
            {
                Console.WriteLine("You have died, better luck next time.");
            }
            else
            {
                Console.WriteLine("Thank you for playing.");
            }
        }
Exemplo n.º 2
0
        private bool _processCommand(Command cmd)
        {
            bool wantToQuit = false;

            if (cmd.IsUnknown())
            {
                Console.WriteLine("I don't know what you mean... be more specific.");
                Console.WriteLine("Use the 'help' command to see which commands you can use.");
                return(false);
            }

            if (_player.IsAlive())
            {
                // this should be handled at one location...
                string commandWord = cmd.GetCommandWord();

                if (commandWord.Equals("help"))
                {
                    Zuul.Commands.HelpCommand command = new HelpCommand(_help);
                    command.Execute();
                }
                else if (commandWord.Equals("go"))
                {
                    _goRoom(cmd);
                }
                else if (commandWord.Equals("take"))
                {
                    _takeItem(cmd);
                }
                else if (commandWord.Equals("use"))
                {
                    _useItem(cmd);
                }
                else if (commandWord.Equals("quit"))
                {
                    Console.WriteLine("You died.. poor you. Cya soon..!");
                    wantToQuit = _quit(cmd);
                }
                else if (commandWord.Equals("inventory"))
                {
                    _showInventory(cmd);
                }
                else if (commandWord.Equals("unlock"))
                {
                    _unlockRoom(cmd);
                }
                else if (commandWord.Equals("look"))
                {
                    _lookInRoom(cmd);
                }
                else if (commandWord.Equals("talk"))
                {
                    _talkToNpc(cmd);
                }
                else if (commandWord.Equals("ask"))
                {
                    _askNpc(cmd);
                }
                else if (commandWord.Equals("bye"))
                {
                    _byeNpc(cmd);
                }
                else if (commandWord.Equals("fight"))
                {
                    _fightMonster(cmd);
                }
                else if (commandWord.Equals("attack"))
                {
                    _attackMonster(cmd);
                }
                else if (commandWord.Equals("loot"))
                {
                    _lootMonster(cmd);
                }
            }

            return(wantToQuit);
        }