mardi 21 avril 2020

Generating random numbers as damage numbers in a fight simulation using a for loop

I am attempting to create a fighting simulation where a random number is generated between 50 and 100 in a for loop. This random number is then subtracted from one of the fighters max HP and then vice versa as it loops and until one of the fighters health reach 0.

I currently have this and have no clue what to do to fix it and is there an easier loop to use?

for(int x = 0; x < fighter1.hp || x < fighter2.hp; x++)
        {
            damage.Next(50, 100); //number generator
            Console.WriteLine(fighter1.name + " dealt " + damage + " damage to " 
                                        + fighter2.name);
        }

It's currently printing this:

Khal Drogo dealt System.Random damage to Jon Snow
Khal Drogo dealt System.Random damage to Jon Snow
Khal Drogo dealt System.Random damage to Jon Snow
Khal Drogo dealt System.Random damage to Jon Snow
Khal Drogo dealt System.Random damage to Jon Snow
Khal Drogo dealt System.Random damage to Jon Snow



Aucun commentaire:

Enregistrer un commentaire