如果玩家达到2级,那么它会立即尝试“if level == 2”。我应该改变什么?如果你升级,那么你只需点击“确定”,就不会弹出任何内容。现在,如果你升级,如果你点击“levelup”消息框文本上的“确定”,它会尝试再次升级你。
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");
}
}
}
答案 0 :(得分:0)
你可以通过首先检查最高级别然后下降来修复它 在第二部分中,我还添加了" if(level == 1)"如果有更多的黄金而不是249,那么它总是会开火。"所以更好地检查lvl还有#34;
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");
}
}
}