예제 #1
0
        public Action(MoveCommand.Commands moveCommand     = MoveCommand.Commands.None,
                      ChargeCommand.Commands chargeCommand = ChargeCommand.Commands.None,
                      TurretCommand.Commands turretCommand = TurretCommand.Commands.None)
        {
            commands = new Command[(int)Types.Count];

            commands[(int)Types.Move]   = new MoveCommand(moveCommand);
            commands[(int)Types.Charge] = new ChargeCommand(chargeCommand);
            commands[(int)Types.Turret] = new TurretCommand(turretCommand);
        }
예제 #2
0
 private void MoveAndRotate(MoveCommand.Commands where, float rotation)
 {
     if ((NormalizedRotation / 45.0) % 2 == 1)
     {
         MoveTo(where);
         RotateBy(rotation);
     }
     else
     {
         RotateBy(rotation);
         MoveTo(where);
     }
 }
        private static void DgvAlgorithm_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            DataGridViewRow row = ((DataGridView)sender).Rows[e.RowIndex];

            // Собираем команды с добавленного DataGridViewRow
            MoveCommand.Commands   moveCommand   = Utilities.ToMoveCommand(row.Cells[1].Value.ToString());
            ChargeCommand.Commands chargeCommand = Utilities.ToChargeCommand(row.Cells[2].Value.ToString());
            TurretCommand.Commands turretCommand = Utilities.ToTurretCommand(row.Cells[3].Value.ToString());

            // Добавляем Action в соответствующий алгоритм танка
            Action action = new Action(moveCommand, chargeCommand, turretCommand);

            ParallelAlgorithm.GetInstance().InsertAction((int)((DataGridView)sender).Tag, action, e.RowIndex);
        }
예제 #4
0
        public void MovementCommand(MoveCommand.Commands command)
        {
            switch (command)
            {
            case MoveCommand.Commands.Forward:
                MoveTo(MoveCommand.Commands.Forward);
                break;

            case MoveCommand.Commands.Backward:
                MoveTo(MoveCommand.Commands.Backward);
                break;

            case MoveCommand.Commands.Rotate90CW:
                RotateBy(90);
                break;

            case MoveCommand.Commands.Rotate90CCW:
                RotateBy(-90);
                break;

            case MoveCommand.Commands.Rotate45CW:
                RotateBy(45);
                break;

            case MoveCommand.Commands.Rotate45CCW:
                RotateBy(-45);
                break;

            case MoveCommand.Commands.Forward45CW:
                MoveAndRotate(MoveCommand.Commands.Forward, 45.0f);
                break;

            case MoveCommand.Commands.Forward45CCW:
                MoveAndRotate(MoveCommand.Commands.Forward, -45.0f);
                break;

            case MoveCommand.Commands.Backward45CW:
                MoveAndRotate(MoveCommand.Commands.Backward, 45.0f);
                break;

            case MoveCommand.Commands.Backward45CCW:
                MoveAndRotate(MoveCommand.Commands.Backward, -45.0f);
                break;

            default:
                break;
            }
        }
예제 #5
0
        private void MoveTo(MoveCommand.Commands where)
        {
            int       sign     = where == MoveCommand.Commands.Forward ? 1 : -1;
            const int rotation = 45;

            // Вверх
            if (NormalizedRotation == rotation * 0)
            {
                MoveBy(new Vector2f(0, -Utilities.GetInstance().TILE_SIZE *sign));
            }
            // Вверх-вправо
            if (NormalizedRotation == rotation * 1)
            {
                MoveBy(new Vector2f(Utilities.GetInstance().TILE_SIZE *sign, -Utilities.GetInstance().TILE_SIZE *sign));
            }
            // Вправо
            if (NormalizedRotation == rotation * 2)
            {
                MoveBy(new Vector2f(Utilities.GetInstance().TILE_SIZE *sign, 0));
            }
            // Вправо-вниз
            if (NormalizedRotation == rotation * 3)
            {
                MoveBy(new Vector2f(Utilities.GetInstance().TILE_SIZE *sign, Utilities.GetInstance().TILE_SIZE *sign));
            }
            // Вниз
            if (NormalizedRotation == rotation * 4)
            {
                MoveBy(new Vector2f(0, Utilities.GetInstance().TILE_SIZE *sign));
            }
            // Вниз-влево
            if (NormalizedRotation == rotation * 5)
            {
                MoveBy(new Vector2f(-Utilities.GetInstance().TILE_SIZE *sign, Utilities.GetInstance().TILE_SIZE *sign));
            }
            // Влево
            if (NormalizedRotation == rotation * 6)
            {
                MoveBy(new Vector2f(-Utilities.GetInstance().TILE_SIZE *sign, 0));
            }
            // Влево-вверх
            if (NormalizedRotation == rotation * 7)
            {
                MoveBy(new Vector2f(-Utilities.GetInstance().TILE_SIZE *sign, -Utilities.GetInstance().TILE_SIZE *sign));
            }

            CheckCollisions();
        }
예제 #6
0
        public static string ToMoveString(MoveCommand.Commands value)
        {
            switch (value)
            {
            case MoveCommand.Commands.Forward:
                return(Properties.Resources.MoveCommandForward);

            case MoveCommand.Commands.Backward:
                return(Properties.Resources.MoveCommandBackward);

            case MoveCommand.Commands.Rotate45CW:
                return(Properties.Resources.MoveCommandRotate45CW);

            case MoveCommand.Commands.Rotate45CCW:
                return(Properties.Resources.MoveCommandRotate45CCW);

            case MoveCommand.Commands.Rotate90CW:
                return(Properties.Resources.MoveCommandRotate90CW);

            case MoveCommand.Commands.Rotate90CCW:
                return(Properties.Resources.MoveCommandRotate90CCW);

            case MoveCommand.Commands.Forward45CW:
                return(Properties.Resources.MoveCommandForwardRotate45CW);

            case MoveCommand.Commands.Forward45CCW:
                return(Properties.Resources.MoveCommandForwardRotate45CCW);

            case MoveCommand.Commands.Backward45CW:
                return(Properties.Resources.MoveCommandBackwardRotate45CW);

            case MoveCommand.Commands.Backward45CCW:
                return(Properties.Resources.MoveCommandBackwardRotate45CCW);

            case MoveCommand.Commands.None:
                return(Properties.Resources.MoveCommandNone);
            }

            throw new Exception($"Строкового представления {value} в перечислении MoveCommand.Commands не существует.");
        }