gpt4 book ai didi

c# - 程序立即执行下一个任务

转载 作者:太空宇宙 更新时间:2023-11-03 15:28:21 25 4
gpt4 key购买 nike

如果播放器达到第 2 级,则它会立即尝试“if level == 2”。我应该改变什么?如果您升级了,那么您只需单击“确定”,就不会弹出任何内容。现在,如果您升级了,如果您在“升级”消息框文本上单击“确定”,它将尝试再次升级您。

private void button4_Click(object sender, EventArgs e)
{
if (gold > 249)
{
gold -= 250;
label3.Text = "Gold: " + gold.ToString();
level++;
label4.Text = "Level: " + level.ToString();
MessageBox.Show(levelup);
}
else
{
int needed = 250;
MessageBox.Show("Not enough to level up! You need: " + needed + " Gold");
}
if (level == 2)
{
button4.Text = "Level Up! (350 Gold)";
if (gold > 349)
{
gold -= 350;
label3.Text = "Gold: " + gold.ToString();
level++;
label4.Text = "Level: " + level.ToString();
MessageBox.Show(levelup);
}
else
{
int needed = 350;
MessageBox.Show("Not enough to level up! You need: " + needed + " Gold");
}
}
}

最佳答案

您可以通过先检查最高等级然后再降低来修复它。
在第二部分,我还添加了“if (level == 1)”,否则如果金币多于 249,它总是会触发。“所以最好也检查一下 lvl”

private void button4_Click(object sender, EventArgs e)
{

if (level == 2)
{
button4.Text = "Level Up! (350 Gold)";
if (gold > 349)
{
gold -= 350;
label3.Text = "Gold: " + gold.ToString();
level++;
label4.Text = "Level: " + level.ToString();
MessageBox.Show(levelup);
}
else
{
int needed = 350;
MessageBox.Show("Not enough to level up! You need: " + needed + " Gold");
}
}

else if (level == 1)
{
if (gold > 249)
{
gold -= 250;
label3.Text = "Gold: " + gold.ToString();
level++;
label4.Text = "Level: " + level.ToString();
MessageBox.Show(levelup);
}
else
{
int needed = 250;
MessageBox.Show("Not enough to level up! You need: " + needed + " Gold");
}
}
}

关于c# - 程序立即执行下一个任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34474160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com