站立会议14

项目进展:

经过了不懈的努力,我们终于还是设计好了此次的项目,虽然很辛苦,但是我们学到了很多。也解决了问题!

存在的问题:

存在的问题现在已经变得很小了,但是我还是要强调一点就是我们非常的缓慢,因为这是我们第一次做这种任务,所以缓慢在所难免,但是以后的时候我们要逐渐适应这个过程!

心得体会:

世上无难事,只怕有心人

全部代码:

  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 app2
 11 {
 12     public partial class Form1 : Form
 13     {
 14         MyBoll myboll;
 15         List<Boll> bolls = new List<Boll>();
 16         SolidBrush sb1 = new SolidBrush(Color.Red);
 17         SolidBrush sb2 = new SolidBrush(Color.Blue);
 18         Graphics g = null;
 19         int bollnum = 30;
 20         public Random rand;
 21         public int timer = 0;
 22         public Form1()
 23         {
 24             InitializeComponent();
 25             this.DoubleBuffered = true;  //避免闪烁
 26         }
 27 
 28         private void Form1_Load(object sender, EventArgs e)
 29         {
 30             rand = new Random();
 31             myboll = new MyBoll(this.ClientSize.Width, this.ClientSize.Height);
 32             for (int i = 0; i < bollnum; i++)
 33             {
 34                 Boll boll = new Boll(this.ClientSize.Width, this.ClientSize.Height, rand);
 35                 bolls.Add(boll);
 36             }
 37             timerball.Start();
 38             timertotal.Start();
 39         }
 40 
 41         private void Form1_Paint(object sender, PaintEventArgs e)
 42         {
 43             g = e.Graphics;
 44             foreach (Boll boll in bolls)
 45             {
 46                 g.FillEllipse(sb1, boll.x, boll.y, boll.d, boll.d);
 47             }
 48             g.FillEllipse(sb2, myboll.x, myboll.y, myboll.d, myboll.d);
 49         }
 50 
 51         private void timerball_Tick(object sender, EventArgs e)
 52         {
 53             foreach (Boll boll in bolls)
 54             {
 55                 boll.Move();        
 56                 double Y = myboll.y - boll.y;
 57                 double X = myboll.x - boll.x;
 58                 double R = X * X + Y * Y;
 59                 if (R <Math.Pow(boll.d / 2 + myboll.d / 2,2))
 60                 {
 61                     this.timerball.Stop();
 62                     this.timertotal.Stop();
 63                     MessageBox.Show("坚持了" + timer + "");
 64                     DialogResult a = MessageBox.Show("你是否要退出?", "提示", MessageBoxButtons.OKCancel);
 65                     if (a == DialogResult.OK)
 66                         Application.Exit();
 67                     else
 68                         Application.Restart();
 69                 }
 70             }
 71             this.Refresh();
 72         }
 73         #region 控制球的方向,上下左右的操作
 74         private void Form1_KeyDown(object sender, KeyEventArgs e)
 75         {
 76             switch (e.KeyCode)
 77             {
 78                 case Keys.Up:
 79                     timerup.Start();
 80                     break;
 81                 case Keys.Down:
 82                     timerdown.Start();
 83                     break;
 84                 case Keys.Left:
 85                     timerleft.Start();
 86                     break;
 87                 case Keys.Right:
 88                     timerright.Start();
 89                     break;
 90                 default: break;
 91             }
 92         }
 93 
 94         private void Form1_KeyUp(object sender, KeyEventArgs e)
 95         {
 96             switch (e.KeyCode)
 97             {
 98                 case Keys.Up:
 99                     timerup.Stop();
100                     break;
101                 case Keys.Down:
102                     timerdown.Stop();
103                     break;
104                 case Keys.Left:
105                     timerleft.Stop();
106                     break;
107                 case Keys.Right:
108                     timerright.Stop();
109                     break;
110                 default: break;
111             }
112         }
113 
114         private void timerup_Tick(object sender, EventArgs e)
115         {
116             myboll.Up();
117         }
118 
119         private void timerleft_Tick(object sender, EventArgs e)
120         {
121             myboll.Left();
122         }
123 
124         private void timerright_Tick(object sender, EventArgs e)
125         {
126             myboll.Right();
127         }
128 
129         private void timerdown_Tick(object sender, EventArgs e)
130         {
131             myboll.Down();
132         }
133         #endregion
134 
135         private void timertotal_Tick(object sender, EventArgs e)
136         {
137             timer++;
138         }
139     }
140 }

 

posted @ 2016-05-25 22:25  葫芦娃救爷爷  阅读(243)  评论(0编辑  收藏  举报