非常简单的WhakeTheHole

lynxAi

成员
已加入
2019年12月7日
留言内容
10
地点
四川省
编程经验
Beginner
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;
            如果(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 = "暂停";
            }
        }
    }
}
批注2019-12-15 213205.jpg



思想击中了每个痣,但仍然有错过的机会,而错过的人数随着click鼠的点击而增长,

也许有错误:

如果(HitClick == true)
{ score++; }
else
{ miss++; }
还有一些地方。
 

跳伞者

工作人员
已加入
2019年4月6日
留言内容
2,609
地点
弗吉尼亚州切萨皮克
编程经验
10+
I haven't cracked open the attachment above, but just guessing, I would guess that your MoveMole() event handler is attached to a timer and each time the timer ticks and you don't have HitClick set to true, you increase the miss count. So it depends on how you define a miss. Is a miss when the user clicks the mouse button and they don't hit a mole? Or is a miss each time a mole appears and moves without getting clicked on?
 

跳伞者

工作人员
已加入
2019年4月6日
留言内容
2,609
地点
弗吉尼亚州切萨皮克
编程经验
10+
是的,您已经附加[il] MoveMole()[/ il]作为计时器刻度的事件处理程序:
在Form1.Designer.cs中:
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.MoveMole);

就像我说的那样,您需要弄清楚如何定义未命中:
错过是指用户单击某个位置并且该位置没有痣。或者
遗漏是指在移至其他位置之前未单击痣。

现在,您的实现正在使用第二个定义。
 
最佳 底部