0
我不知道爲什麼在我添加最後的if
聲明後,我得到了這個錯誤 我的代碼工作的很好,但添加if
我得到這個錯誤。我真的很感激,如果你能幫助我解決這個問題。Invalid token'('in class,struct或interface member declaration if after
string answer = Console.ReadLine();
if (answer == "cold" || answer == "a cold")
{
Console.WriteLine("Well done you may pass");
Console.WriteLine("Doors are now Open");
Console.ReadLine();
}
else if (selection == "W" ||selection == "w" && answer != "cold" || answer != "a cold")
{
characterHealth = characterHealth - 20;
Console.WriteLine("Wrong Answer Try Again");
Console.WriteLine("Your health level is: {0}", characterHealth);
Console.ReadLine();
}
else if (selection == "S" || selection == "s" && answer != "cold" || answer != "a cold")
{
characterHealth = characterHealth - 10;
Console.WriteLine("Wrong Answer Try Again");
Console.WriteLine("Your health level is: {0}", characterHealth);
Console.ReadLine();
}
}
int dragonHealth = 150;
int strike = randomNumbers.Next(1, 30);
int strike1 = randomNumbers.Next(1, 50);
Console.Writeline("As you move on you are encountering a small dragon");
while (dragonHealth >= 0 && characterHealth >= 0)
{
dragonHealth = dragonHealth - strike1;
characterHealth = characterHealth - strike;
Console.WriteLine("You strike the dragon, its health is: {0}", dragonHealth);
Console.WriteLine("The dragon counters, your health is: {0}", characterHealth);
if (characterHealth >= 0 && dragonHealth <= 0)
{
Console.WriteLine("Congratulations you have killed the dragon");
Console.WriteLine("You found the tresure, Story ends here");
Console.ReadLine();
}
if (characterHealth <= 0 && dragonHealth >=0)
{
Console.WriteLine("You died Game over");
return;
}
if (characterHealth <= 0 && dragonHealth <=0)
{
Console.WriteLine("You both died at the same time bad luck");
return;
}
Console.ReadLine();
呃,請格式化您的代碼。大多數編輯甚至可以自動爲你做。 – kviiri
'int dragonHealth = 150;'之前還有一個額外的緊密支撐; – siride