Ejemplo n.º 1
0
        /// <summary>
        ///     Resets attacking phase recoloring everything back.
        ///     Notice: deploying phase passed in parameter must be corect in order
        ///     to make this method work properly.
        /// </summary>
        /// <param name="attackingPhase">Attacking phase</param>
        /// <param name="deployingPhase">Deploying phase</param>
        public void ResetAttackingPhase(Attacking attackingPhase, Deploying deployingPhase)
        {
            // TODO: check + should not clear
            var attacks = attackingPhase.Attacks;
            IEnumerable <IGrouping <Region, Attack> > attackerRegionsGroups = from attack in attacks
                                                                              group attack by attack.Attacker;
            var regionAttackingArmyPairEnumerable = from gr in attackerRegionsGroups
                                                    select new
            {
                Attacker      = gr.Key,
                AttackingArmy = gr.Sum(x => x.AttackingArmy)
            };

            foreach (var item in regionAttackingArmyPairEnumerable)
            {
                Region attacker = item.Attacker;

                IEnumerable <int> regionDeployedArmy = from tuple in deployingPhase.ArmiesDeployed
                                                       where tuple.Region == attacker
                                                       select tuple.Army;
                if (!regionDeployedArmy.Any())
                {
                    textDrawingHandler.OverDrawArmyNumber(attacker, attacker.Army);
                }
                else
                {
                    int army = regionDeployedArmy.First();
                    textDrawingHandler.OverDrawArmyNumber(attacker, army);
                }

                OnImageChanged?.Invoke();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reports how much army can player deploy based on what he has deployed already.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="deploying"></param>
        /// <returns></returns>
        public static int GetArmyLeftToDeploy(this Player player, Deploying deploying)
        {
            int deployedUnitsSum = (from deployment in deploying.ArmiesDeployed
                                    where deployment.Region.Owner == player
                                    select deployment.Army - deployment.Region.Army).Sum();

            return(player.GetIncome() - deployedUnitsSum);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Resets round, recoloring everything to previous color, writing
        ///     original numbers of armies.
        /// </summary>
        /// <param name="gameRound">Round to reset</param>
        internal void ResetRound(GameTurn gameRound)
        {
            Attacking attackingPhase = gameRound.Attacking;

            ResetAttackingPhase(attackingPhase, gameRound.Deploying);

            Deploying deployingPhase = gameRound.Deploying;

            ResetDeployingPhase(deployingPhase);
        }
Ejemplo n.º 4
0
        private void PlayDeploying(LinearizedGameRound round)
        {
            Deploying deploying = round.Deploying;

            foreach (var deployedArmies in deploying.ArmiesDeployed)
            {
                Region region = game.Map.Regions.First(x => x == deployedArmies.Region);
                region.Army = deployedArmies.Army;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Resets deploying phase, recoloring everything to the previous color,
        ///     redrawing everything to the original state.
        /// </summary>
        /// <param name="deployingPhase"></param>
        public void ResetDeployingPhase(Deploying deployingPhase)
        {
            foreach (var tuple in deployingPhase.ArmiesDeployed)
            {
                Region region = tuple.Region;
                if (region.Owner == null)
                {
                    throw new ArgumentException();
                }
                coloringHandler.Recolor(region, Color.FromKnownColor(region.Owner.Color));
                textDrawingHandler.DrawArmyNumber(region, region.Army);
            }

            OnImageChanged?.Invoke();
        }