Esempio n. 1
0
        private static void MakeTurn(Player player1, Player player2, Deck deck)
        {
            //give card
            var card = MovementUtil.MakeTurn(player1, player2, deck, null);

            //Check for additional point -> (20 or 40)
            //TODO Idea for modification: Player choose if he wants to call his announce. If has more than one announce can choose which one wants to play.
            if (SixtySixUtil.HasForty(player1.Cards, card, deck))
            {
                SixtySixUtil.CallForty(player1);
                player1.HasTwentyForty.Add(new Card()
                {
                    Suit = card.Suit, Value = card.Value == CardValue.QUEEN ? CardValue.KING : CardValue.QUEEN
                });
            }
            else if (SixtySixUtil.HasTwenty(player1.Cards, card, deck))
            {
                SixtySixUtil.CallTwenty(player1);
                player1.HasTwentyForty.Add(new Card()
                {
                    Suit = card.Suit, Value = card.Value == CardValue.QUEEN ? CardValue.KING : CardValue.QUEEN
                });
            }

            var otherCard = MovementUtil.MakeTurn(player2, player1, deck, card);
            var handScore = (int)card.Value + (int)otherCard.Value;

            deck.ThrownCards.Add(card);
            deck.ThrownCards.Add(otherCard);

            // player1 plays first, so if first card wins, then the first player wins
            if (SixtySixUtil.WinsFirstCard(card, otherCard, deck.TrumpSuit))
            {
                if (!(player1.IsSilent && player2.IsSilent))
                {
                    Console.WriteLine("Winning card {0}", card);
                }
                player1.Score         += handScore;
                player1.HasWonLastHand = true;
                player2.HasWonLastHand = false;
                SixtySixUtil.DrawCard(player1, deck);
                SixtySixUtil.DrawCard(player2, deck);
            }
            else
            {
                if (!(player1.IsSilent && player2.IsSilent))
                {
                    Console.WriteLine("Winning card {0}", otherCard);
                }
                player2.Score         += handScore;
                player2.HasWonLastHand = true;
                player1.HasWonLastHand = false;
                SixtySixUtil.DrawCard(player2, deck);
                SixtySixUtil.DrawCard(player1, deck);
            }
        }
Esempio n. 2
0
        /*
         * TODO
         *      Handle reaching 66 (Note: handle end of game by cannling)
         */
        private void HandleGiveCardCommand(object parameter)
        {
            //This check handle the case in which input player gives card before the AI player, when the AI player is on turn
            if (this.Opponent.HasWonLastHand && this.Opponent.SelectedCard == null)
            {
                return;
            }

            if (Deck.Cards.Count == 0)
            {
                this.TrumpCard = null;
            }

            this.Player.Messages   = null;
            this.Opponent.Messages = null;


            if (parameter != null)
            {
                var playerCard = (CardViewModel)parameter;

                if (this.Opponent.SelectedCard != null &&
                    SixtySixUtil.HasToAnswerWithMatching(this.Deck, this.Opponent.SelectedCard.ToCard()) &&
                    SixtySixUtil.HasAnsweringCard(this.Player.ToPlayer(), this.Opponent.SelectedCard.ToCard()))
                {
                    var playedFromOther = this.Opponent.SelectedCard.ToCard();
                    var answeringCards  = SixtySixUtil.GetHandAnsweringCards(this.Player.ToPlayer(), playedFromOther);
                    if (!answeringCards.Contains(playerCard.ToCard()))
                    {
                        this.BoardMessage = "Player, you have to answer with matching card!!!";
                        return;
                    }
                }

                this.Player.SelectedCard = (CardViewModel)parameter;
                if (this.Opponent.SelectedCard == null)
                {
                    HandleCallingAnnounce(this.Player, this.Deck);
                    if (HandleEndOfDeal(this.Player, this.Opponent, this.Deck))
                    {
                        return;
                    }
                }
            }

            bool winsFirstCard;

            if (this.Opponent.SelectedCard == null)
            {
                var opponentCard = CardViewModel.ConvertToCardViewModel(AIMovementUtil.MakeTurn(this.Opponent.ToPlayer(), this.Player.ToPlayer(), this.Deck, this.Player.SelectedCard.ToCard()));
                this.Opponent.SelectedCard = opponentCard;
                winsFirstCard = SixtySixUtil.WinsFirstCard(this.Player.SelectedCard.ToCard(), this.Opponent.SelectedCard.ToCard(), this.Deck.TrumpSuit);
            }
            else
            {
                winsFirstCard = !SixtySixUtil.WinsFirstCard(this.Opponent.SelectedCard.ToCard(), this.Player.SelectedCard.ToCard(), this.Deck.TrumpSuit);
            }

            var handScore = (int)this.Player.SelectedCard.Value + (int)this.Opponent.SelectedCard.Value;



            if (winsFirstCard)
            {
                this.Player.HasWonLastHand   = true;
                this.Opponent.HasWonLastHand = false;


                this.BoardMessage = "Player wins";
                //the player holds the hand
                this.Player.Score = this.Player.Score + handScore;

                var newPlayerCard = SixtySixUtil.DrawCard(this.Player.ToPlayer(), this.Deck);
                if (newPlayerCard != null)
                {
                    this.Player.Cards.Add(CardViewModel.ConvertToCardViewModel(newPlayerCard));
                    var newOpponentCard = SixtySixUtil.DrawCard(this.Opponent.ToPlayer(), this.Deck);
                    if (newOpponentCard != null)
                    {
                        this.Opponent.Cards.Add(CardViewModel.ConvertToCardViewModel(newOpponentCard));
                    }
                }

                Task.Delay(1000).ContinueWith(_ =>
                {
                    if (HandleEndOfDeal(this.Player, this.Opponent, this.Deck))
                    {
                        this.Player.SelectedCard   = null;
                        this.Opponent.SelectedCard = null;
                        return;
                    }
                    this.Player.SelectedCard   = null;
                    this.Opponent.SelectedCard = null;
                });
            }
            else
            {
                //the opponent hold the hand
                this.Opponent.HasWonLastHand = true;
                this.Player.HasWonLastHand   = false;

                this.BoardMessage   = "Opponent wins";
                this.Opponent.Score = this.Opponent.Score + handScore;

                var newOpponentCard = SixtySixUtil.DrawCard(this.Opponent.ToPlayer(), this.Deck);
                if (newOpponentCard != null)
                {
                    this.Opponent.Cards.Add(CardViewModel.ConvertToCardViewModel(newOpponentCard));
                    var newPlayerCard = SixtySixUtil.DrawCard(this.Player.ToPlayer(), this.Deck);
                    if (newPlayerCard != null)
                    {
                        this.Player.Cards.Add(CardViewModel.ConvertToCardViewModel(newPlayerCard));
                    }
                }

                CardViewModel opponentCard = null;

                if (HandleEndOfDeal(this.Opponent, this.Player, this.Deck))
                {
                    return;
                }

                Task.Delay(1000).ContinueWith(_ =>
                {
                    this.Player.SelectedCard   = null;
                    this.Opponent.SelectedCard = null;
                });

                if (this.Player.SelectedCard == null)
                {
                    ChangeTrumpCardLogic(this.Opponent);
                }

                opponentCard = CardViewModel.ConvertToCardViewModel(AIMovementUtil.MakeTurn(this.Opponent.ToPlayer(), this.Player.ToPlayer(), this.Deck));
                this.Opponent.Cards.Remove(opponentCard);


                Task.Delay(1500).ContinueWith(_ =>
                {
                    if (Deck.Cards.Count == 0)
                    {
                        this.TrumpCard = null;
                    }

                    this.Opponent.SelectedCard = opponentCard;
                    if (this.Player.SelectedCard == null)
                    {
                        HandleCallingAnnounce(this.Opponent, this.Deck);
                        HandleEndOfDeal(this.Opponent, this.Player, this.Deck);
                    }
                });
            }
        }