HeroVsMonster

 avatar
unknown
csharp
2 years ago
642 B
10
Indexable
int heroHealth    = 10;
int monsterHealth = 10;

Random rnd = new Random();
do
{
    int mHit = rnd.Next(1, 11);
    int hHit = rnd.Next(1, 11);

    monsterHealth -= mHit;
    Console.WriteLine("Monster was damaged and lost {0} health and now has {1} health.", mHit, monsterHealth);

    if (monsterHealth > 0)
    {
        heroHealth -= hHit;
        Console.WriteLine("Hero was damaged and lost {0} health and now has {1} health.", hHit, heroHealth);
    }
    
} while (heroHealth > 0 && monsterHealth > 0);

if (heroHealth > 0)
    Console.WriteLine("Hero Wins!!");
else 
    Console.WriteLine("Monster Wins!");
Editor is loading...