---恢复内容开始---
程序开发周期
程序的一些重要算法
public void call()//根据电梯所在楼层和所在楼层的距离差,选择最近的电梯调度 { int[] a = new int[4]; a[0] = (442 - label2.Top) / 19;//电梯一所在楼层 a[1] = (442 - label3.Top) / 19;//电梯二所在楼层 a[2] = (442 - label4.Top) / 19;//电梯三所在楼层 a[3] = (442 - label5.Top) / 19;//电梯四所在楼层 int n = 0; int min = 461; for (int i = 0; i <= 3; i++)//找出距离最近的电梯 if (Math.Abs(a[i] - floor1) < min) { n = i; m=n;//传值到函数用来判断请求到的电梯 min = Math.Abs(a[i] - floor1); } if (floor1 - a[n] == 0)//所在楼层相同不动 { switch (n) { case 3: this.timer1.Stop(); break; case 2: this.timer3.Stop(); break; case 1: this.timer5.Stop(); break; case 0: this.timer7.Stop(); break; } } else { if ((floor1 - a[n])> 0)//电梯所在楼层小于请求楼层,向上走 { switch (n) { case 3: this.timer1.Start(); break; case 2: this.timer3.Start(); break; case 1: this.timer5.Start(); break; case 0: this.timer7.Start(); break; } }
/*向下走*/ else { switch (n) { case 3: this.timer2.Start(); break; case 2: this.timer4.Start(); break; case 1: this.timer6.Start(); break; case 0: this.timer8.Start(); break; } } } }
电梯的上升函数
public void timer1_Tick(object sender, EventArgs e)//电梯四上升 { label7.Text = "电梯四";//显示请求到的电梯 label1.Text = ("" + (461 - label5.Top) / 19 + " ↑");//显示所在楼层及状态 if (label5.Top < 53 + 19 * (21 - floor1)) this.timer1.Stop(); label5.Top -= 19;//电梯上升 }
电梯下降函数
private void timer2_Tick(object sender, EventArgs e)//电梯四下降 { label7.Text = "电梯四"; label1.Text = ("" + (424 - label5.Top) / 19 + " ↓"); if (label5.Top >404-19*floor1 ) this.timer2.Stop(); label5.Top += 19; }
运行的一些截图