lynxAi
Member
C#:
public partial class Form1 : Form
{
int score = 0;
int miss = 0;
Random rabg = new Random();
int location = 0;
bool HitClick = false;
public Form1()
{
InitializeComponent();
}
private void Start_Click(object sender, EventArgs e)
{
pictureBox1.Enabled = true;
timer1.Enabled = true;
Start.Visible = false;
}
private void MoveMole(object sender, EventArgs e)
{
MoveMole();//应用自定义函数。
lblhit.Text = "打中"(got hit) + score;
lblmiss.Text = "错失"(miss) + miss;
if (HitClick == true)
{ score++; }
else
{ miss++; }
if (score > 15)
{
timer1.Stop();
score = 0;
miss = 0;
MessageBox.Show("你赢了!(you win)", "提示", MessageBoxButtons.OK);
Start.Text = "开始(start)";
Start.Visible = true;
}
if (miss > 10)
{
timer1.Stop();
score = 0;
miss = 0;
MessageBox.Show("你输了(you lost)", "提示", MessageBoxButtons.OK);
Start.Text = "开始";
Start.Visible = true;
}
}
private void HitMole_Click(object sender, EventArgs e)
{
score++;
pictureBox1.Image = Properties.Resources.molehit;
HitClick = false;
pictureBox1.Enabled = false;
}
private void MoveMole()//自定义函数“移动鼹鼠”
{
pictureBox1.Image = Properties.Resources.molelive;
HitClick = false;
pictureBox1.Enabled = Enabled;
location = rabg.Next(1, 7);
switch (location)
{
case 1:
pictureBox1.Location = new Point(111, 60);
break;
case 2:
pictureBox1.Location = new Point(343, 61);
break;
case 3:
pictureBox1.Location = new Point(583, 59);
break;
case 4:
pictureBox1.Location = new Point(97, 297);
break;
case 5:
pictureBox1.Location = new Point(343, 298);
break;
case 6:
pictureBox1.Location = new Point(583, 299);
break;
default:
break;
}
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Enabled = false;
this.Cursor = new Cursor("hammer.cur");
}
private void button2_Click(object sender, EventArgs e)
{
if (timer1.Enabled == true)
{
timer1.Enabled = false;
pictureBox1.Enabled = false;
button2.Text = "继续";
}
else
{
timer1.Enabled = true;
pictureBox1.Enabled = true;
button2.Text = "暂停";
}
}
}
}
thought hit every moles but still have the number of miss, and the miss number grow up with the mole click,
Maybe there error:
if (HitClick == true)
{ score++; }
else
{ miss++; }
and some place.