jeudi 11 février 2021

How can I make this combat system I have repeat as long as the character is not dead and both enemies are not dead. (C#)

I have a combat system in my first attempt at coding my very own project and I was wondering how to make it so the combat system can repeat as long as the main character isn't dead and both enemy one and enemy two are not dead. I left out the actual combat part of the code just because it is a lot but if needed I can post it. I am trying to use a do/while loop but I am not sure if that is the best way to go about it.

            if (enemy1.health <= 0)
            {
                enemy1Dead = true;
            }
            else enemy1Dead = false;

            if (enemy2.health <= 0)
            {
                enemy2Dead = true;
            }
            else { enemy2Dead = false; }

            if (healthAmount == 0)
            {
                playerDead = true;
            }
(then there code for the actual combat here that I left out for conciseness because it is not relevant.)

     if (enemy1.health > 0)
            {
                Console.WriteLine("");
                Console.WriteLine($"One of the monsters swipes it's claw at you, dealing {enemy1.damage} damage");
                healthAmount = healthAmount - enemy1.damage;
                Console.WriteLine($"You now have {healthAmount} health.");
            }
            //Enemy Two Attack
            if (enemy2.health > 0)
            {
                Console.WriteLine("");
                Console.WriteLine($"The other monster roars and charges at you dealing {enemy2.damage} damage");
                healthAmount = healthAmount - enemy2.damage;
                Console.WriteLine($"You now have {healthAmount} health.");
            }

            if (playerDead == true)
            { goto PlayerDies; }
            else if (enemy2Dead == true && enemy1Dead == true )
            { goto EnemiesDie; }
        }
        while (playerDead == false && (enemy2Dead == false || enemy1Dead == false));

Aucun commentaire:

Enregistrer un commentaire