Exemple #1
0
        private void HandleAlliedAttackingEnemy(GameTime gameTime)
        {
            if (_alliedUnitAttacking != null && _enemyUnitUnderAttack != null)
            {
                if (_alliedAttackFlash < 3)
                {
                    switch (_alliedAttackFlash)
                    {
                    case 0:
                        // turn allied unit red
                        _alliedAttackFlash++;
                        _timeSinceLastFlash = 0;
                        break;

                    case 1:
                        _timeSinceLastFlash += (float)gameTime.ElapsedGameTime.TotalSeconds;
                        if (_timeSinceLastFlash > 0.2f)
                        {
                            // turn enemy unit red
                            _alliedAttackFlash++;
                            _timeSinceLastFlash = 0;
                        }
                        break;

                    case 2:
                        _timeSinceLastFlash += (float)gameTime.ElapsedGameTime.TotalSeconds;
                        if (_timeSinceLastFlash > 0.2f)
                        {
                            _alliedAttackFlash++;
                        }
                        break;
                    }
                }
                else
                {
                    // compute attack
                    //_log.Debug($"HandleUnitMovement() allied ({_alliedUnitAttacking.UnitNumber}) attacking enemy:{_enemyUnitUnderAttack.UnitNumber}");

                    _alliedUnitAttacking.UnitHasAttackedThisTurn = true;
                    _units.ComputeAttack(_alliedUnitAttacking, _enemyUnitUnderAttack);

                    _alliedUnitAttacking  = null;
                    _enemyUnitUnderAttack = null;
                    _alliedAttackFlash    = 0;
                    _timeSinceLastFlash   = 0;
                    _units.UnselectUnits();
                }
            }
        }
        private bool HandleEnemyAttackingAllied(bool visible)
        {
            //_log.Debug("HandleEnemyAttackingAllied()");
            if (EnemyUnitAttacking != null && AlliedUnitUnderAttack != null)
            {
                // wake allied unit if being attacked
                AlliedUnitUnderAttack.Sleep = false;

                if (EnemyUnitAttacking.Flash == null)
                {
                    _log.Debug("HandleEnemyAttackingAllied() set enemy unit attack flash");
                    EnemyUnitAttacking.Flash    = new UnitFlash(2, 0.2f, new Color(200, 100, 100));
                    AlliedUnitUnderAttack.Flash = null;
                }

                if (EnemyUnitAttacking.Flash.Complete && AlliedUnitUnderAttack.Flash == null)
                {
                    _log.Debug("HandleEnemyAttackingAllied() set allied unit under attack flash");
                    AlliedUnitUnderAttack.Flash = new UnitFlash(2, 0.2f, new Color(200, 100, 100));
                }

                if (AlliedUnitUnderAttack.Flash != null && (EnemyUnitAttacking.Flash.Complete && AlliedUnitUnderAttack.Flash.Complete))
                {
                    //_log.Debug("HandleEnemyAttackingAllied() compute attack");
                    // compute attack
                    _totalUnitsMovedOrAttacked++;
                    EnemyUnitAttacking.UnitHasAttackedThisTurn = true;
                    EnemyUnitAttacking.SkipTurn = true;
                    _units.ComputeAttack(EnemyUnitAttacking, AlliedUnitUnderAttack);
                    EnemyUnitAttacking.Flash    = null;
                    AlliedUnitUnderAttack.Flash = null;

                    EnemyUnitAttacking    = null;
                    AlliedUnitUnderAttack = null;
                    _units.UnselectUnits();

                    return(true);
                }
            }
            else
            {
                // nobody left to attack
            }

            return(false);
        }