码迷,mamicode.com
首页 > 其他好文 > 详细

封装,策略模式

时间:2015-11-25 21:47:54      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.IO;
 6 
 7 namespace 出题
 8 {
 9     class Writeclear   //Writeclear类
10     {
11        private string a;
12        private string b;
13        private string opertaors;
14        public Writeclear(string A,string B,string Operators)
15        {
16            a = A;
17            b = B;
18            opertaors = Operators;
19  
20        }
21        
22        private string x;
23        private string y;
24        private string operator1;
25        public string X
26        {
27            set
28            {
29                x = value;
30            }
31        }
32        public string Y
33        {
34            set
35            {
36                y = value;
37            }
38        }
39        public string Operator1
40        {
41            set
42            {
43                operator1 = value;
44            }
45        }
46   
47        public void write()
48        {
49            StreamWriter a1 = new StreamWriter(a, true);
50            a1.WriteLine(x);
51            a1.Close();
52            StreamWriter a2 = new StreamWriter(b, true);
53            a2.WriteLine(y);
54            a2.Close();
55            StreamWriter a3 = new StreamWriter(opertaors, true);
56            a3.WriteLine(operator1);
57            a3.Close();
58            
59        }
60        public void clear()
61        {
62            StreamWriter b1 = new StreamWriter(a);
63            b1.WriteLine("");
64            b1.Close();
65            StreamWriter b2 = new StreamWriter(b);
66            b2.WriteLine("");
67            b2.Close();
68            StreamWriter b3 = new StreamWriter(opertaors);
69            b3.WriteLine("");
70            b3.Close();
71        }
72        
73 
74     }
75 }

from1

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 using System.IO;
10 
11 
12 namespace 出题
13 {
14     public partial class Form1 : Form
15     {
16         public Form1()
17         {
18             InitializeComponent();
19         }
20 
21 
22         private void button1_Click(object sender, EventArgs e)
23         {
24             string fnm = @"one";
25             string fnmm = @"tow";
26             string fnmn = @"fuhao";
27             Writeclear write1 = new Writeclear(fnm,fnmm,fnmn);
28             write1.X = textBox1.Text;
29             write1.Y = textBox2.Text;
30             write1.Operator1 = comboBox1.Text;
31             write1.write();
32             textBox1.Clear();
33             textBox2.Clear(); 
34 
35         }
36 
37         private void button2_Click(object sender, EventArgs e)
38         {
39             Form2 fam = new Form2();
40             fam.ShowDialog();
41          
42         }
43 
44         private void button3_Click(object sender, EventArgs e)
45         {
46 
47             string fnm = @"one";
48             string fnmm = @"tow";
49             string fnmn = @"fuhao";         
50             Writeclear write1 = new Writeclear(fnm, fnmm, fnmn); 
51             write1.clear();
52         }
53       
54  
55         }
56     }

from2

sing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace 出题
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        int i=1;
       public static int count = -1;
       public static int right = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                int t = int.Parse(textBox5.Text);
                if (t <= 0)
                {
                    timer1.Enabled = false;
                    textBox5.Enabled = false;
                    MessageBox.Show("时间到了!");
                    Form3 fr3 = new Form3();
                    fr3.ShowDialog();

                }
                t = t - 1;
                textBox5.Text = t.ToString();

            }
            catch
            {
 
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string t = textBox5.Text;
                textBox5.Text = t;
                timer1.Enabled = true;
                timer1.Interval = 1000;
                timer1.Start();
            }
            catch
            { 

            }
            baaa();
            count++;
        

        }

        private void textBox4_KeyDown(object sender, KeyEventArgs e)
        { 
            Calculator calculator=new Calculator();
            calcuall cal=new calcuall();
            calculator.X=int.Parse(textBox1.Text);
            calculator.Y=int.Parse(textBox3.Text);
            calculator.Operator1=textBox2.Text;
            cal.Operator2=textBox2.Text;                     
            if (e.KeyCode == Keys.Enter)
            {
                if (textBox4.Text ==calculator.Answer.ToString() )
                {
                    MessageBox.Show("回答正确!");
                    right++;

from3

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 
10 namespace 出题
11 {
12     public partial class Form3 : Form
13     {
14         public Form3()
15         {
16             InitializeComponent();
17         }
18 
19         private void Form3_Load(object sender, EventArgs e)
20         {
21             textBox1.Text = Form2.right.ToString();
22             textBox2.Text = Form2.count.ToString();
23             textBox3.Text = ((Form2.right / (double)(Form2.count)) * 100).ToString() + "%";
24         }
25     }
26 }

 

封装,策略模式

标签:

原文地址:http://www.cnblogs.com/zwt0626/p/4995630.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!