Example #1
0
        static int PlayerChose(PlayerMage player, EnemyMage enemy)
        {
            bool goodInput = false;
            int  choice    = 0;

            while (goodInput == false)
            {
                try
                {
                    // show them the player stats and what their options are
                    player.DisplayAttributes();
                    enemy.DisplayAttributes();
                    Console.WriteLine("Choose your next move:");
                    // if they haven't used the shield, display option for shield
                    if (player.shieldUsed == false)
                    {
                        Console.WriteLine("Attack: 1\n" +
                                          "Heal: 2\n" +
                                          "Shield: 3 (one time use)\n");
                    }
                    // if they have used the shield, remove the option
                    else
                    {
                        Console.WriteLine("Attack: 1\n" +
                                          "Heal: 2\n");
                    }
                    // get their input
                    choice = Convert.ToInt32(Console.ReadLine());

                    if (choice == 1)
                    {
                        goodInput = true;
                    }
                    else if (choice == 2)
                    {
                        goodInput = true;
                    }
                    else if (choice == 3)
                    {
                        // if they haven't used the shield, it's a good input
                        if (player.shieldUsed == false)
                        {
                            goodInput = true;
                        }
                        // if they have used the shield, it's not a good input
                        else
                        {
                            Console.Clear();
                            Console.WriteLine("You've already used your shield");
                            goodInput = false; // redundant, but just to remind myself what's happening more less
                            // goodInput staying false will let the while loop run again to get a new choice
                        }
                    }
                    // if they didn't enter 1, 2, or 3, rerun the while loop to
                    // clear the console to redisplay the stats and give options again
                    else
                    {
                        Console.Clear();
                        continue;
                    }
                }
                catch
                {
                    Console.Clear();
                    continue;
                }
            }
            return(choice);
        }