public void AlarmFixed() { heisState = HeisState.Running; }
public HeisControls(int numberOfFloors, int initialFloor) { this.numberOfFloors = numberOfFloors; currentFloor = initialFloor; floorsSelected = new List <int>(numberOfFloors); betweenFloorTime = new TimeSpan(0, 0, 3); heisState = HeisState.Running; floorRunner = new Thread(() => { while (true) { List <int> directionList = new List <int>(); lock (threadKey) { if (floorsSelected.Count > 0 && heisState == HeisState.Running) { if (floorsSelected.Contains(currentFloor)) { Console.WriteLine("At {0}", currentFloor); floorsSelected.Remove(floorsSelected.Where(a => a == currentFloor).First()); Thread.Sleep(betweenFloorTime); } else { if (goingUp) { var sameWay = from f in floorsSelected where f > currentFloor select f; if (sameWay.Count() > 0) { nextFloor = sameWay.Min(); } else { goingUp = false; nextFloor = floorsSelected.Max(); } } else { var sameWay = from f in floorsSelected where f < currentFloor select f; if (sameWay.Count() > 0) { nextFloor = sameWay.Max(); } else { goingUp = true; nextFloor = floorsSelected.Min(); } } } } else { if (heisState == HeisState.Running) { Console.WriteLine("No floor selected current flor is {0}", currentFloor); } else { Console.WriteLine("Alarm at {0}", currentFloor); } } } Thread.Sleep(betweenFloorTime); if (nextFloor > currentFloor && heisState == HeisState.Running) { Console.WriteLine("Moving up"); currentFloor++; } else if (nextFloor < currentFloor && heisState == HeisState.Running) { Console.WriteLine("Moving down"); currentFloor--; } Console.WriteLine("Current floor {0}", currentFloor); } }); }
public void Alarm() { heisState = HeisState.Alarm; }