我正在開發一款遊戲。爲什麼程序在「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