Atividade de desafio em que é preciso examinar a solução para a diferença entre do e while

Concluído

O código a seguir é uma solução possível para o desafio da unidade anterior.

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!");

Esse código é apenas "uma solução possível" porque há muitas maneiras diferentes de executar a lógica de ataque.

Independentemente, a saída deve ser semelhante à seguinte saída de exemplo a seguir:

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!

Se você conseguiu, parabéns! Continue para o próximo desafio. Se você teve problemas, reserve um tempo para revisar a solução e tentar entender como ela funciona. Você pode revisar as unidades anteriores e tentar novamente esta atividade de desafio antes de continuar.