public void Update(GameTime gameTime) { _units.Update(gameTime); if (DumpGameData) { _units.DumpData(); DumpGameData = false; } // TODO: move this section to its own object/method if (_units.CurrentTurn == NATIONALITY.USA) { HandleNextActiveUnit(); HandleSleepingUnit(); // make selected unit flash on/off CheckIdleUnit(); HandleUnitMovement(gameTime); HandleAlliedAttackingEnemy(gameTime); if (_units.IsTurnComplete(NATIONALITY.USA) || NextTurn) { _units.ClearAllFlash(); _units.IdleUnit = null; _units.SetTurn(NATIONALITY.Germany); _enemyPlan.StartEnemyTurn(); } } _enemyPlan.HandleEnemy(gameTime, _noMaskView || ShowAll); NextUnit = false; SleepUnit = false; NextTurn = false; }
public void HandleEnemy(GameTime gameTime, bool visible) { if (_units.CurrentTurn == NATIONALITY.Germany) { //TODO: need to detect when units are blocked or all idle. if (NextEnemyUnitToMove == null) { NextEnemyUnitToMove = FindEnemyUnitToMove(); } if (NextEnemyUnitToMove != null) { switch (NextEnemyUnitToMove.EnemyUnitMode) { case 0: if (_units.IsUnitWithinAttackRange(NextEnemyUnitToMove, _alliedEnemyMatrix)) { NextEnemyUnitToMove.ClearPath(); NextEnemyUnitToMove.Movement = 0; NextEnemyUnitToMove.Flash = null; FindEnemyUnitToAttackFrom(); NextEnemyUnitToMove.EnemyUnitMode = 1; NextEnemyUnitToMove.Flash = new UnitFlash(2, 0.2f, new Color(200, 100, 100)); } else { NextEnemyUnitToMove.EnemyUnitMode = 3; } break; case 1: if (!IsUnitFlashing(visible)) { NextEnemyUnitToMove.EnemyUnitMode = 2; } break; case 2: if (HandleEnemyAttackingAllied(visible)) { NextEnemyUnitToMove.EnemyUnitMode = 5; } break; case 3: NextEnemyUnitToMove.Flash = new UnitFlash(2, 0.2f, new Color(100, 200, 100)); NextEnemyUnitToMove.EnemyUnitMode = 4; break; case 4: if (NextEnemyUnitToMove.Movement < 0.1) { if (_units.IsUnitWithinAttackRange(NextEnemyUnitToMove, _alliedEnemyMatrix)) { NextEnemyUnitToMove.ClearPath(); NextEnemyUnitToMove.Movement = 0; NextEnemyUnitToMove.Flash = null; FindEnemyUnitToAttackFrom(); NextEnemyUnitToMove.EnemyUnitMode = 1; NextEnemyUnitToMove.Flash = new UnitFlash(2, 0.2f, new Color(200, 100, 100)); return; } NextEnemyUnitToMove.EnemyUnitMode = 5; return; } if (!IsUnitFlashing(visible)) { HandleEnemyUnitMove(visible); } break; case 5: EnemyUnitQueue.Dequeue(); NextEnemyUnitToMove = null; break; } } // forallunits((Movement == 0 && UnitHasAttackedThisTurn) || Sleep || SkipTurn) if (_units.IsTurnComplete(NATIONALITY.Germany) || EnemyUnitQueue.Count == 0) { //_log.Debug("HandleEnemy() turn complete"); _units.SetTurn(NATIONALITY.USA); EnemyUnitAttacking = null; AlliedUnitUnderAttack = null; NextEnemyUnitToMove = null; } } }