Example #1
0
        /// <summary>
        ///     Performs given command and returns the game end state depending on the results.
        /// </summary>
        /// <param name="command">player's input command</param>
        /// <returns>game end state</returns>
        public EndState GetEndState(string command)
        {
            EndState endState;

            switch (command)
            {
            case "M":
                Player.Move();
                endState = CheckPlayerMovement();
                break;

            case "S":
                endState = Player.ShootArrow(Wumpus.RoomNumber);
                break;

            case "Q":
                endState = new EndState(true, "");
                break;

            default:
                endState = new EndState();
                break;
            }
            return(endState);
        }
        public static void ChooseNextAction(Player player1, StreamReader reader, StreamWriter writer)
        {
            //While the player has not been eaten by the wumpus, the player is prompted
            //for another action.
            while (player1.IsPlayerAlive() == true)
            {
                //Ask the player what they want to do.
                writer.WriteLine("Shoot or Move (S/M): ");
                string input = reader.ReadLine();
                string playerChoice = input.Trim().ToUpper();

                //If player wants to shoot an arrow, they lose an arrow.
                if (playerChoice == "S")
                {
                    player1.ShootArrow();
                    writer.WriteLine("You have {0} arrows.", player1.GetPlayerArrows());
                }
                //If player wants to move, they are prompted for which room and are moved there.
                else if (playerChoice == "M")
                {
                    writer.WriteLine("Enter which cave would you like to move to:");
                    int caveNumber = int.Parse(reader.ReadLine());
                    EnterCave(player1, caveNumber, writer);
                }
                //If player does not choose shoot or move, there is no action and they
                //will be prompted again.
                else
                {
                    writer.WriteLine("Invalid entry");
                }
            }
        }