Making a simple elevator system in c#, got it working for when yuo select a floor by typing in a floor number, the lift then goes to this floor.
The next stage is to select a floor using a button. The problem is when the lift gets to the floor that the user requested, the program does not accept the input from a button..
This is the code i have to call the lift movement and switch the timer on:
private void liftOneMove()
{
if ((liftOne.Direction == 1) && (lift1.Value <= 40)) // while lifts going up and floor less/equal to 40
{
timer1.Enabled = true;
}
}
This is the code within the timer:
private void timer1_Tick(object sender, EventArgs e)
{
lift1.Value++;
liftOne.CurrentFloor = lift1.Value;
lblLift1Flr.Text = "" + lift1.Value;
if (liftOne.FloorRequests.Exists(element => element == lift1.Value))
{
RbLift1.Checked = true;
lblLift1Current.Text = "Doors opening";
//Need to pause the timer here to allow user to select a floor
liftOne.FloorRequests.Remove(lift1.Value);
if(liftOne.FloorRequests.Count == 0)
{
liftOne.Direction = 2;
timer1.Enabled = false;
MessageBox.Show("Floor Requests " + liftOne.FloorRequests.Count);
}
}
}