zoukankan      html  css  js  c++  java
  • 作业四: 结对编程项目---四则运算

    本次作业,在和小伙伴的一起努力下,终于完成了。感觉这难度有点大,还需要不断看书 学习知识。才能掌握必要的技能

    然后这次的代码如下 :

    namespace _SZYS1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            public static int Count = 0;
            public static int right = 0;
            public static int fault = 0;  
         PRivate void RandomNum()
            {
                Random ran = new Random();
                int a, b; string m;
                a = ran.Next(int.Parse(textBox4.Text), int.Parse(textBox5.Text));
                b = ran.Next(int.Parse(textBox4.Text), int.Parse(textBox5.Text));
                if (a >= b)
                {
                    textBox1.Text = a.ToString();
                    textBox2.Text = b.ToString();
                    textBox3.Text = "";
                    Count++;
                    textBox6.Text = Form1.Count.ToString();
    
                    if (textBox7.Text == textBox6.Text)
                    {
                        MessageBox.Show("你已做完计算!");
    
                    }
    
                }
                else if (a < b)
                {
                    m = b.ToString();
                    textBox2.Text = a.ToString();
                    textBox1.Text = m;
                    textBox3.Text = "";
                    Count++;
                    textBox6.Text = Form1.Count.ToString();
                    if (textBox7.Text == textBox6.Text)
                    {
                        MessageBox.Show("你已做完计算!");
    
                    }
                }
    
            }
            private void timer1_Tick(object sender, EventArgs e)
            {
                if (Convert.ToInt32(textBox8.Text) <= 0)
                {
                      timer1.Enabled = false;
                      textBox3.Enabled = false;
                      MessageBox.Show("时间到!");
                      textBox3.Enabled = false;
                      Form2 frm2 = new Form2();
                      frm2.ShowDialog()
    
                }
    
                  int t = Convert.ToInt32(textBox8.Text);
    
                  t = t - 1;
    
                  textBox8.Text = t.ToString();
    
            }
    
    private void textBox3_KeyDown(object sender, KeyEventArgs e)
            {
                int sum = 0;
                string m = label3.Text;
    
                if (m == "+")
                {
    
                    sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);
                    if (e.KeyCode == Keys.Enter)
                    {
                        if (textBox3.Text == sum.ToString())
                        {
                            right++;
    
                            RandomNum();
                        }
                        else
                        {
                            fault++;
                            RandomNum();
                        }
                    }
                }
    
                else if (m == "-")
                {
                    sum = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);
                    if (e.KeyCode == Keys.Enter)
                    {
                        if (textBox3.Text == sum.ToString())
                        {
                            right++;
    
                            RandomNum();
                        }
                        else
                        {
                            fault++;
                            RandomNum();
                        }
                    }
                }
    
    
    
                else if (m == "x")
                {
                    sum = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);
                    if (e.KeyCode == Keys.Enter)
                    {
                        if (textBox3.Text == sum.ToString())
                        {
                            right++;
    
                            RandomNum();
                        }
                        else
                        { fault++;
                        RandomNum();
                        }
                    }
                }
    
    
                else
                {
                    sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
    
                }
                
            }
            private void button1_Click(object sender, EventArgs e)
            {
                label3.Text = "+";
                int t = Convert.ToInt32(textBox8.Text);
                label2.Text = t.ToString();
                timer1.Enabled = true;
                timer1.Interval = 1000;
                timer1.Start();
                RandomNum();
            }
            private void button2_Click(object sender, EventArgs e)
            {
                label3.Text = "-";
                int t = Convert.ToInt32(textBox8.Text);
                label2.Text = t.ToString();
                timer1.Enabled = true;
                timer1.Interval = 1000;
                timer1.Start();
                RandomNum();
    
            }
            private void button3_Click(object sender, EventArgs e)
            {
                label3.Text = "x";
                int t = Convert.ToInt32(textBox8.Text);
                label2.Text = t.ToString();
                timer1.Enabled = true;
                timer1.Interval = 1000;
                timer1.Start();
                RandomNum();
            }
            private void button4_Click(object sender, EventArgs e)
            {
    
                label3.Text = "/";
                int t = Convert.ToInt32(textBox8.Text);
                label2.Text = t.ToString();
                timer1.Enabled = true;
                timer1.Interval = 1000;
                timer1.Start();
                Random ran = new Random();
                int a, b; string m;
                a = ran.Next(int.Parse(textBox4.Text), int.Parse(textBox5.Text));
                b = ran.Next(int.Parse(textBox4.Text), int.Parse(textBox5.Text));
                if (b != 0)
                {
                    textBox1.Text = a.ToString();
                    textBox2.Text = b.ToString();
                    textBox3.Text = "";
                    Count++;
                    textBox6.Text = Form1.Count.ToString();
                    if (textBox7.Text == textBox6.Text)
                    {
                        MessageBox.Show("你已做完计算!");
                    }
                }
                else
                {
                    m = b.ToString();
                    textBox2.Text = a.ToString();
                    textBox1.Text = m;
                    textBox3.Text = "";
                    Count++;
                    textBox6.Text = Form1.Count.ToString();
                    if (textBox7.Text == textBox6.Text)
                    {
                        MessageBox.Show("你已做完计算!");
                    }
                }
            }
            private void button7_Click(object sender, EventArgs e)
            {
                Form2 frm2 = new Form2();
                frm2.ShowDialog();
            }       private void textBox4_TextChanged(object sender, EventArgs e)
            {
                int result;
                if (int.TryParse(textBox4.Text, out result) == false)
                {
                    if (!(textBox4.Text == ""))
                    {
                        MessageBox.Show("请输入数字!", "提示");
                        textBox4.Clear();
                    }
                }
            }
            private void textBox5_TextChanged(object sender, EventArgs e)
            {
                int result;
                if (int.TryParse(textBox5.Text, out result) == false)
                {
                    if (!(textBox5.Text == ""))
                    {
                        MessageBox.Show("请输入数字!", "提示");
                        textBox5.Clear();
                    }
                }
            }
            private void textBox7_TextChanged(object sender, EventArgs e)
            {
                 int result;
                if (int.TryParse(textBox7.Text, out result) ==false)
                {
                    if (!(textBox7.Text == ""))
                    {
                        MessageBox.Show("请输入数字!", "提示");
                        textBox7.Clear();
                    }                                                            
                }           
            }
    
            private void button5_Click(object sender, EventArgs e)
            {
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox4.Clear();
                textBox5.Clear();
                textBox7.Clear();
               
            }
          }      
    }
    

      

    截图:

  • 相关阅读:
    STL容器 erase的使用陷井
    转:VC++线程同步-事件对象
    VC线程同步方法
    C/C++四种退出线程的方法
    rabbitMQ 常用命令
    Spring @Configuration
    Spring RabbitMQ 延迟队列
    rabbitmq web管理界面 用户管理
    Linux下tar.gz 安装
    Linux下RPM软件包的安装及卸载
  • 原文地址:https://www.cnblogs.com/btycnblogs/p/5361666.html
Copyright © 2011-2022 走看看