Esempio n. 1
0
        /// <summary>
        /// 打出卡牌
        ///   從手牌中打出 1張卡牌,正面朝上置於桌面場內。
        ///   從牌堆抽取最上方一張牌,正面朝外,置於手牌上。
        ///   打出的卡牌必須符合下列原則:
        ///     牌上數字須為桌面場內同色牌未出現,且須接續在已出現同色牌數字後。
        ///   若打出的卡牌不符合以上原則,即算施放失敗。
        ///     取 1個紅色錯誤指示物,施放失敗的花火卡則正面朝上置於棄牌區
        ///   若玩家完成一組顏色花火卡牌施放(即數字1~5依照順序排列的「同花順」)
        ///     得到 1個藍色傳達指示物做為獎勵。
        ///     若已無藍色傳達指示物,則無此獎勵行動。
        /// </summary>
        /// <param name="cardIndex">打出的牌</param>
        /// <param name="player">出牌玩家</param>
        /// <param name="board">遊戲資訊</param>
        /// <param name="drawedCard">出牌後的補牌</param>
        /// <returns>出牌的結果</returns>
        public PlayCardResult PlayCard(CardIndexType cardIndex, IHanabiPlayer player, GameBoard board, out Card drawedCard)
        {
            Card playedCard = player.GetCard(cardIndex);

            if (playedCard == null)
            {
                drawedCard = null;
                return(PlayCardResult.InvalidCardIndex);
            }
            player.PlayCard(cardIndex);

            drawedCard = board.Draw();
            if (drawedCard != null)
            {
                player.DrawCard(drawedCard);
            }

            if (board.Play(playedCard))
            {
                if (playedCard.Value == CardValueType.Value5)
                {
                    board.Reward();
                }
                return(PlayCardResult.Success);
            }
            else
            {
                board.Punish();
                board.Discard(playedCard);
                return(PlayCardResult.FailNoSlot);
            }
        }
Esempio n. 2
0
        public void TestGameRule_PlayCardSuccessDrawCard()
        {
            var           player   = new Mock <IHanabiPlayer>();
            CardIdType    id       = new CardIdType(0);
            CardIndexType index    = new CardIndexType(0);
            Card          card     = new Card(id, index, CardColorType.Blue, CardValueType.Value1);
            HandCard      handCard = new HandCard(card);

            player.Setup(x => x.GetHandCard(index)).Returns(handCard);
            player.Setup(x => x.PlayCard(index));

            var           board    = new Mock <IGameBoard>();
            CardIdType    newId    = new CardIdType(1);
            CardIndexType newIndex = new CardIndexType(1);
            Card          newCard  = new Card(newId, newIndex, CardColorType.Blue, CardValueType.Value1);

            board.Setup(x => x.Draw()).Returns(newCard);
            board.Setup(x => x.Play(card)).Returns(true);

            GameRule rule = new GameRule();

            Debug.Assert(rule.PlayCard(index, player.Object, board.Object) == PlayCardResult.Success);

            player.VerifyAll();
            board.VerifyAll();
        }
Esempio n. 3
0
        /// <summary>
        /// 建立抽牌堆
        /// </summary>
        /// <param name="settings">遊戲設定</param>
        public DrawPile(GameSettings settings)
        {
            // NOTE: 各色牌都有 3張1 2張2,3,4 1張5
            CardValueType[] values =
            {
                CardValueType.Value1, CardValueType.Value1, CardValueType.Value1,
                CardValueType.Value2, CardValueType.Value2,
                CardValueType.Value3, CardValueType.Value3,
                CardValueType.Value4, CardValueType.Value4,
                CardValueType.Value5
            };

            int cardNumber = ( int )settings.ColorCount * values.Length;

            CardIndexType[] indeies = new CardIndexType[cardNumber];
            for (int count = 0; count < cardNumber; ++count)
            {
                indeies[count] = new CardIndexType(count);
            }
            GameBoard.RandomSort(indeies);

            Card[] tempCards = new Card[cardNumber];
            for (int count = 0; count < cardNumber; ++count)
            {
                CardColorType color  = ( CardColorType )(((count / 10) + 1) * 10);
                CardValueType number = values[count % 10];
                tempCards[count] = new Card(new CardIdType(count), indeies[count], color, number);
            }
            GameBoard.RandomSort(tempCards);

            Pile = new Queue <Card>(tempCards);
        }
Esempio n. 4
0
        public void TestGameRule_PlayCardFailedNoSlot()
        {
            var           player   = new Mock <IHanabiPlayer>();
            CardIdType    id       = new CardIdType(0);
            CardIndexType index    = new CardIndexType(0);
            Card          card     = new Card(id, index, CardColorType.Blue, CardValueType.Value1);
            HandCard      handCard = new HandCard(card);

            player.Setup(x => x.GetHandCard(index)).Returns(handCard);
            player.Setup(x => x.PlayCard(index));

            var board = new Mock <IGameBoard>();

            board.Setup(x => x.Draw()).Returns <Card>(null);
            board.Setup(x => x.Play(card)).Returns(false);
            board.Setup(x => x.Discard(card));
            board.Setup(x => x.Punish());

            GameRule rule = new GameRule();

            Debug.Assert(rule.PlayCard(index, player.Object, board.Object) == PlayCardResult.FailNoSlot);

            player.VerifyAll();
            board.VerifyAll();
        }
Esempio n. 5
0
        private void RemoveCard(CardIndexType index)
        {
            Card card = GetCard(index);

            if (card == null)
            {
                return;
            }
            Cards.Remove(card);
        }
Esempio n. 6
0
 public Card GetCard(CardIndexType index)
 {
     foreach (var card in Cards)
     {
         if (card.Index == index)
         {
             return(card);
         }
     }
     return(null);
 }
Esempio n. 7
0
        public void TestGameRule_PlayCardFailedInvalidIndex()
        {
            var           player = new Mock <IHanabiPlayer>();
            CardIndexType index  = new CardIndexType(0);

            player.Setup(x => x.GetHandCard(index)).Returns <HandCard>(null);

            var board = new Mock <IGameBoard>();

            GameRule rule = new GameRule();

            Debug.Assert(rule.PlayCard(index, player.Object, board.Object) == PlayCardResult.InvalidCardIndex);

            player.VerifyAll();
            board.VerifyAll();
        }
Esempio n. 8
0
        /// <summary>
        /// 丟棄手牌
        ///   從手牌中丟棄一張牌,正面朝上置於棄牌區。
        ///   從牌堆抽取最上方一張牌,正面朝外,置於手牌上。
        ///   得到 1個藍色傳達指示物,若已無已消耗藍色傳達指示物,則不可執行此行動。
        /// </summary>
        /// <param name="cardIndex">丟棄的牌</param>
        /// <param name="player">丟牌玩家</param>
        /// <param name="board">遊戲資訊</param>
        /// <param name="drawedCard">出牌後的補牌</param>
        /// <returns>棄牌結果</returns>
        public DiscardCardResult DiscardCard(CardIndexType cardIndex, IHanabiPlayer player, GameBoard board, out Card drawedCard)
        {
            Card discardedCard = player.GetCard(cardIndex);

            if (discardedCard == null)
            {
                drawedCard = null;
                return(DiscardCardResult.InvalidCardIndex);
            }
            player.DiscardCard(cardIndex);

            drawedCard = board.Draw();
            if (drawedCard != null)
            {
                player.DrawCard(drawedCard);
            }

            board.Discard(discardedCard);
            board.Reward();

            return(DiscardCardResult.Success);
        }
Esempio n. 9
0
        public void DiscardCard(CardIndexType index)
        {
            RemoveCard(index);

            CheckIsLastTurn();
        }