Example #1
0
        private void CreateCargoEllipse()
        {
            engine.Map.CreateCargos();
            var cargos = engine.Map.Cargos;

            CargoEllipse cargoEllipse = new CargoEllipse(cargos[cargos.Count - 1]);

            cargoEllipse.Position = GetNextCargoPosition();
            cargoEllipse.Cargo.X  = (int)cargoEllipse.Position.X;
            cargoEllipse.Cargo.Y  = (int)cargoEllipse.Position.Y;

            cargoEllipse.UiElement = new Ellipse()
            {
                Width  = robotSquareSize,
                Height = robotSquareSize,
                Fill   = cargoEllipse.Color
            };
            cargoElls.Add(cargoEllipse);
            GameArea.Children.Add(cargoEllipse.UiElement);
            GameArea.Children.Add(cargoEllipse.Weight);
        }
Example #2
0
        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Up:
                robotDirection = RobotDirection.Up;
                MoveRobot();
                break;

            case Key.Down:
                robotDirection = RobotDirection.Down;
                MoveRobot();
                break;

            case Key.Left:
                robotDirection = RobotDirection.Left;
                MoveRobot();
                break;

            case Key.Right:
                robotDirection = RobotDirection.Right;
                MoveRobot();
                break;

            case Key.Enter:
                PickUpCargo();
                break;

            case Key.U:
                try
                {
                    engine.UndoCommandExecuter();

                    GameArea.Children.Remove(robotSquare.UiElement);
                    robotSquare.Position = new Point(robotSquare.Robot.X,
                                                     robotSquare.Robot.Y);
                    DrawRobot();

                    foreach (CargoEllipse cargoEllipse in cargoElls.ToArray())
                    {
                        GameArea.Children.Remove(cargoEllipse.UiElement);
                        GameArea.Children.Remove(cargoEllipse.Weight);
                        cargoElls.Remove(cargoEllipse);
                    }

                    foreach (Cargo cargo in engine.Map.Cargos)
                    {
                        CargoEllipse cargoEllipse = new CargoEllipse(cargo);
                        cargoEllipse.Position  = new Point(cargo.X, cargo.Y);
                        cargoEllipse.UiElement = new Ellipse()
                        {
                            Width  = robotSquareSize,
                            Height = robotSquareSize,
                            Fill   = cargoEllipse.Color
                        };
                        cargoElls.Add(cargoEllipse);
                        GameArea.Children.Add(cargoEllipse.UiElement);
                        GameArea.Children.Add(cargoEllipse.Weight);
                        DrawCargo();
                    }

                    UpdateGameStatus();
                }
                catch (CantUndoException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                break;
            }
        }