Untitled

mail@pastecode.io avatar
unknown
csharp
2 years ago
620 B
8
Indexable
Never
var monster = 10;
var hero = 10;

var rand = new Random();

var attacked = "";  
var dmg = 0;
var attackedHp = 0;

var isHero = true;
while(monster > 0 && hero > 0) {
    dmg = rand.Next(10) + 1;
    
    if (isHero) {
        attacked = "Monster";
        monster -= dmg;
        attackedHp = monster;
    } else {
        attacked = "Hero";
        hero -= dmg;
        attackedHp = hero;
    }
    isHero = !isHero;

    Console.WriteLine("{0} was damaged and lost {1} health and now has {2} health.", attacked, dmg, Math.Max(attackedHp, 0));
}  

Console.WriteLine("{0} Wins!", hero > monster ? "Hero" : "Monster");