C# 实验3 自动出题算术训练

自动出题算术训练

代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 自动出题
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            init();
        }

        int a = 0;
        int b = 0;
        int result = 0;
        int score = 0;
        Boolean haveAddScore = false;

        Random rnd = new Random();

        private void init()
        {
            int choose = 0;
            if (radioButton1.Checked)
            {
                choose = 1;
                a = rnd.Next(11);
                b = rnd.Next(11);

            }
            if (radioButton2.Checked)
            {
                choose = 2;
                a = rnd.Next(21);
                b = rnd.Next(21);
            }
            if (radioButton3.Checked)
            {
                choose = 3;
                a = rnd.Next(8) + 1;
                b = rnd.Next(8) + 1;

            }
            switch (choose)
            {
                case 1: addArSub(); break;
                case 2: addArSub(); break;
                case 3: chengfa(); break;

            }
            label1.Text = a.ToString();
            label3.Text = b.ToString();
            label6.Text = score.ToString() + "分";
            label7.Text = "当前速度:" + (timer1.Interval / 1000) + "秒/题";
            // 重置计数器
            timer1.Stop();
            timer1.Start();
        }

        // 加法
        private void addArSub()
        {
            int op = rnd.Next(2);
            if(op < 1)
            {
                label2.Text = "+";
                result = a + b;
            }
            else
            {
                label2.Text = "-";
                result = a - b;
            }
            
        }

        // 乘法
        private void chengfa()
        {
            label2.Text = "*";
            result = a * b;
        }

        // 提交检查
        private void button3_Click(object sender, EventArgs e)
        {
            string input = textBox1.Text;
            int f = 0;
            if (input == "")
            {
                textBox1.BackColor = Color.Red;
            }
            else
            {
                f = int.Parse(input);
                if (result == f)
                {
                    textBox1.BackColor = Color.Green;
                    if (!haveAddScore)
                    {
                        score += 10;
                        haveAddScore = true;
                    }
                    
                    label6.Text = score.ToString() + "分";
                }
                else
                {
                    textBox1.BackColor = Color.Red;
                }
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }


        // 下一题
        private void button4_Click(object sender, EventArgs e)
        {
            init();
            textBox1.Text = "";
            textBox1.BackColor = Color.White;
            haveAddScore = false;
            // 重置计数器
            timer1.Stop();
            timer1.Start();
        }


        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox1.BackColor = Color.White;
            haveAddScore = false;
            init();
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox1.BackColor = Color.White;
            haveAddScore = false;
            init();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox1.BackColor = Color.White;
            haveAddScore = false;
            init();
        }

        // 自动刷新题目
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                timer1.Start();
            }
            else
            {
                timer1.Stop();
            }
            
            
        }

        // 加快
        private void button1_Click(object sender, EventArgs e)
        {
            if (timer1.Interval > 5000)
            {
                timer1.Interval -= 5000;
                label7.Text = "当前速度:" + (timer1.Interval / 1000) + "秒/题";
            }
                
        }

        // 减慢
        private void button2_Click(object sender, EventArgs e)
        {
            if (timer1.Interval < 50000)
            {
                timer1.Interval += 5000;
                label7.Text = "当前速度:" + (timer1.Interval / 1000) + "秒/题";
            }
                
        }
    }
}

运行截图

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值