我正在制作一个具有不同帮助选项的琐事游戏,但用户只能使用一次。 我知道我需要有一个bool变量才能这样做,但我不知道该怎么做。
50/50帮助的例子。
else if (key_pressed.Equals("1"))
{
char c;
string erradas = "";
for (int i = 1; i <= 4; i++)
{
if (!levels[current_level][x][i].Equals(resp))
{
c = (char)(i + 64);
erradas = erradas + c;
}
else
{
c = (char)(i + 64);
respostas = respostas + c;
}
}
ajuda_used = true;
respostas = respostas + HELP5050(erradas);
continue;
}
public static string HELP5050(string opcoes)
{
Random rand = new Random();
int r = rand.Next(0, 2);
return (opcoes.ElementAt(r).ToString());
}
答案 0 :(得分:0)
bool bonusUsed = false;
if(!bonusUsed)
{
// do your thing
bonusUsed = true;
}
根据您的情况,我认为key_pressed.Equals("1")
应该调用50/50的帮助。所以
bool fiftyFiftyUsed = false;
...
else if (key_pressed.Equals("1"))
{
if(fiftyFiftyUsed)
{
Console.WriteLine("You have already used this help.");
continue;
}
char c;
string erradas = "";
for (int i = 1; i <= 4; i++)
{
if (!levels[current_level][x][i].Equals(resp))
{
c = (char)(i + 64);
erradas = erradas + c;
}
else
{
c = (char)(i + 64);
respostas = respostas + c;
}
}
ajuda_used = true;
respostas = respostas + HELP5050(erradas);
continue;
fiftyFiftyUsed = true; // <-- and do not forget to set this
}