1 using System.Windows.Forms; 2 3 namespace 计应142 王斌 4 { 5 public partial class Form1 : Form 6 { 7 public static int Count = 0; 8 private int t = 60; 9 public static int right = 0; 10 public static int fault = 0; 11 12 public Form1() 13 { 14 InitializeComponent(); 15 } 16 17 private void button4_Click(object sender, EventArgs e) 18 { 19 label2.Text = "/"; 20 // RandomNum(); 21 } 22 23 private void button1_Click(object sender, EventArgs e) 24 { 25 label2.Text = "+"; 26 // RandomNum(); 27 } 28 29 private void button2_Click(object sender, EventArgs e) 30 { 31 label2.Text = "-"; 32 // RandomNum(); 33 } 34 private void button3_Click(object sender, EventArgs e) 35 { 36 label2.Text = "*"; 37 // RandomNum(); 38 } 39 private void RandomNum() 40 { 41 Random ran = new Random(); 42 int n1, n2; 43 n1 = ran.Next(1, 11); 44 n2 = ran.Next(1, 11); 45 textBox1.Text = n1.ToString(); 46 textBox2.Text = n2.ToString(); 47 48 switch (label2.Text) 49 { 50 case "-": 51 while (true) 52 { 53 if (int.Parse(textBox1.Text) >= int.Parse(textBox2.Text)) 54 { 55 break; 56 } 57 n1 = ran.Next(1, 11); 58 n2 = ran.Next(1, 11); 59 textBox1.Text = n1.ToString(); 60 textBox2.Text = n2.ToString(); 61 62 } 63 break; 64 65 } 66 textBox3.Text = ""; 67 Count++; 68 } 69 private void button6_Click(object sender, EventArgs e) 70 { 71 72 textBox3.Enabled = false; 73 Form2 frm2 = new Form2(); 74 frm2.ShowDialog(); 75 76 } 77 private void textBox3_KeyDown(object sender, KeyEventArgs e) 78 { 79 int m; 80 if (e.KeyCode == Keys.Enter) 81 { 82 switch (label2.Text) 83 { 84 case "+": 85 m = int.Parse(textBox2.Text) + int.Parse(textBox3.Text); 86 break; 87 88 case "*": 89 m = int.Parse(textBox2.Text) * int.Parse(textBox3.Text); 90 break; 91 default: 92 m = int.Parse(textBox2.Text) / int.Parse(textBox3.Text); 93 break; 94 } 95 if (textBox3.Text == Convert.ToString(m)) 96 { 97 right++; 98 // RandomNum(); 99 } 100 else 101 { 102 fault++; 103 RandomNum(); 104 } 105 } 106 } 107 private void button5_Click(object sender, EventArgs e) 108 { 109 try 110 { 111 t = int.Parse(textBox4 .Text ); 112 if (t <= 0) 113 { 114 MessageBox.Show("时间不能为负数"); 115 return; 116 } 117 label4.Text = t.ToString(); 118 textBox4.Enabled = false; 119 } 120 catch (Exception) 121 { 122 MessageBox.Show("请输入正确的时间"); 123 return; 124 125 } 126 // label4.Text = t.ToString(); 127 128 timer1.Enabled = true; 129 timer1.Interval = 1000; 130 timer1.Start(); 131 RandomNum(); 132 } 133 private void timer1_Tick(object sender, EventArgs e) 134 { 135 if (t <= 0) 136 { 137 timer1.Enabled = false; 138 textBox4.Enabled = false; 139 MessageBox.Show("时间到!!!"); 140 textBox4.Enabled = false; 141 // txtTime.Enblaed = false; 142 Form2 frm2 = new Form2(); 143 frm2.ShowDialog(); 144 } 145 t = t - 1; 146 label4.Text = t.ToString(); 147 } 148 149 private void Form1_Load(object sender, EventArgs e) 150 { 151 152 } 153 154 private void textBox1_TextChanged(object sender, EventArgs e) 155 { 156 157 } 158 159 private void textBox3_TextChanged(object sender, EventArgs e) 160 { 161 } 162 } 163 164 }
项目耗时纪录:
(另查找资料另用一小时左右)
PSP2.1 | Personal Software Process Stages | 耗时(分钟) |
计划 | 10 | |
估计任务用时 | 10 | |
开发 | 180 | |
需求分析 |
20 | |
设计复审 | 15 | |
代码规范 | 10 | |
具体设计 | 20 | |
具体编码 | 70 | |
代码复审 | 15 | |
测试 |
10 | |
报告 | 30 | |
测试报告 | 15 | |
计算工作量 | 5 | |
事后总结 | 15 |
又在原基础上增加了时间设置,即用户可以自己定义时间,并且完成了减数不会出现负数,并且用户可以自己定义运算符号。