예제 #1
0
 /// <summary>
 /// As the lift moves, this function should be called every tick to check the current
 /// location of the lift. As the lift moves between floors this will set the currentFloor
 /// variable to the correct value.
 /// </summary>
 public void SetCurrentFloor()
 {
     if (currentDirection == Direction.UP)
     {
         if ((floor_y[0] > liftImage.Top && floor_y[1] < liftImage.Top) || floor_y[0] == liftImage.Top)
         {
             currentFloor = 0;
         }
         else if ((floor_y[1] > liftImage.Top && floor_y[2] < liftImage.Top) || floor_y[1] == liftImage.Top)
         {
             currentFloor = 1;
         }
         else if ((floor_y[2] > liftImage.Top && floor_y[3] < liftImage.Top) || floor_y[2] == liftImage.Top)
         {
             currentFloor = 2;
         }
         else if ((floor_y[3] > liftImage.Top && floor_y[4] < liftImage.Top) || floor_y[3] == liftImage.Top)
         {
             currentFloor = 3;
         }
         else if (floor_y[4] == liftImage.Top)
         {
             currentFloor = 4;
         }
         else
         {
             currentFloor = -1; // this should not happen
         }
     }
     else if (currentDirection == Direction.DOWN)
     {
         if ((floor_y[4] < liftImage.Top && floor_y[3] > liftImage.Top) || floor_y[4] == liftImage.Top)
         {
             currentFloor = 4;
         }
         else if ((floor_y[3] < liftImage.Top && floor_y[2] > liftImage.Top) || floor_y[3] == liftImage.Top)
         {
             currentFloor = 3;
         }
         else if ((floor_y[2] < liftImage.Top && floor_y[1] > liftImage.Top) || floor_y[2] == liftImage.Top)
         {
             currentFloor = 2;
         }
         else if ((floor_y[1] < liftImage.Top && floor_y[0] > liftImage.Top) || floor_y[1] == liftImage.Top)
         {
             currentFloor = 1;
         }
         else if (floor_y[0] == liftImage.Top)
         {
             currentFloor = 0;
         }
         else
         {
             currentFloor = -1; // this should not happen
         }
     }
     mainForm.UpdateFloorDisp(currentFloor, liftID);
 }
예제 #2
0
        /************************************************************************************************/


        /// <summary>
        /// Create a new Lift object.
        /// </summary>
        /// <param name="limg">The PictureBox control this Lift object is associated to.</param>
        /// <param name="fy">The list of floor y coordinates</param>
        /// <param name="sf">The floor the lift will idle/start on</param>
        /// <param name="mf">The main form (pass in 'this')</param>
        public Lift(PictureBox limg, int[] fy, int sf, frmLiftSim mf, int id)
        {
            liftImage = limg;
            floor_y   = fy;
            idleFloor = sf;
            mainForm  = mf;
            liftID    = id;

            liftImage.Top = floor_y[idleFloor];  // Move lift to the start position
            currentFloor  = idleFloor;           // Set the lift's current position

            mainForm.AddToLog("Lift " + liftID + " initialised. Start floor: " + currentFloor);

            dtMove.Interval = TimeSpan.FromMilliseconds(20);
            dtMove.Tick    += new EventHandler(dtMove_Tick);

            dtWait.Interval = TimeSpan.FromSeconds(2);
            dtWait.Tick    += new EventHandler(dtWait_Tick);

            mainForm.UpdateFloorDisp(currentFloor, liftID);
        }
예제 #3
0
파일: Lift.cs 프로젝트: Xiol/Lift-Simulator
        private int nextDestFloor; // Next floor the lift is heading to

        #endregion Fields

        #region Constructors

        /************************************************************************************************/
        /// <summary>
        /// Create a new Lift object.
        /// </summary>
        /// <param name="limg">The PictureBox control this Lift object is associated to.</param>
        /// <param name="fy">The list of floor y coordinates</param>
        /// <param name="sf">The floor the lift will idle/start on</param>
        /// <param name="mf">The main form (pass in 'this')</param>
        public Lift(PictureBox limg, int[] fy, int sf, frmLiftSim mf, int id)
        {
            liftImage = limg;
            floor_y = fy;
            idleFloor = sf;
            mainForm = mf;
            liftID = id;

            liftImage.Top = floor_y[idleFloor];  // Move lift to the start position
            currentFloor = idleFloor;            // Set the lift's current position

            mainForm.AddToLog("Lift " + liftID + " initialised. Start floor: " + currentFloor);

            dtMove.Interval = TimeSpan.FromMilliseconds(20);
            dtMove.Tick += new EventHandler(dtMove_Tick);

            dtWait.Interval = TimeSpan.FromSeconds(2);
            dtWait.Tick += new EventHandler(dtWait_Tick);

            mainForm.UpdateFloorDisp(currentFloor, liftID);
        }