public void Start() { Thread.Sleep(delay); semaphore.Signal(); for (; 0 == 0;) { this.zeroCar(); panel.Invalidate(); buffer.Read(ref this.colour, ref this.endPoint); if (((this.endPoint == 10 && this.panelID == 100) || (this.endPoint == 12 && this.panelID == 120) || (this.endPoint == 8 && this.panelID == 88) || (this.endPoint == 9 && this.panelID == 99) || (this.endPoint == 7 && this.panelID == 77) || (this.endPoint == 11 && this.panelID == 1100) || (this.endPoint == 1 && this.panelID == 11) || (this.endPoint == 3 && this.panelID == 33) || (this.endPoint == 22 && this.panelID == 23) || (this.endPoint == 4 && this.panelID == 44) || (this.endPoint == 6 && this.panelID == 66) || (this.endPoint == 120 && this.panelID == 23) || (this.endPoint == 140 && this.panelID == 44) || (this.endPoint == 161 && this.panelID == 66) || (this.endPoint == 700 && this.panelID == 77) || (this.endPoint == 900 && this.panelID == 99) || (this.endPoint == 1101 && this.panelID == 1100))) { for (int i = 1; i <= steps; i++) { this.moveCar(xDelta, yDelta); Thread.Sleep(delay); panel.Invalidate(); } semaphore2.Wait(); buffer2.Write(this.colour, this.endPoint); semaphore.Signal(); this.colour = Color.White; panel.Invalidate(); } else if ((this.endPoint == 0 && this.panelID == 0) || (this.endPoint == 24 && this.panelID == 0) || (this.endPoint == 401 && this.panelID == 0) || (this.endPoint == 9001 && this.panelID == 0) || (this.endPoint == 8001 && this.panelID == 0)) { steps = 20; for (int i = 1; i <= steps; i++) { this.moveCar(xDelta, yDelta); Thread.Sleep(delay); panel.Invalidate(); } semaphore.Signal(); this.colour = Color.White; panel.Invalidate(); } else if ((this.endPoint == 9 && this.panelID == 160) || (this.endPoint == 7 && this.panelID == 160) || (this.endPoint == 11 && this.panelID == 160) || (this.endPoint == 22 && this.panelID == 110) || (this.endPoint == 4 && this.panelID == 110) || (this.endPoint == 6 && this.panelID == 110) || (this.endPoint == 24 && this.panelID == 160) || (this.endPoint == 120 && this.panelID == 160) || (this.endPoint == 140 && this.panelID == 160) || (this.endPoint == 161 && this.panelID == 160) || (this.endPoint == 401 && this.panelID == 110) || (this.endPoint == 700 && this.panelID == 110) || (this.endPoint == 900 && this.panelID == 110) || (this.endPoint == 1101 && this.panelID == 110) || (this.endPoint == 9001 && this.panelID == 160) || (this.endPoint == 8001 && this.panelID == 110)) { for (int i = 1; i <= steps; i++) { this.moveCar(xDelta, yDelta); Thread.Sleep(delay); panel.Invalidate(); } semaphore2.Wait(); buffer2.Write(this.colour, this.endPoint); semaphore.Signal(); this.colour = Color.White; panel.Invalidate(); } else if ((this.endPoint == 24 && this.panelID == 240) || (this.endPoint == 120 && this.panelID == 240) || (this.endPoint == 140 && this.panelID == 240) || (this.endPoint == 161 && this.panelID == 240) || (this.endPoint == 9001 && this.panelID == 240)) { for (int i = 1; i <= steps; i++) { this.car.X++; Thread.Sleep(delay); panel.Invalidate(); } semaphore2.Wait(); buffer2.Write(this.colour, this.endPoint); semaphore.Signal(); this.colour = Color.White; panel.Invalidate(); } else if ((this.endPoint == 8001 && this.panelID == 240)) { for (int i = 1; i <= steps; i++) { this.car.X--; Thread.Sleep(delay); panel.Invalidate(); } semaphore3.Wait(); buffer3.Write(this.colour, this.endPoint); semaphore.Signal(); this.colour = Color.White; panel.Invalidate(); } else if ((this.endPoint == 401 && this.panelID == 245) || (this.endPoint == 700 && this.panelID == 245) || (this.endPoint == 900 && this.panelID == 245) || (this.endPoint == 1101 && this.panelID == 245) ) { for (int i = 1; i <= steps; i++) { this.car.X--; Thread.Sleep(delay); panel.Invalidate(); } semaphore2.Wait(); buffer2.Write(this.colour, this.endPoint); semaphore.Signal(); this.colour = Color.White; panel.Invalidate(); } else if ((this.endPoint == 9001 && this.panelID == 245)) { for (int i = 1; i <= steps; i++) { this.car.X++; Thread.Sleep(delay); panel.Invalidate(); } semaphore3.Wait(); buffer3.Write(this.colour, this.endPoint); semaphore.Signal(); this.colour = Color.White; panel.Invalidate(); } else if (this.endPoint == 9001 && this.panelID == 888) { steps = 4; for (int i = 1; i <= steps; i++) { this.car.X++; Thread.Sleep(delay); panel.Invalidate(); } semaphore3.Wait(); buffer3.Write(this.colour, this.endPoint); semaphore.Signal(); this.colour = Color.White; panel.Invalidate(); } else if ((this.endPoint == 8001 && this.panelID == 245) || (this.endPoint == 8001 && this.panelID == 288)) { if ((this.endPoint == 8001 && this.panelID == 288)) { steps = 6; } for (int i = 1; i <= steps; i++) { this.car.X--; Thread.Sleep(delay); panel.Invalidate(); } semaphore2.Wait(); buffer2.Write(this.colour, this.endPoint); semaphore.Signal(); this.colour = Color.White; panel.Invalidate(); } else { for (int i = 1; i <= steps; i++) { this.moveCar(xDelta, yDelta); Thread.Sleep(delay); panel.Invalidate(); } semaphore1.Wait(); buffer1.Write(this.colour, this.endPoint); semaphore.Signal(); this.colour = Color.White; panel.Invalidate(); } } }
public void Starts() // starts { Thread.Sleep(delay); locked = false; // this means the parking button is locked till the car is coming semaphore.Signal(); for (; 0 == 0;) { buffer.Read(ref this.colour, ref this.endPoint); if ((this.endPoint == this.panelID) || (this.endPoint == 700 && this.panelID == 7) || (this.endPoint == 900 && this.panelID == 9) || (this.endPoint == 1101 && this.panelID == 11)) // this is working for parking panels { this.origin = new Point(100, 30); // starting point of moving car this.zeroCar(); panel.Invalidate(); lock (this) { while (locked) { Monitor.Wait(this); } } steps = 5; for (int i = 1; i <= steps; i++) { this.moveCar(xDelta, yDelta); Thread.Sleep(delay); panel.Invalidate(); } locked = true; this.btn.BackColor = locked ? Color.Red : Color.Green; this.endPoint = 0; this.origin = new Point(45, 30); // parking slot stop point this.yDelta = 0; this.xDelta = 5; // moving direction of the car in the parking panel ,once you clicked the parking button. buffer.Write(this.colour, this.endPoint); } else if ((this.endPoint == 8 && this.panelID == 80) || (this.endPoint == 10 && this.panelID == 100) || (this.endPoint == 12 && this.panelID == 120) || (this.endPoint == 22 && this.panelID == 20) || (this.endPoint == 4 && this.panelID == 40) || (this.endPoint == 6 && this.panelID == 60) || (this.endPoint == 9 && this.panelID == 99) || (this.endPoint == 120 && this.panelID == 20) || (this.endPoint == 140 && this.panelID == 40) || (this.endPoint == 161 && this.panelID == 60)) { this.origin = new Point(10, 30); this.zeroCar(); panel.Invalidate(); lock (this) { while (locked) { Monitor.Wait(this); } } steps = 5; for (int i = 1; i <= steps; i++) { this.moveCar(xDelta, yDelta); Thread.Sleep(delay); panel.Invalidate(); } locked = true; this.btn.BackColor = locked ? Color.Red : Color.Green; this.endPoint = 0; this.origin = new Point(45, 30); // parking slot stop point this.yDelta = 0; this.xDelta = -5; // once clicked the parking button , moving direction of the car buffer.Write(this.colour, this.endPoint); } else { this.zeroCar(); panel.Invalidate(); lock (this) { while (locked) { Monitor.Wait(this); } } for (int i = 1; i <= steps; i++) { this.moveCar(xDelta, yDelta); Thread.Sleep(delay); panel.Invalidate(); } semaphore1.Wait(); buffer1.Write(this.colour, this.endPoint); semaphore.Signal(); this.colour = Color.LightYellow; panel.Invalidate(); } } }