예제 #1
0
        public GameEngineControl(TankEngine tank, EnemyTankEngine enemyTank, BulletEngine bullet,
                                 ControlBase controlBase,
                                 MapBase map, MoveDirection direction, MoveDirection enemyDirection)
        {
            PlayerWin           = false;
            GameOver            = false;
            _tank               = tank;
            _enemyTank          = enemyTank;
            _bullet             = bullet;
            _controlBase        = controlBase;
            _map                = map;
            _lastDirection      = direction;
            _direction          = direction;
            _lastEnemyDirection = enemyDirection;
            _enemyDirection     = enemyDirection;

            _bulletsTimer          = new Timer(10000);
            _bulletsTimer.Elapsed += BulletsTimerOnElapsed;
            _bulletsTimer.Interval = _bullesSpeed;

            _tanksTimer          = new Timer(10000);
            _tanksTimer.Elapsed += TanksTimerOnElapsed;
            _tanksTimer.Interval = _tanksSpeed;
            switch (direction)
            {
            case MoveDirection.Up:
                _action = ControlActions.MoveUp;
                break;

            case MoveDirection.Down:
                _action = ControlActions.MoveDown;
                break;

            case MoveDirection.Right:
                _action = ControlActions.MoveRight;
                break;

            case MoveDirection.Left:
                _action = ControlActions.MoveLeft;
                break;
            }
            switch (enemyDirection)
            {
            case MoveDirection.Up:
                _enemyAction = ControlActions.MoveUp;
                break;

            case MoveDirection.Down:
                _enemyAction = ControlActions.MoveDown;
                break;

            case MoveDirection.Right:
                _enemyAction = ControlActions.MoveRight;
                break;

            case MoveDirection.Left:
                _enemyAction = ControlActions.MoveLeft;
                break;
            }
        }
        public MoveDirection Control(out ControlActions enemyAction, List <TankFragment> enemyTank,
                                     List <TankFragment> myTank, EnemyTankEngine tank, ControlActions enemyTankLastAction,
                                     MoveDirection direction, BulletEngine bullet, MapBase map)
        {
            ControlActions nextEnemyAction;
            MoveDirection  nextEnemyDirection = 0;

            EnemyTankChoseActions(out nextEnemyAction, enemyTank, myTank, enemyTankLastAction);
            if (nextEnemyAction == ControlActions.Shoot)
            {
                tank.Shoot(enemyTank[1].X, enemyTank[1].Y, direction);
                enemyAction = enemyTankLastAction;
            }
            else
            {
                enemyAction = nextEnemyAction;
            }
            switch (enemyAction)
            {
            case ControlActions.MoveUp:
                nextEnemyDirection = MoveDirection.Up;
                break;                                                                      //дивитись коментар до GameEngineControl

            case ControlActions.MoveDown:
                nextEnemyDirection = MoveDirection.Down;
                break;

            case ControlActions.MoveLeft:
                nextEnemyDirection = MoveDirection.Left;
                break;

            case ControlActions.MoveRight:
                nextEnemyDirection = MoveDirection.Right;
                break;
            }
            return(nextEnemyDirection);
        }
        public GameEngineControl(TankEngine tank, EnemyTankEngine enemyTank, BulletEngine bullet,
                                 ControlBase controlBase,
                                 MapBase map, MoveDirection direction, MoveDirection enemyDirection)
        {
            PlayerWin           = false;
            GameOver            = false;
            _tank               = tank;
            _enemyTank          = enemyTank;
            _bullet             = bullet;
            _controlBase        = controlBase;
            _map                = map;
            _lastDirection      = direction;
            _direction          = direction;
            _lastEnemyDirection = enemyDirection;
            _enemyDirection     = enemyDirection;

            _bulletsTimer          = new Timer(10000);
            _bulletsTimer.Elapsed += BulletsTimerOnElapsed;
            _bulletsTimer.Interval = _bullesSpeed;

            _tanksTimer          = new Timer(10000);
            _tanksTimer.Elapsed += TanksTimerOnElapsed;
            _tanksTimer.Interval = _tanksSpeed;


            //тут двічі, і ще в методі Control класу EnemyTankEngine, де ми отримуємо ControlAction є код, який повторюється
            // public static ControlAction GetControlAction(MoveDirection direction)
            //     switch    (direction)
            //         {
            //               case MoveDirection.Up:
            //                 return ControlActions.MoveUp;
            //                 break;
            //            case MoveDirection.Down:
            //                 return = ControlActions.MoveDown;
            //                 break;
            //            case MoveDirection.Right:
            //                 return = ControlActions.MoveRight;
            //                 break;
            //            case MoveDirection.Left:
            //                 return = ControlActions.MoveLeft;
            //                 break;
            //        }
            //        return ControlActions.MoveUp;
            //_action = GetControlAction(direction)



            //_enemyAction = GetControlAction(enemyDirection)


            switch (direction)
            {
            case MoveDirection.Up:
                _action = ControlActions.MoveUp;
                break;

            case MoveDirection.Down:
                _action = ControlActions.MoveDown;
                break;

            case MoveDirection.Right:
                _action = ControlActions.MoveRight;
                break;

            case MoveDirection.Left:
                _action = ControlActions.MoveLeft;
                break;
            }
            switch (enemyDirection)
            {
            case MoveDirection.Up:
                _enemyAction = ControlActions.MoveUp;
                break;

            case MoveDirection.Down:
                _enemyAction = ControlActions.MoveDown;
                break;

            case MoveDirection.Right:
                _enemyAction = ControlActions.MoveRight;
                break;

            case MoveDirection.Left:
                _enemyAction = ControlActions.MoveLeft;
                break;
            }
        }