Ejemplo n.º 1
0
        public BasicForm(Speedometer s, GearChanger gc, Clutch c)
        {
            this.s  = s;
            this.gc = gc;
            this.c  = c;

            InitializeComponent();
        }
Ejemplo n.º 2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Speedometer s  = new Speedometer();
            GearChanger gc = new GearChanger();
            Clutch      c  = new Clutch();
            BasicForm   f  = new BasicForm(s, gc, c);

            f.MinimumSize = new System.Drawing.Size(500, 500);
            f.MaximumSize = new System.Drawing.Size(500, 500);
            f.MaximizeBox = false;
            f.MinimizeBox = false;
            Application.Run(f);
        }
Ejemplo n.º 3
0
        public void Release(Speedometer s, GearChanger gc)
        {
            this.pressedClutch = false;
            int currentGear = gc.getGear();

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true; //must wait a time gap till pedal is released fully
                w = new Waiter(10);
                w.RunThread();
            }).Start();
            if (currentGear > this.lastGear)
            {
                if (this.lastSpeed > 60f)
                {
                    s.setSpeed(this.lastSpeed - 25f);
                }
                else if (this.lastSpeed < 20f)
                {
                    s.KillEngine();
                    Console.WriteLine("engine stopped " + this.lastSpeed.ToString());
                }
            }
            else if (currentGear < this.lastGear)
            {
                if (currentGear != 0)
                {
                    if (this.lastSpeed < 120f && this.lastSpeed > 20f)
                    {
                        s.setSpeed(this.lastSpeed + 25f);
                    }
                    else if (this.lastSpeed < 20f)
                    {
                        s.KillEngine();
                        Console.WriteLine("engine stopped ");
                    }
                }
            }
            else if (currentGear == this.lastGear && currentGear != 0)
            {
                s.setSpeed(this.lastSpeed);
            }
        }
Ejemplo n.º 4
0
        public void Press(Speedometer s, GearChanger gc)
        {
            this.pressedClutch = true;
            this.lastSpeed     = s.getSpeed();
            this.lastGear      = gc.getGear();
            //need to make this function unblocking
            if (gc.getGear() != 0)
            {
                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    while (this.isClutchPressed()) //while engine isn't engaged
                    {
                        System.Threading.Thread.Sleep(10);
                        s.decreaseSpeed(5f);
                    }
                }).Start();


                this.pressFinished = true;
            }
        }
Ejemplo n.º 5
0
 public PainterUpdater2(BasicForm f, GearChanger gc)
 {
     g = f.CreateGraphics();
     this.f = f;
     this.gc = gc;
 }