C#で簡単なエレベーターシステムを作成し、フロア番号を入力してフロアを選択すると、リフトがそのフロアに移動します。
次の段階は、ボタンを使用してフロアを選択することです。問題は、リフトがユーザーが要求した階に到達したときに、プログラムがボタンからの入力を受け付けないことです..
これは、リフトの動きを呼び出してタイマーをオンにする必要があるコードです。
private void liftOneMove()
{
if ((liftOne.Direction == 1) && (lift1.Value <= 40)) // while lifts going up and floor less/equal to 40
{
timer1.Enabled = true;
}
}
これはタイマー内のコードです。
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);
}
}
}