我正在c#中进行快速测验游戏,我正在努力制作标签(questionLabel)并且按钮(ans1 - ans4)显示指定的文字,当点击播放按钮时,提前谢谢你
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int pointCounter = 0;
private SoundPlayer _soundPlayer;
int questionNr = 1;
public Form1()
{
InitializeComponent();
_soundPlayer = new SoundPlayer("song.wav");
}
private void pictureBox1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.amazon.com/Chuck-Seasons-One-Five-Blu-ray/dp/B007AFS0N2");
}
private void Form1_Load(object sender, EventArgs e)
{
_soundPlayer.PlayLooping();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void muteButton_Click(object sender, EventArgs e)
{
if (muteButton.Text == "Mute")
{
muteButton.Text = "Unmute";
_soundPlayer.Stop();
}
else
{
muteButton.Text = "Mute";
_soundPlayer.PlayLooping();
}
}
private void button1_Click(object sender, EventArgs e)
{
ans1.Visible = true;
ans2.Visible = true;
ans3.Visible = true;
ans4.Visible = true;
playButton.Visible = false;
while (questionNr >= 2)
{
if (questionNr == 1)
{
questionLabel.Text = "What is Chuck's full name?";
ans1.Text = "fushfus";
ans2.Text = "bhfsfs";
ans3.Text = "Chuck";
ans4.Text = "sfhus";
}
}
}
private void ans3_Click(object sender, EventArgs e)
{
if (questionLabel.Text == "What is Chuck's full name?")
{
pointCounter++;
}
else
{
}
}
public void PointCounter(){
pointsLabel.Text = pointCounter.ToString();
}
}
}
答案 0 :(得分:0)
如果button1是播放按钮,那么我猜你的while()循环错了。
它永远不会输入while(questionNr >= 2)
,因为在创建实例时,questionNr为1。
public partial class Form1 : Form
{
int pointCounter = 0;
private SoundPlayer _soundPlayer;
int questionNr = 1; <--
public Form1() { ... }
}
变化:
while (questionNr >= 2)
{
if (questionNr == 1)
{
questionLabel.Text = "What is Chuck's full name?";
ans1.Text = "fushfus";
ans2.Text = "bhfsfs";
ans3.Text = "Chuck";
ans4.Text = "sfhus";
}
}
要:
if (questionNr == 1)
{
questionLabel.Text = "What is Chuck's full name?";
ans1.Text = "fushfus";
ans2.Text = "bhfsfs";
ans3.Text = "Chuck";
ans4.Text = "sfhus";
}