Exemplo n.º 1
0
        private void MapWindow_KeyDown(object sender, KeyEventArgs e)
        {
            if (this.keyboardAction == null)
            {
                this.keyboardAction = new CarAction()
                {
                    Duration = 999
                };
            }
            if (e.Key == Key.Up || e.Key == Key.W)
            {
                upPressed = true;
            }
            //this.keyboardAction.MoveAction = MoveAction.Forward;
            else if (e.Key == Key.Down || e.Key == Key.S)
            {
                downPressed = true;
            }
            //this.keyboardAction.MoveAction = MoveAction.Backward
            else if (e.Key == Key.Left || e.Key == Key.A)
            {
                leftPressed = true;
            }
            //this.keyboardAction.Direction = Direction.Left;
            else if (e.Key == Key.Right || e.Key == Key.D)
            {
                rightPressed = true;
            }
            //this.keyboardAction.Direction = Direction.Right;

            if ((e.Key == Key.Up || e.Key == Key.W || e.Key == Key.Down || e.Key == Key.S) ||
                (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.A || e.Key == Key.D))
            {
                refreshForcesCozKeyboard();
                if (this.keyboardAction.Duration < 50)
                {
                    //this.keyboardAction.Duration = 1000;
                }
                //ext.ActionsList.Add(this.keyboardAction);
            }
        }
Exemplo n.º 2
0
        private void moveForwardBtn_Click(object sender, RoutedEventArgs e)
        {
            Direction        direction;
            List <CarAction> actionsList = ext.ActionsList;
            CarAction        carAction   = new CarAction()
            {
                MoveAction = MoveAction.Forward
            };
            CarAction carAction1 = carAction;

            if (this.turnLeftCheckBox.IsChecked.Value)
            {
                direction = Direction.Left;
            }
            else
            {
                direction = (this.turnRightCheckBox.IsChecked.Value ? Direction.Right : Direction.Straight);
            }
            carAction1.Direction = direction;
            carAction.Duration   = double.Parse(this.timeTxt.Text);
            actionsList.Add(carAction);
        }
Exemplo n.º 3
0
        private void theTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            double movingStep;

            if (ext.ActionsList.Count != 0)
            {
                CarAction carAction = ext.ActionsList[0];
                if (carAction.Duration > 0)
                {
                    Action action = null;
                    double num    = RandomMersene.genrand_real1() * ((RandomMersene.genrand_bool() ? -1.0 : 1.0));
                    if (carAction.MoveAction == MoveAction.SmartMovement)
                    {
                        action              = () => this.theCar.translateRotateCuplu();
                        carAction.Duration -= this.theTimer.Interval / 1000;
                    }
                    else if (carAction.Direction != Direction.Straight)
                    {
                        movingStep         = (double)((carAction.MoveAction == MoveAction.Forward ? 1 : -1)) * ext.MovingStep + num * ext.deviationPercent / 100 * ext.MovingStep;
                        action             = () => this.theCar.autoTranslateRotate(movingStep, carAction.Direction);
                        carAction.Duration = carAction.Duration - this.theTimer.Interval / 1000;
                    }
                    else
                    {
                        movingStep         = (double)((carAction.MoveAction == MoveAction.Forward ? 1 : -1)) * ext.MovingStep + num * ext.deviationPercent / 100 * ext.MovingStep;
                        action             = () => this.theCar.Move(movingStep);
                        carAction.Duration = carAction.Duration - this.theTimer.Interval / 1000;
                    }
                    System.Windows.Threading.Dispatcher dispatcher = base.Dispatcher;
                    if (action != null)
                    {
                        Action action1 = () =>
                        {
                            if (action != null)
                            {
                                action();
                            }
                            this.RefreshShits();
                        };
                        if (!dispatcher.CheckAccess())
                        {
                            try
                            {
                                dispatcher.Invoke(action1);
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            action1();
                        }
                    }
                }
                else
                {
                    ext.ActionsList.Remove(carAction);
                }
            }
            if (tmpRefreshShitsTimes > 0)
            {
                Action action1 = () =>
                {
                    this.theCar.autoTranslateRotate(0, Direction.Left);
                    this.RefreshShits();
                };
                System.Windows.Threading.Dispatcher dispatcher = base.Dispatcher;
                if (!dispatcher.CheckAccess())
                {
                    try
                    {
                        dispatcher.Invoke(action1);
                    }
                    catch
                    {
                    }
                }
                else
                {
                    action1();
                }
                tmpRefreshShitsTimes--;
            }
        }