示例#1
0
        internal override Card PlayerPickWarAttack(WarPlayer player, int attackIndex)
        {
            //
            // Pre conditions

            if (!battleTracker.PlayerAttacks.Keys.Contains(player))
            {
                throw new InvalidOperationException("Cannot go to war without having attacked first.");
            }
            if (!battleTracker.ActiveWars.ContainsKey(player) || battleTracker.ActiveWars[player].Count == 0)
            {
                throw new InvalidOperationException(String.Format("{0} has not declared war.", player.Name));
            }
            if (battleTracker.ActiveAttacks.ContainsKey(player))
            {
                throw new InvalidOperationException(String.Format("{0} already has an active attack.", player.Name));
            }

            RequireGameState(WarGameState.AtWar);

            //
            // Validate attack index

            const int maxIndex = NumberOfCardsToDealForWar - 1;

            if ((attackIndex == -1) && (player.Cards.Count == 0))
            //
            // Player is out of cards, default to last attack.
            {
                var lastAttachIndex = battleTracker.PlayerAttacks[player].Count - 1;
                var defactoResult   = battleTracker.PlayerAttacks[player][lastAttachIndex];
                battleTracker.ActiveAttacks[player] = defactoResult;
                return(defactoResult);
            }
            else if (attackIndex > maxIndex || attackIndex < 0)
            {
                throw new ArgumentOutOfRangeException("attackIndex",
                                                      String.Format("Index must be from 0 to {0} (was {1})", maxIndex, attackIndex));
            }

            //
            // Activate the selected attack

            var wars     = battleTracker.ActiveWars[player];
            var warCards = wars[wars.Count - 1];
            var result   = warCards[attackIndex];

            battleTracker.ActiveAttacks[player] = result;

            Debug.WriteLine(String.Format("{0} went to war with the {1}", player.Name, result));

            return(result);
        }
示例#2
0
        internal override Card PlayerBattle(WarPlayer player)
        {
            Debug.Assert(battleTracker.PlayerAttacks.Keys.Contains(player), "Player is not part of game.");
            this.RequireGameState(WarGameState.AtBattle, WarGameState.NewGame);

            var result = player.Cards.DealTo(battleTracker.PlayerAttacks[player]);

            battleTracker.ActiveAttacks[player] = result;

            Debug.WriteLine(String.Format("{0} went to battle with the {1}", player.Name, result));

            return(result);
        }
示例#3
0
        /// <summary>
        /// Deals three cards (or players remaining cards, if fewer than three) for war.
        /// </summary>
        /// <param name="player">Specifies the player going to war.</param>
        /// <returns>The number of cards dealt for the war.</returns>
        internal override int PlayerDeclareWar(WarPlayer player)
        {
            //
            // Pre conditions

            if (!battleTracker.PlayerAttacks.Keys.Contains(player))
            {
                throw new InvalidOperationException("Cannot declare war without having attacked first.");
            }

            RequireGameState(WarGameState.WarDeclared);

            //
            // Deactivate active attack

            battleTracker.ActiveAttacks.Remove(player);
            if (!battleTracker.ActiveWars.ContainsKey(player))
            {
                battleTracker.ActiveWars[player] = new List <CardList>();
            }
            battleTracker.ActiveWars[player].Add(new CardList(NumberOfCardsToDealForWar));
            var warIndex = battleTracker.ActiveWars[player].Count - 1;

            //
            // Deal cards to "declare war"

            var result = 0;

            for (var i = 1; i <= NumberOfCardsToDealForWar && player.Cards.Count > 0; i++)
            {
                var card = player.Cards.DealTo(battleTracker.PlayerAttacks[player]);
                battleTracker.ActiveWars[player][warIndex].Add(card);
                result++;
            }

            Debug.Assert(result <= NumberOfCardsToDealForWar, "Did not deal enough war cards.");
            Debug.Assert(!battleTracker.ActiveAttacks.ContainsKey(player), "Player has invalid attack.");
            Debug.WriteLine(player.Name + " declared war!");

            return(result);
        }
示例#4
0
 internal abstract Card PlayerPickWarAttack(WarPlayer player, int attackIndex);
示例#5
0
 internal abstract int PlayerDeclareWar(WarPlayer player);
示例#6
0
 internal abstract Card PlayerBattle(WarPlayer player);