'life'開始爲12,'randomNumberhit'爲1,2或3的隨機數; 'randomNumberhit'被帶離'生活',但當我試圖認識到'生命'是0,-1或-2時,它不起作用。如何修復丟失'if'
int life = 12;
...
Random randomhit = new Random();
int randomNumberhit = randomhit.Next(1, 4);
...
life = life - randomNumberhit;
Console.WriteLine(life);
if (life == 0)
{
Console.Writeline("end 0");
}
if (life == -1)
{
Console.Writeline("end -1");
}
if (life == -2)
{
Console.Writeline("end -2");
}
即使當'生命'是0,-1或-2它不遵循路徑,任何幫助將不勝感激。