I am currently trying to create a test road track with 2 cars one Red and one Blue which will run round the circuit from wait panel to wait panel once the buttons are clicked but no 2 cars can be in the same wait panel at the same time and each car must do a circuit of the track, but i'm currently having problems getting the cars to run the circuit, they just seem to run in each of the panels at the same time, how many semaphores and buffers do you need and how is this implemented and is there an easier way to work it out and there relationship to get them to circuit the track
using System; using System.Windows.Forms; using System.Threading; using System.ComponentModel; using System.Collections; using System.Data; using System.Drawing;
semThread = new Thread(new ThreadStart(semaphore.Start)); buffThread = new Thread(new ThreadStart(buffer.Start));
thread1 = new Thread(new ThreadStart(p1.Start)); thread2 = new Thread(new ThreadStart(p2.Start));
thread3 = new Thread(new ThreadStart(w1.Start)); thread4 = new Thread(new ThreadStart(w2.Start)); thread5 = new Thread(new ThreadStart(w3.Start)); thread6 = new Thread(new ThreadStart(w4.Start)); thread7 = new Thread(new ThreadStart(w5.Start)); thread8 = new Thread(new ThreadStart(w6.Start));
this.Closing += new CancelEventHandler(this.Form1_Closing);
protected override void Dispose(bool disposing) { if (disposing) { if (components != null) components.Dispose(); } base.Dispose(disposing); }
private void InitializeComponent() { this.pnl1 = new System.Windows.Forms.Panel(); this.btn1 = new System.Windows.Forms.Button(); this.pnl2 = new System.Windows.Forms.Panel(); this.btn3 = new System.Windows.Forms.Button(); this.wait1 = new System.Windows.Forms.Panel(); this.wait2 = new System.Windows.Forms.Panel(); this.wait3 = new System.Windows.Forms.Panel(); this.wait4 = new System.Windows.Forms.Panel(); this.wait5 = new System.Windows.Forms.Panel(); this.wait6 = new System.Windows.Forms.Panel(); this.pnl1.SuspendLayout(); this.pnl2.SuspendLayout(); this.SuspendLayout();
this.pnl1.BackColor = System.Drawing.Color.White; this.pnl1.Controls.Add(this.btn1); this.pnl1.Location = new System.Drawing.Point(130, 4); this.pnl1.Name = "pnl1"; this.pnl1.Size = new System.Drawing.Size(30, 178); this.pnl1.TabIndex = 0;
SolidBrush brush = new SolidBrush(colour); g.FillRectangle(brush, plane.X, plane.Y, 10, 10);
brush.Dispose(); g.Dispose(); } }
public class WaitPanelThread { private Point origin; private int delay; private Panel panel; private bool westEast; private Color colour; private Point plane; private int xDelta; private int yDelta; private Semaphore semaphore; private Buffer buffer;
public class WaitPanelThreadWest { private Point origin; private int delay; private Panel panel; private bool westEast; private Color colour; private Point plane; private int xDelta; private int yDelta; private Semaphore semaphore; private Buffer buffer;
public class WaitPanelThreadDown { private Point origin; private int delay; private Panel panel; private bool westEast; private Color colour; private Point plane; private int xDelta; private int yDelta; private Semaphore semaphore; private Buffer buffer;
public class WaitPanelThreadDownUp { private Point origin; private int delay; private Panel panel; private bool westEast; private Color colour; private Point plane; private int xDelta; private int yDelta; private Semaphore semaphore; private Buffer buffer;
Question
Sarkhan Vol
I am currently trying to create a test road track with 2 cars one Red and one Blue which will run round the circuit from wait panel to wait panel once the buttons are clicked but no 2 cars can be in the same wait panel at the same time and each car must do a circuit of the track, but i'm currently having problems getting the cars to run the circuit, they just seem to run in each of the panels at the same time, how many semaphores and buffers do you need and how is this implemented and is there an easier way to work it out and there relationship to get them to circuit the track
Link to comment
Share on other sites
2 answers to this question
Recommended Posts