Esempio n. 1
0
        private void ProcessNextTurn()
        {
            _turnNumber++;
            BattleView.UpdateNextStepButton("Next Turn", false);
            BattleView.ClearBattleLog();
            _grid.ClearReservations();
            _casualtyMap.Clear();
            Log(false, "Turn " + _turnNumber.ToString());
            // this is a three step process: plan, execute, and apply

            ConcurrentBag <IAction>  moveSegmentActions  = new ConcurrentBag <IAction>();
            ConcurrentBag <IAction>  shootSegmentActions = new ConcurrentBag <IAction>();
            ConcurrentBag <IAction>  meleeSegmentActions = new ConcurrentBag <IAction>();
            ConcurrentQueue <string> log = new ConcurrentQueue <string>();

            Plan(shootSegmentActions, moveSegmentActions, meleeSegmentActions, log);
            while (!log.IsEmpty)
            {
                log.TryDequeue(out string line);
                Log(false, line);
            }

            HandleShootingAndMoving(shootSegmentActions, moveSegmentActions);
            while (!log.IsEmpty)
            {
                log.TryDequeue(out string line);
                Log(false, line);
            }

            HandleMelee(meleeSegmentActions);
            while (!log.IsEmpty)
            {
                log.TryDequeue(out string line);
                Log(false, line);
            }

            ProcessWounds();
            CleanupAtEndOfTurn();

            if (_selectedBattleSquad?.IsPlayerSquad == true)
            {
                BattleView.OverwritePlayerWoundTrack(GetSquadDetails(_selectedBattleSquad));
            }
            else if (_selectedBattleSquad != null)
            {
                BattleView.OverwritePlayerWoundTrack(GetSquadSummary(_selectedBattleSquad));
            }

            if (_playerBattleSquads.Count() == 0 || _opposingBattleSquads.Count() == 0)
            {
                Log(false, "One side destroyed, battle over");
                BattleView.UpdateNextStepButton("End Battle", true);
            }
            else
            {
                BattleView.UpdateNextStepButton("Next Turn", true);
            }
        }