我正在开发一款游戏。为什么程序在“if”应该在这里时将它设置为“else”?
在场景中有一个图片框,图片框的图像设置在用户在文本框中回答图像的正确名称后随机更改的数组中。
我现在已经设置了一个Int变量增加正确和减少错误。
它会发出正确的特定声音和错误的特定声音。
为什么我调试, 它的作品,因为它应该几次,然后,通过 1按钮点击, 它去到别人,而不是如果。
因此,即使正确的输入设置在文本框中,我也不会增加Int并播放错误的音频。这里是代码:
namespace AngelinaSkriver2
{
public partial class Form1 : Form
{
Bitmap[] bildeListe = new Bitmap[4];
int poengInt;
Random r = new Random();
public Form1()
{
InitializeComponent();
bildeListe[0] = Properties.Resources.ål;
bildeListe[1] = Properties.Resources.ant;
bildeListe[2] = Properties.Resources.apple;
bildeListe[3] = Properties.Resources.arm;
pictureBox1.Image = bildeListe[r.Next(0, 3)];
}
public void button1_Click(object sender, EventArgs e)
{
int tilfeldigBildet = r.Next(0, 3);
SoundPlayer riktigLyd = new SoundPlayer("lyd/applause.wav");
SoundPlayer feilLyd = new SoundPlayer("lyd/feil.wav");
if (pictureBox1.Image == bildeListe[0])
{
if (textBox1.Text.Trim().ToLower() == "ål")
{
riktigLyd.Play();
poengInt += 1;
textBox1.Text = "";
pictureBox1.Image = bildeListe[tilfeldigBildet];
}
else
{
feilLyd.Play();
poengInt -= 1;
textBox1.Text = "";
}
String poengString = poengInt.ToString();
label1.Text = poengString;
}
if (pictureBox1.Image == bildeListe[1])
{
if (textBox1.Text.Trim().ToLower() == "maur")
{
riktigLyd.Play();
poengInt += 1;
textBox1.Text = "";
pictureBox1.Image = bildeListe[tilfeldigBildet];
}
else {
feilLyd.Play();
poengInt -= 1;
textBox1.Text = "";
}
String poengString = poengInt.ToString();
label1.Text = poengString;
}
if (pictureBox1.Image == bildeListe[2])
{
if (textBox1.Text.Trim().ToLower() == "eple")
{
riktigLyd.Play();
poengInt += 1;
textBox1.Text = "";
pictureBox1.Image = bildeListe[tilfeldigBildet];
}
else
{
feilLyd.Play();
poengInt -= 1;
textBox1.Text = "";
}
String poengString = poengInt.ToString();
label1.Text = poengString;
}
if (pictureBox1.Image == bildeListe[3])
{
if (textBox1.Text.Trim().ToLower() == "arm")
{
riktigLyd.Play();
poengInt += 1;
textBox1.Text = "";
pictureBox1.Image = bildeListe[tilfeldigBildet];
}
else
{
feilLyd.Play();
poengInt -= 1;
textBox1.Text = "";
}
String poengString = poengInt.ToString();
label1.Text = poengString;
}
}
我似乎找不到任何应该使它不工作,我可以忽略的东西?
甚至poengint--以及测试文本的函数? –
是的,文字是正确的。 :)我会应用你也建议的一些变化。 – Praise
如果问题显示一个苹果,我会输入“Apple”。我会显示正确的。苹果再次表明,我将再次进入“苹果”,但现在它不工作。它播放错误的声音。 – Praise