Esempio n. 1
0
 public override void RunThread()
 {
     while (true)
     {
         if (gc.isChange())
         {
             l = f.getGear();
             Action action_update_l = () => l.Text = gc.getGear().ToString();
             f.Invoke(action_update_l);
             gc.setChange(false);
         }
     }
 }
Esempio n. 2
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;
            }
        }
Esempio 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);
            }
        }
Esempio n. 4
0
        public void BasicForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 81 && !c.isClutchPressed()) //if press clutch (q) and haven't before
            {
                Action action = () => c.Press(s, gc);
                this.Invoke(action);
            }
            else if (e.KeyValue == 80 && c.isClutchPressed() && !Waiter.getStop())   //if press shift_up(p) and clutch is pressed
            {
                gc.ShiftUP(s);
            }
            else if (e.KeyValue == 76 && c.isClutchPressed() && !Waiter.getStop())
            {
                gc.ShiftDOWN(s);
            }
            else if (e.KeyValue == 87 && !Waiter.getStop() && !c.isClutchPressed())
            {
                s.setwPressed(true);
                switch (gc.getGear())
                {
                case 0:
                    s.increaseSpeed(8f);
                    break;

                case 1:
                    s.increaseSpeed(2f);
                    break;

                case 2:
                    s.increaseSpeed(1.5f);
                    break;

                case 3:
                    s.increaseSpeed(1f);
                    break;

                case 4:
                    s.increaseSpeed(0.9f);
                    break;

                case 5:
                    s.increaseSpeed(0.7f);
                    break;

                case 6:
                    s.increaseSpeed(0.5f);
                    break;
                }
            }
            else if (e.KeyValue == 81 && s.getwPressed())
            {
                s.setwPressed(false);
                Action action = () => c.Press(s, gc);
                this.Invoke(action);
            }
            else if (e.KeyValue == 87 && c.isClutchPressed() && gc.getGear() == 1)
            {
                s.Ignition();
                c.setLastSpeed(30f);
                s.setSpeed(30f);
            }
        }