Exemplo n.º 1
0
        /// <summary>
        /// Deploys units to the region.
        /// </summary>
        /// <param name="region"></param>
        /// <param name="bonusArmy">Bonus army to the region.</param>
        public void Deploy(Region region, int bonusArmy)
        {
            if (region == null)
            {
                throw new ArgumentException($"Region cannot be null.");
            }
            if (region.Owner == null)
            {
                throw new ArgumentException($"Region {region.Name} owner cannot be null.");
            }
            if (region.Owner != PlayerOnTurn)
            {
                throw new ArgumentException("You cannot deploy to regions you do not own.");
            }

            var lastTurn = (GameTurn)LastTurn;

            int newArmy = lastTurn.GetRegionArmy(region) + bonusArmy;

            if (bonusArmy > 0 && bonusArmy > PlayerOnTurn.GetArmyLeftToDeploy(lastTurn.Deploying))
            {
                // bonus army > 0 and is more than i can deploy
                throw new ArgumentException($"Cannot deploy. Your limit {PlayerOnTurn.GetIncome()} for deployed units would be exceeded.");
            }
            else if (bonusArmy < 0 && region.Army > newArmy)
            {
                throw new ArgumentException("You cannot deploy less than region had at this round beginning.");
            }
            // if there exists deployment entry => remove that entry and create new one
            lastTurn.Deploying.AddDeployment(region, newArmy);

            ImageProcessor.Deploy(region, newArmy);
        }