Exemplo n.º 1
0
        public Card ComputerDoMove(Card fieldCard, Suit troef)
        {
            List<Card> lstAllowedCards = GetAllowedCards(fieldCard, troef);
            Random random = new Random();
            return lstAllowedCards[random.Next(0, lstAllowedCards.Count - 1)];

        }
Exemplo n.º 2
0
        public void PlayCard(Card card)
        {
            if (PlayerCards.Contains(card))
                PlayerCards.Remove(card);
            if (PlayerUpField.Contains(card))
            {
                int place = PlayerUpField.IndexOf(card);
                if (PlayerDownField[place] != null)
                {
                    PlayerUpField[place] = PlayerDownField[place];
                    PlayerDownField[place] = null;
                }
                else
                    PlayerUpField[place] = null;
            }

        }
Exemplo n.º 3
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());
            }
        }
Exemplo n.º 4
0
 private void PlayCard(Card card)
 {
     gameEngine.PlayCard(card);
 }
Exemplo n.º 5
0
 public void AddPlayerScoredCards(Card card)
 {
     PlayerScoredCards.Add(card);
 }
Exemplo n.º 6
0
 public void AddPlayerDownFieldCard(Card card)
 {
     PlayerDownField.Add(card);
     OnDealedNewCard();
 }
Exemplo n.º 7
0
 public void AddPlayerCard(Card card)
 {
     PlayerCards.Add(card);
     OnDealedNewCard();
 }
Exemplo n.º 8
0
 protected List<Card> GetAllowedCards(Card fieldCard, Suit troef)
 {
     List<Card> lstAllowedCards = new List<Card>();
     lstAllowedCards.AddRange(
         PlayerCards.Where(card => card.Number > fieldCard.Number && fieldCard.Suit == card.Suit));
     lstAllowedCards.AddRange(
         PlayerUpField.Where(
             card => card != null && card.Number > fieldCard.Number && fieldCard.Suit == card.Suit));
     if (lstAllowedCards.Count > 0)
         return lstAllowedCards;
     lstAllowedCards.AddRange(PlayerCards.Where(card => fieldCard.Suit == card.Suit));
     lstAllowedCards.AddRange(PlayerUpField.Where(card => card != null && fieldCard.Suit == card.Suit));
     if (lstAllowedCards.Count > 0)
         return lstAllowedCards;
     lstAllowedCards.AddRange(PlayerCards.Where(card => troef == card.Suit));
     lstAllowedCards.AddRange(PlayerUpField.Where(card => card != null && troef == card.Suit));
     if (lstAllowedCards.Count > 0)
         return lstAllowedCards;
     lstAllowedCards.AddRange(PlayerCards);
     lstAllowedCards.AddRange(PlayerUpField.Where(card => card != null));
     return lstAllowedCards;
 }
Exemplo n.º 9
0
 public bool PlayCard(Card card, Card fieldcard, Suit troef)
 {
     if (GetAllowedCards(fieldcard, troef).Contains(card))
     {
         if (PlayerCards.Contains(card))
             PlayerCards.Remove(card);
         if (PlayerUpField.Contains(card))
         {
             int place = PlayerUpField.IndexOf(card);
             if (PlayerDownField[place] != null)
             {
                 PlayerUpField[place] = PlayerDownField[place];
                 PlayerDownField[place] = null;
             }
             else
                 PlayerUpField[place] = null;
         }
         return true;
     }
     return false;
 }