Revizuiți soluția de făcut și în timp ce provocați activitatea

Finalizat

Următorul cod este o soluție posibilă pentru provocarea de la unitatea anterioară.

int hero = 10;
int monster = 10;

Random dice = new Random();

do
{
    int roll = dice.Next(1, 11);
    monster -= roll;
    Console.WriteLine($"Monster was damaged and lost {roll} health and now has {monster} health.");

    if (monster <= 0) continue;

    roll = dice.Next(1, 11);
    hero -= roll;
    Console.WriteLine($"Hero was damaged and lost {roll} health and now has {hero} health.");

} while (hero > 0 && monster > 0);

Console.WriteLine(hero > monster ? "Hero wins!" : "Monster wins!");

Acest cod este doar "o soluție posibilă", deoarece există multe moduri diferite de a efectua logica de atac.

Indiferent, ieșirea ar trebui să fie similară cu următorul exemplu de ieșire:

Monster was damaged and lost 1 health and now has 9 health.
Hero was damaged and lost 2 health and now has 8 health.
Monster was damaged and lost 1 health and now has 8 health.
Hero was damaged and lost 4 health and now has 4 health.
Monster was damaged and lost 7 health and now has 1 health.
Hero was damaged and lost 6 health and now has -2 health.
Monster wins!

Dacă ați reușit, felicitări! Continuați cu următoarea provocare. Dacă ați avut probleme, așteptați să revizuiți soluția și încercați să înțelegeți cum funcționează. Se recomandă să revizuiți unitățile anterioare, apoi să reîncercați această activitate de provocare înainte de a continua.