竞猜计时器数字窗体控件焦点作用预

点击开始游戏后静态可用计时器开始计时猜到正确的数之后计时器停止。
每一局都有成绩统计。
超过10局显示不可玩。
是winform课,做不出来了,卡住了

img

img

img

img

回答:小游戏哈,做出来了,用到了ACCESS数据库,不用数据库感觉不太好做,整体效果如下:

img

img

img

整个需要用到数据库,可能你没有提供程序,这边给出源码,也可以直接上网盘下载,链接如下:
链接:


提取码:0925

代码如下(部分代码,默认生成的代码就没给了,网盘里面下载的都有,26MB左右)
Form.cs,主程序

using System;
using System.Data.OleDb;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        int time = 0;
        int guess;
        public Form1()
        {
            InitializeComponent();
            button_guess.Enabled = false;
            textBox_input.Enabled = false;
            Delete();
        }

        private void button_start_Click(object sender, EventArgs e)
        {
            button_guess.Enabled = true;
            textBox_input.Enabled = true;
            textBox_input.Text = "";
            Random random = new Random();
            int n = random.Next(1, 100);
            guess = n;
            Delete();
        }

        private void button_guess_Click(object sender, EventArgs e)
        {
            string guess_number = textBox_input.Text;
            string guess_time = time.ToString();
            string guess_result;

            if (textBox_input.Text != "")
            {
                int result = int.Parse(textBox_input.Text);

                if (result > guess)
                {
                    guess_result = "猜测大了";
                    MessageBox.Show("猜测大了");
                }
                else if (result < guess)
                {
                    guess_result = "猜测小了";
                    MessageBox.Show("猜测小了");
                }
                else
                {
                    guess_result = "猜测正确";
                    MessageBox.Show("猜测正确");
                }

                OleDbConnection conn = new OleDbConnection
                {
                    ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Test.accdb"
                };
                conn.Open();
                OleDbCommand command = new OleDbCommand("INSERT INTO [Game] (猜测时间,猜测数字,猜测结果) VALUES ('" + guess_time + "','" + guess_number + "','" + guess_result + "')", conn);
                command.ExecuteReader();
                conn.Close();
            }
            else
            {
                MessageBox.Show("请输入猜测数字");
            }
        }

        private void button_end_Click(object sender, EventArgs e)
        {
            Application.Exit();
            Delete();
        }

        private void button_score_Click(object sender, EventArgs e)
        {
            Static form = new Static();
            form.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            time += 1;
            textBox_time.Text = time.ToString() + "S";
        }

        public void Delete()
        {
            OleDbConnection conn = new OleDbConnection
            {
                ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Test.accdb"
            };
            conn.Open();
            OleDbCommand command = new OleDbCommand("DELETE * FROM [Game]", conn);
            command.ExecuteReader();
            conn.Close();
        }
    }
}