Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // create the players for the game
            Warrior        player     = new Warrior("David");
            Warrior        cpu        = new Warrior("Goliath");
            List <Warrior> playerList = new List <Warrior>()
            {
                player, cpu
            };
            int playerTurn = 0;
            int playerAction;
            int cpuAction;

            Console.WriteLine("Welcome to the tournament!");
            Console.WriteLine("You are playing as David vs. Goliath (CPU)\n");

            do
            {
                DisplayHP(playerList);

                // player attack
                if (playerTurn == 0)
                {
                    playerAction = PlayerChoice(player, "offense");
                    cpuAction    = CPUChoice(cpu, "defense");
                    PerformAction(player, cpu, playerAction, cpuAction);
                }

                //player defend
                else
                {
                    playerAction = PlayerChoice(player, "defense");
                    cpuAction    = CPUChoice(cpu, "offense");
                    PerformAction(cpu, player, cpuAction, playerAction);
                }

                playerTurn = 1 - playerTurn; // change turns
            } while (!player.IsDead() && !cpu.IsDead());

            // display the winner
            DisplayHP(playerList);
            Warrior winner = player.IsDead() ? cpu : player;

            Console.WriteLine($"\n{winner.Name} won the fight!");
        }