예제 #1
0
        public async void PlayCard(Card card)
        {
            PlayingEnabled = false;
            if (FieldCards[0].Number == 0 && FieldCards[1].Number == 0)
            {
                if (IsPlayerTurn)
                {
                    FieldCards[0] = card;
                    _player.PlayCard(card);
                    OnFieldCardsChanged(this);
                    IsPlayerTurn = !IsPlayerTurn;
                    PlayCard(_computer.ComputerDoMove(card, _troef));
                }
                else
                {
                    _computer.PlayCard(card);
                    FieldCards[1] = card;
                    IsPlayerTurn  = !IsPlayerTurn;
                    OnFieldCardsChanged(this);
                    PlayingEnabled = true;
                }
            }
            else
            {
                bool allowed = false;
                allowed = FieldCards[0].Number == 0 ? _player.PlayCard(card, FieldCards[1], _troef) : _computer.PlayCard(card, FieldCards[0], _troef);
                if (!allowed)
                {
                    OnWrongCardPlayed(this);
                    PlayingEnabled = true;
                    return;
                }
                if (FieldCards[0].Number == 0)
                {
                    FieldCards[0] = card;
                }
                else
                {
                    FieldCards[1] = card;
                }

                OnFieldCardsChanged(this);
                if (FieldCards.DidPlayerWinTurn(_troef, IsPlayerTurn))
                {
                    _player.AddPlayerScoredCards(FieldCards[0]);
                    _player.AddPlayerScoredCards(FieldCards[1]);
                    IsPlayerTurn = true;
                    OnTurnIsOver(this, new TurnIsOverEventArgs()
                    {
                        DidPlayerWin = true
                    });
                }
                else
                {
                    _computer.AddPlayerScoredCards(FieldCards[0]);
                    _computer.AddPlayerScoredCards(FieldCards[1]);
                    IsPlayerTurn = false;
                    OnTurnIsOver(this, new TurnIsOverEventArgs()
                    {
                        DidPlayerWin = false
                    });
                }
                await Task.Delay(2000);

                FieldCards.EmptyCards();
                OnFieldCardsChanged(this);
                PlayingEnabled = true;

                if (_player.IsOutOfCards())
                {
                    OnRoundIsOver();
                    return;
                }
                if (!IsPlayerTurn)
                {
                    PlayCard(_computer.ComputerDoMove());
                }
            }
        }