Ejemplo n.º 1
0
        // randomly select an action for the cpu to take
        // returns the attack value or defend value
        static int CPUChoice(Warrior cpu, string action)
        {
            int randNum = new Random().Next(0, 2);

            if (string.Equals(action, "offense"))
            {
                return((randNum == 0) ? cpu.Attack() : cpu.PowerfulStrike());
            }
            else if (string.Equals(action, "defense"))
            {
                return((randNum == 0) ? cpu.Defend() : cpu.Counter());
            }
            else
            {
                return(-1);
            }
        }
Ejemplo n.º 2
0
        // ask the player what action they want to take
        // returns the attack value or defend value
        static int PlayerChoice(Warrior player, string action)
        {
            string choice;

            // continuously ask for a valid offense option
            if (string.Equals(action, "offense"))
            {
                do
                {
                    Console.ForegroundColor = ConsoleColor.DarkBlue;
                    Console.WriteLine("(A)ttack or (P)owerful Strike?");
                    Console.ResetColor();
                    choice = Console.ReadLine().ToUpper();
                    Console.WriteLine();

                    if (choice == "A")
                    {
                        return(player.Attack());
                    }
                    else if (choice == "P")
                    {
                        return(player.PowerfulStrike());
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("Invalid option\n");
                        Console.ResetColor();
                    }
                } while (true);
            }

            // continuously ask for a valid defense option
            else if (string.Equals(action, "defense"))
            {
                do
                {
                    Console.ForegroundColor = ConsoleColor.DarkBlue;
                    Console.WriteLine("(D)efend or (C)ounter?");
                    Console.ResetColor();
                    choice = Console.ReadLine().ToUpper();
                    Console.WriteLine();

                    if (choice == "D")
                    {
                        return(player.Defend());
                    }
                    else if (choice == "C")
                    {
                        return(player.Counter());
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("Invalid option\n");
                        Console.ResetColor();
                    }
                } while (true);
            }
            else
            {
                return(-1);
            }
        }