• 作业四: 结对编程项目---四则运算


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

    然后这次的代码如下 :

    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();
               
            }
          }      
    }
    

      

    截图:

  • 相关阅读:
    ESAPI = Enterprise Security API
    WingIDE中调试GAE(google app engine)
    C# 发送Http请求 WebClient类
    [转]使用Google App Engine Helper for Django
    装上Window7
    最近遇到个关于接口的奇怪的问题
    JNDI概述(转载)
    Google App Engine 中通过自定义Django的filter解决时区问题
    C# string与byte[]互转
    Python天天美味(33) 五分钟理解元类(Metaclasses)[转]
  • 原文地址:https://www.cnblogs.com/btycnblogs/p/5361666.html
Copyright © 2020-2023  润新知