示例#1
0
        /// <summary>
        /// Active player's continuously turn actions.
        /// </summary>
        /// <returns>Info about "Will the active player continue to play?"</returns>
        private bool ContinuouslyPlayerTurnActions()
        {
            if (!CheckPlayability())
            {
                (_activePlayer, _opponentPlayer) = _operations.SwitchActiveAndOpponentPlayers(_activePlayer, _opponentPlayer);

                return(false);
            }

            if (!AttackCardSelection(out ICard selectedAttackCard))
            {
                (_activePlayer, _opponentPlayer) = _operations.SwitchActiveAndOpponentPlayers(_activePlayer, _opponentPlayer);

                return(false);
            }

            _isGameContinuous = _operations.AttackTheOpponent(selectedAttackCard, _activePlayer, _opponentPlayer);

            _operations.RemoveUsedCardFromHand(_activePlayer.Hand, selectedAttackCard);

            if (_isGameContinuous)
            {
                return(true);
            }

            _io.YouWinMessage(_activePlayer, _opponentPlayer);

            return(false);
        }
        public void AttackTheOpponentTests()
        {
            var activePlayerMock   = new Mock <IPlayer>();
            var opponentPlayerMock = new Mock <IPlayer>();

            activePlayerMock.SetupProperty(player => player.Mana, (byte)8);
            opponentPlayerMock.SetupProperty(player => player.Health, (byte)6);

            var selectedCard = new Card {
                ManaCost = 7
            };

            bool isGameContinues = _operations.AttackTheOpponent(selectedCard, activePlayerMock.Object, opponentPlayerMock.Object);

            Assert.AreEqual(false, isGameContinues);
            Assert.AreEqual(0, opponentPlayerMock.Object.Health);
            Assert.AreEqual(1, activePlayerMock.Object.Mana);

            activePlayerMock.Object.Mana     = 4;
            opponentPlayerMock.Object.Health = 19;
            selectedCard.ManaCost            = 3;

            isGameContinues = _operations.AttackTheOpponent(selectedCard, activePlayerMock.Object, opponentPlayerMock.Object);

            Assert.AreEqual(true, isGameContinues);
            Assert.AreEqual(1, activePlayerMock.Object.Mana);
            Assert.AreEqual(16, opponentPlayerMock.Object.Health);

            activePlayerMock.Object.Mana = 1;

            try
            {
                isGameContinues = _operations.AttackTheOpponent(selectedCard, activePlayerMock.Object, opponentPlayerMock.Object);
            }
            catch (ArgumentOutOfRangeException)
            {
                Assert.AreEqual(1, activePlayerMock.Object.Mana);
                Assert.AreEqual(16, opponentPlayerMock.Object.Health);
                Assert.AreEqual(true, isGameContinues);
            }
        }