zoukankan      html  css  js  c++  java
  • 【C#】结对项目开发-电梯调度仿真系统(Bata版)(党云龙、黄为)

    • 相对于上一版本做出的修改
      完善了四部电梯的运行。
      修复了在调用电梯过程中运行混乱的问题。
    • 时间管理


    • 电梯的核心代码
    //========================第一部电梯======================================
            public int getfloorLength()//形成队列处理函数三
            {
                return panel3.Height - l.Num * n;
            }
            private void openDoor_Tick(object sender, EventArgs e)
            {
                for (int bdx = 52; bdx >= 1; bdx--)
                {
    
                    doorLeft.Width = bdx;
                    doorRight.Width = bdx;
                    doorRight.Location = new Point(53 + 52 - bdx, 0);
                    System.Threading.Thread.CurrentThread.Join(10);
    
    
                }
                //flagColor = 1;
                openDoor.Stop();
    
            }
            private void closeDoor_Tick(object sender, EventArgs e)
            {
                for (int bdx = 0; bdx <= 52; bdx++)
                {
                    doorLeft.Width = bdx;
                    doorRight.Width = bdx;
                    doorRight.Location = new Point(106 - bdx, 0);
                    System.Threading.Thread.CurrentThread.Join(10);
                }
                //flagColor = 0;
                closeDoor.Stop();
            }
            private void move_Tick(object sender, EventArgs e)
            {
    
    
                if (NumFloor < l.Num)
                {
                    lblup.ForeColor = Color.Red;
                    for (int i = panel3.Height - NumFloor * n; i >= getfloorLength(); i--)
                    {
    
                        lift.Location = new Point(3, i);
                        //判断有没有请求
                        //if(isRequest[NumFloor-1]==1)
                        // MessageBox.Show("有人出");
                        System.Threading.Thread.CurrentThread.Join(10);
                    }
                }
                else
                {
                    lbldown.ForeColor = Color.Red;
                    for (int i = panel3.Height - NumFloor * n; i <= getfloorLength(); i++)
                    {
    
                        lift.Location = new Point(3, i);
                        System.Threading.Thread.CurrentThread.Join(10);
                    }
                }
    
                openDoor.Interval = 500;
                openDoor.Start();
               // this.Focus();
    
                System.Threading.Thread.CurrentThread.Join(1000);
                JudgeFloor(NumFloor);
    
                NumFloor = l.Num;
                RecordFloor[0] = l.Num;
                lblup.ForeColor = Color.DimGray;
                lbldown.ForeColor = Color.DimGray;
    
                lbUp.ForeColor = Color.DimGray;
                lbDown.ForeColor = Color.DimGray;
    
                // closeDoor.Interval = 500;
                //  closeDoor.Start();
              //  this.Focus();
                move.Stop();
            }//形成队列处理函数二
            private void btnClose_Click(object sender, EventArgs e)
            {
    
                closeDoor.Interval = 500;
                closeDoor.Start();
                while (k < 21)
                {
                    k++;
                    if (Squeue.msg[k] != 0)
                    {
                        l.Num = Squeue.msg[k];
                        lbNum.Text = l.Num.ToString();
                        lbFloorNum.Text = l.Num.ToString();
    
                        move.Interval = 1000;
                        move.Start();
                        break;
                    }
    
                }
               
                if (k >= 21)
                    k = 0;
    
              //  this.Focus();
            }
            private void btnOpen_Click(object sender, EventArgs e)
            {
                openDoor.Interval = 500;
                openDoor.Start();
               // this.Focus();
            }
            // --------------电梯内21个数字按钮------------------------
    
            private void btn21_Click(object sender, EventArgs e)
            {
                btn21.ForeColor = Color.Yellow;
                string s1 = btn21.Name;
                btnAction(s1);
            }
            private void btn20_Click(object sender, EventArgs e)
            {
                btn20.ForeColor = Color.Yellow;
                string s1 = btn20.Name;
                btnAction(s1);
            }
            private void btn19_Click(object sender, EventArgs e)
            {
                btn19.ForeColor = Color.Yellow;
                string s1 = btn19.Name;
                btnAction(s1);
            }
            private void btn18_Click(object sender, EventArgs e)
            {
                btn18.ForeColor = Color.Yellow;
                string s1 = btn18.Name;
                btnAction(s1);
            }
            private void btn17_Click(object sender, EventArgs e)
            {
                btn17.ForeColor = Color.Yellow;
                string s1 = btn17.Name;
                btnAction(s1);
            }
            private void btn16_Click(object sender, EventArgs e)
            {
                btn16.ForeColor = Color.Yellow;
                string s1 = btn16.Name;
                btnAction(s1);
            }
            private void btn15_Click(object sender, EventArgs e)
            {
                btn15.ForeColor = Color.Yellow;
                string s1 = btn15.Name;
                btnAction(s1);
            }
            private void btn14_Click(object sender, EventArgs e)
            {
                btn14.ForeColor = Color.Yellow;
                string s1 = btn14.Name;
                btnAction(s1);
            }
            private void btn13_Click(object sender, EventArgs e)
            {
                btn13.ForeColor = Color.Yellow;
                string s1 = btn13.Name;
                btnAction(s1);
            }
            private void btn12_Click(object sender, EventArgs e)
            {
                btn12.ForeColor = Color.Yellow;
                string s1 = btn12.Name;
                btnAction(s1);
            }
            private void btn11_Click(object sender, EventArgs e)
            {
                btn11.ForeColor = Color.Yellow;
                string s1 = btn11.Name;
                btnAction(s1);
            }
            private void btn10_Click(object sender, EventArgs e)
            {
                btn10.ForeColor = Color.Yellow;
                string s1 = btn10.Name;
                btnAction(s1);
            }
            private void btn9_Click(object sender, EventArgs e)
            {
                btn9.ForeColor = Color.Yellow;
                string s1 = btn9.Name;
                btnAction(s1);
            }
            private void btn8_Click(object sender, EventArgs e)
            {
                btn8.ForeColor = Color.Yellow;
    
                string s1 = btn8.Name;
                btnAction(s1);
    
            }
            private void btn7_Click(object sender, EventArgs e)
            {
                btn7.ForeColor = Color.Yellow;
                string s1 = btn7.Name;
                btnAction(s1);
            }
            private void btn6_Click(object sender, EventArgs e)
            {
                btn6.ForeColor = Color.Yellow;
                string s1 = btn6.Name;
                btnAction(s1);
            }
            private void btn5_Click(object sender, EventArgs e)
            {
                btn5.ForeColor = Color.Yellow;
                string s1 = btn5.Name;
                btnAction(s1);
            }
            private void btn4_Click(object sender, EventArgs e)
            {
                btn4.ForeColor = Color.Yellow;
                string s1 = btn4.Name;
    
                btnAction(s1);
    
            }
            private void btn3_Click(object sender, EventArgs e)
            {
                btn3.ForeColor = Color.Yellow;
                string s1 = btn3.Name;
                btnAction(s1);
            }
            private void btn2_Click(object sender, EventArgs e)
            {
                btn2.ForeColor = Color.Yellow;
                string s1 = btn2.Name;
    
                btnAction(s1);
    
            }
            private void btn1_Click(object sender, EventArgs e)
            {
                btn1.ForeColor = Color.Yellow;
                string s1 = btn1.Name;
    
                btnAction(s1);
    
    
    
            }
    
            //----------------------各楼层按钮-------------------------------
    
            // 21楼按钮
            
            private void btn21Down_Click(object sender, EventArgs e)
            {
                btn21Down.ForeColor = Color.Red;
                string s1 = btn21.Name;
                btnAction1(s1);
            }
            private void btn21Up_Click(object sender, EventArgs e)
            {
                btn21Up.ForeColor = Color.Red;
                string s1 = btn21.Name;
                btnAction1(s1);
    
            } 
            private void btn20Down_Click(object sender, EventArgs e)
            {
                btn20Down.ForeColor = Color.Red;
                string s1 = btn20.Name;
                btnAction1(s1);
            }
            private void btn20Up_Click(object sender, EventArgs e)
            {
                btn20Up.ForeColor = Color.Red;
                string s1 = btn20.Name;
                btnAction1(s1);
    
            } 
            private void btn19Down_Click(object sender, EventArgs e)
            {
                btn19Down.ForeColor = Color.Red;
                string s1 = btn19.Name;
                btnAction1(s1);
            }
            private void btn19Up_Click(object sender, EventArgs e)
            {
                btn19Up.ForeColor = Color.Red;
                string s1 = btn19.Name;
                btnAction1(s1);
    
            } 
            private void btn18Down_Click(object sender, EventArgs e)
            {
                btn18Down.ForeColor = Color.Red;
                string s1 = btn18.Name;
                btnAction1(s1);
            }
            private void btn18Up_Click(object sender, EventArgs e)
            {
                btn18Up.ForeColor = Color.Red;
                string s1 = btn18.Name;
                btnAction1(s1);
    
            } 
            private void btn17Down_Click(object sender, EventArgs e)
            {
                btn17Down.ForeColor = Color.Red;
                string s1 = btn17.Name;
                btnAction1(s1);
            }
            private void btn17Up_Click(object sender, EventArgs e)
            {
                btn17Up.ForeColor = Color.Red;
                string s1 = btn17.Name;
                btnAction1(s1);
    
            } 
            private void btn16Down_Click(object sender, EventArgs e)
            {
                btn17Down.ForeColor = Color.Red;
                string s1 = btn16.Name;
                btnAction1(s1);
            }
            private void btn16Up_Click(object sender, EventArgs e)
            {
                btn16Up.ForeColor = Color.Red;
                string s1 = btn16.Name;
                btnAction1(s1);
    
            } 
            private void btn15Down_Click(object sender, EventArgs e)
            {
                btn15Down.ForeColor = Color.Red;
                string s1 = btn15.Name;
                btnAction1(s1);
            }
            private void btn15Up_Click(object sender, EventArgs e)
            {
                btn15Up.ForeColor = Color.Red;
                string s1 = btn15.Name;
                btnAction1(s1);
    
            } 
            private void btn14Down_Click(object sender, EventArgs e)
            {
                btn14Down.ForeColor = Color.Red;
                string s1 = btn14.Name;
                btnAction1(s1);
            }
            private void btn14Up_Click(object sender, EventArgs e)
            {
                btn14Up.ForeColor = Color.Red;
                string s1 = btn14.Name;
                btnAction1(s1);
    
            } 
            private void btn13Down_Click(object sender, EventArgs e)
            {
                btn13Down.ForeColor = Color.Red;
                string s1 = btn13.Name;
                btnAction1(s1);
            }
            private void btn13Up_Click(object sender, EventArgs e)
            {
                btn13Up.ForeColor = Color.Red;
                string s1 = btn13.Name;
                btnAction1(s1);
    
            } 
            private void btn12Down_Click(object sender, EventArgs e)
            {
                btn12Down.ForeColor = Color.Red;
                string s1 = btn12.Name;
                btnAction1(s1);
            }
            private void btn12Up_Click(object sender, EventArgs e)
            {
                btn12Up.ForeColor = Color.Red;
                string s1 = btn12.Name;
                btnAction1(s1);
    
            } 
            private void btn11Down_Click(object sender, EventArgs e)
            {
                btn11Down.ForeColor = Color.Red;
                string s1 = btn11.Name;
                btnAction1(s1);
            }
            private void btn11Up_Click(object sender, EventArgs e)
            {
                btn11Up.ForeColor = Color.Red;
                string s1 = btn11.Name;
                btnAction1(s1);
    
            } 
            private void btn10Down_Click(object sender, EventArgs e)
            {
                btn10Down.ForeColor = Color.Red;
                string s1 = btn10.Name;
                btnAction1(s1);
            }
            private void btn10Up_Click(object sender, EventArgs e)
            {
                btn10Up.ForeColor = Color.Red;
                string s1 = btn10.Name;
                btnAction1(s1);
    
            } 
            private void btn9Down_Click(object sender, EventArgs e)
            {
                btn9Down.ForeColor = Color.Red;
                string s1 = btn9.Name;
                btnAction1(s1);
            }
            private void btn9Up_Click(object sender, EventArgs e)
            {
                btn9Up.ForeColor = Color.Red;
                string s1 = btn9.Name;
                btnAction1(s1);
    
            }      
            private void btn8Down_Click(object sender, EventArgs e)
            {
                btn8Down.ForeColor = Color.Red;
                string s1 = btn8.Name;
                btnAction1(s1);
            }
            private void btn8Up_Click(object sender, EventArgs e)
            {
                btn8Up.ForeColor = Color.Red;
                string s1 = btn8.Name;
                btnAction1(s1);
    
            }
            private void btn7Down_Click(object sender, EventArgs e)
            {
                btn7Down.ForeColor = Color.Red;
                string s1 = btn7.Name;
                btnAction1(s1);
            }
            private void btn7Up_Click(object sender, EventArgs e)
            {
                btn7Up.ForeColor = Color.Red;
                string s1 = btn7.Name;
                btnAction1(s1);
    
            }
            private void btn6Up_Click(object sender, EventArgs e)
            {
                btn6Up.ForeColor = Color.Red;
                string s1 = btn6.Name;
                btnAction1(s1);
            }
            private void btn6Down_Click(object sender, EventArgs e)
            {
                btn6Down.ForeColor = Color.Red;
                string s1 = btn6.Name;
                btnAction1(s1);
            }
            private void btn5Up_Click(object sender, EventArgs e)
            {
                btn5Up.ForeColor = Color.Red;
                string s1 = btn5.Name;
                btnAction1(s1);
            }
            private void btn5Down_Click(object sender, EventArgs e)
            {
                btn5Down.ForeColor = Color.Red;
                string s1 = btn5.Name;
                btnAction1(s1);
            }
            private void btn4Up_Click(object sender, EventArgs e)
            {
                btn4Up.ForeColor = Color.Red;
                string s1 = btn4.Name;
                btnAction1(s1);
            }
            private void btn4Down_Click(object sender, EventArgs e)
            {
                btn4Down.ForeColor = Color.Red;
                string s1 = btn4.Name;
                btnAction1(s1);
            }
            private void btn3Up_Click(object sender, EventArgs e)
            {
                btn3Up.ForeColor = Color.Red;
                string s1 = btn3.Name;
                btnAction1(s1);
            }
            private void btn3Down_Click(object sender, EventArgs e)
            {
                btn3Down.ForeColor = Color.Red;
                string s1 = btn3.Name;
                btnAction1(s1);
            }
            private void btn2Up_Click(object sender, EventArgs e)
            {
                btn2Up.ForeColor = Color.Red;
                string s1 = btn2.Name;
                btnAction1(s1);
            }
            private void btn2Down_Click(object sender, EventArgs e)
            {
                btn2Up.ForeColor = Color.Red;
                string s1 = btn2.Name;
                btnAction1(s1);
            }
            private void btn1Up_Click(object sender, EventArgs e)
            {
                btn1Up.ForeColor = Color.Red;
                string s1 = btn1.Name;
                btnAction1(s1);
            }
            private void btn1Down_Click(object sender, EventArgs e)
            {
                btn1Down.ForeColor = Color.Red;
                string s1 = btn1.Name;
                btnAction1(s1);
    
            }
            public void btnAction(string s1)//形成队列处理函数一
            {
                isRequest[getFloor(s1)]=1;
                if (getFloor(s1) < l.Num)
                {
                    lbldown.ForeColor = Color.Red;
                    lbDown.ForeColor = Color.Red;
                }
                else if (getFloor(s1) > l.Num)
                {
                    lblup.ForeColor = Color.Red;
                    lbUp.ForeColor = Color.Red;
                }
                //l.Num = getFloor(s1);
                Squeue.msg[getFloor(s1)] = getFloor(s1);//将楼层存入数组
                isRequest[getFloor(s1)] = 0;//确定已存入
     
                 //     l.Num = Squeue.msg[temp];//如何访问数组里的值
          /*   while(temp<=getFloor(s1))
                {
                    if (Squeue.msg[temp] != 0)
                    {
                        l.Num = Squeue.msg[temp];
                        lbNum.Text = l.Num.ToString();
                        lbFloorNum.Text = l.Num.ToString();
                    }
                   
                  
                    delay.Start();
                    //move.Interval = 1000;
                   // move.Start();
                    temp++;
                }
                        */
                    
               
                    
                
            }
    
            //电梯外上下键的按钮动作
            public void btnAction1(string s1)//形成队列处理函数一
            {
               // isRequest[getFloor(s1)] = 1;
               // isRequest[getFloor(s1)] = 1;
                if (getFloor(s1) < l.Num)
                {
                    lbldown.ForeColor = Color.Red;
                    lbDown.ForeColor = Color.Red;
                }
                else if (getFloor(s1) > l.Num)
                {
                    lblup.ForeColor = Color.Red;
                    lbUp.ForeColor = Color.Red;
                }
                //l.Num = getFloor(s1);
                Squeue.msg1[getFloor(s1)] = getFloor(s1);//将楼层存入数组
              //  isRequest[getFloor(s1)] = 0;//确定已存入
                    
                      
             }
    
     
            //防止超载
            private void control_Click(object sender, EventArgs e)
            {
    
                maxPerson = Convert.ToInt32(tbIn.Text);
                if (maxPerson > l.PersonLimit)
                    MessageBox.Show("人数超");
            }
            private void btnHelp_Click(object sender, EventArgs e)
            {
                MessageBox.Show("发送求助");
            }
            private void delay_Tick(object sender, EventArgs e)
            {
              
                
           
             }
            void continue_run()
            {
            
            }
            private void move1_Tick(object sender, EventArgs e)
            {     
           
                
                if (NumFloor < l.Num)
                {
                    lblup.ForeColor = Color.Red;
                    for (int i = panel3.Height - NumFloor * n; i >= getfloorLength(); i--)
                    {
                       
                        lift.Location = new Point(3, i);
                        //判断有没有请求
                        //if(isRequest[NumFloor-1]==1)
                           // MessageBox.Show("有人出");
                        System.Threading.Thread.CurrentThread.Join(10);
                    }
                }
                else
                {
                    lbldown.ForeColor = Color.Red;
                    for (int i = panel3.Height - NumFloor * n; i <= getfloorLength(); i++)
                    {
                        
                        lift.Location = new Point(3, i);
                       System.Threading.Thread.CurrentThread.Join(10);
                    }
                }
                
                openDoor.Interval = 500;
                openDoor.Start();
               // this.Focus();
    
                System.Threading.Thread.CurrentThread.Join(1000);
                JudgeFloor(NumFloor);
    
                NumFloor = l.Num;
                RecordFloor[0] = l.Num;
                lblup.ForeColor = Color.DimGray;
                lbldown.ForeColor = Color.DimGray;
    
                lbUp.ForeColor = Color.DimGray;
                lbDown.ForeColor = Color.DimGray;
    
                //closeDoor.Interval = 500;
                //closeDoor.Start();
               // this.Focus();
                move1.Stop();
      
            }
            private void panel3_Click(object sender, EventArgs e)
            {
                closeDoor.Interval = 500;
                closeDoor.Start();
                while (k1 < 21)
                {
                    k1++;
                    if (Squeue.msg1[k1] != 0)
                    {
                        l.Num = Squeue.msg1[k1];
                        lbNum.Text = l.Num.ToString();
                        lbFloorNum.Text = l.Num.ToString();
    
                        move1.Interval = 1000;
                        move1.Start();
                        break;
                    }
    
                }
                if (k1 >= 21)
                    k1 = 0;
    
               // this.Focus();
            }
    
          


     

    • 功能截图
      运行中的截图
       

           运行结束后:
             
              人数限制:
             
              应急设置(HELP)
             

     

  • 相关阅读:
    洛谷P3003 [USACO10DEC]苹果交货Apple Delivery
    洛谷P1576 最小花费
    洛谷P1821 [USACO07FEB]银牛派对Silver Cow Party
    洛谷P1948 [USACO08JAN]电话线Telephone Lines
    洛谷P3371【模板】单源最短路径
    洛谷P2384最短路
    FirstOfAll
    Proxy模式:管理第三方API
    Abstract Server模式,Adapter模式和Bridge模式
    Observer模式
  • 原文地址:https://www.cnblogs.com/feelwell/p/3614879.html
Copyright © 2011-2022 走看看