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); } }
private static void HandleCallingAnnounce(PlayerViewModel player, Deck deck) { var card = player.SelectedCard; if (card != null) { if (SixtySixUtil.HasForty(player.ToPlayer().Cards, card.ToCard(), deck)) { player.Score += Constants.FORTY_ANNOUNCEMENT; player.Messages = "Forty!!!"; } else if (SixtySixUtil.HasTwenty(player.ToPlayer().Cards, card.ToCard(), deck)) { player.Score += Constants.TWENTY_ANNOUNCEMENT; player.Messages = "Twenty!!!"; } } }
public static Card MakeTurn(Player player, Deck deck, Card playedFromOther = null) { if (!player.IsSilent) { Console.WriteLine(); if (playedFromOther != null) { Console.WriteLine("Other player played: " + playedFromOther); } Console.WriteLine("Your Hand: " + player.ToStringPlayerCards()); } Card card = null; do { Console.WriteLine("Ender the choosen card in format <<<cardValue cardSuit>>>"); String input = Console.ReadLine(); var parts = input.Split(null); var value = ParseInputToCardValue(parts[0]); var suit = ParseInputToCardSuit(parts[1]); card = new Card() { Value = value, Suit = suit }; } while (card == null || card.Suit == 0); if (SixtySixUtil.HasForty(player.Cards, card, deck)) { SixtySixUtil.CallForty(player); } else if (SixtySixUtil.HasTwenty(player.Cards, card, deck)) { SixtySixUtil.CallTwenty(player); } player.GiveCard(card); return(card); }
private static Card GiveCardIfFirst(Player player, Deck deck) { var rand = new Random(System.DateTime.Now.Millisecond); var playerCards = player.Cards; if (SixtySixUtil.HasForty(playerCards, deck)) { return(player.Cards.First(x => x.Suit == deck.TrumpSuit && (x.Value == CardValue.KING || x.Value == CardValue.QUEEN))); } else if (SixtySixUtil.HasTwenty(playerCards, deck)) { return(player.Cards.First(x => x.Suit != deck.TrumpSuit && (x.Value == CardValue.KING || x.Value == CardValue.QUEEN))); } //if player has Ace trump and will reach 66 else if (playerCards.FirstOrDefault(x => x.Suit == deck.TrumpSuit && x.Value == CardValue.ACE) != null && player.Score + (int)CardValue.ACE >= Constants.TOTAL_SCORE) { return(playerCards.First(x => x.Suit == deck.TrumpSuit && x.Value == CardValue.ACE)); } //if Ace trump is thrown and player has 10 trump and will reach 66 else if (playerCards.FirstOrDefault(x => x.Suit == deck.TrumpSuit && x.Value == CardValue.TEN) != null && deck.ThrownCards.Contains(new Card(CardValue.ACE, deck.TrumpSuit)) && player.Score + (int)CardValue.TEN >= Constants.TOTAL_SCORE) { return(playerCards.First(x => x.Suit == deck.TrumpSuit && x.Value == CardValue.TEN)); } else { // give the lowest card if (deck.Cards.Count > 0 && !deck.IsClosed) { // 9 not trump if (playerCards.FirstOrDefault(x => x.Value == CardValue.NINE && x.Suit != deck.TrumpSuit) != null) { return(playerCards.First(x => x.Value == CardValue.NINE && x.Suit != deck.TrumpSuit)); } // Jack not trump else if (playerCards.FirstOrDefault(x => x.Value == CardValue.JACK && x.Suit != deck.TrumpSuit) != null) { return(playerCards.First(x => x.Value == CardValue.JACK && x.Suit != deck.TrumpSuit)); } // Queen not trump else if (playerCards.FirstOrDefault(x => x.Value == CardValue.QUEEN && x.Suit != deck.TrumpSuit) != null) { return(playerCards.First(x => x.Value == CardValue.QUEEN && x.Suit != deck.TrumpSuit)); } // KING not trump else if (playerCards.FirstOrDefault(x => x.Value == CardValue.KING && x.Suit != deck.TrumpSuit) != null) { return(playerCards.First(x => x.Value == CardValue.KING && x.Suit != deck.TrumpSuit)); } // supposed to be in this case only if the player has only 10 and Aces then just play a random card else { return(playerCards[rand.Next(playerCards.Count)]); } } else { // the cards in deck are left OR the game is closed var aces = playerCards.Where(x => x.Value == CardValue.ACE); var tenthsWhichAcesAreThrown = playerCards.Where(x => x.Value == CardValue.TEN && deck.ThrownCards.Contains(new Card(CardValue.ACE, x.Suit))); if (aces.FirstOrDefault(x => x.Suit == deck.TrumpSuit) != null) { return(aces.First(x => x.Suit == deck.TrumpSuit)); } else if (tenthsWhichAcesAreThrown.FirstOrDefault(x => x.Suit == deck.TrumpSuit) != null && deck.ThrownCards.Contains(new Card(CardValue.ACE, deck.TrumpSuit))) { return(tenthsWhichAcesAreThrown.First(x => x.Suit == deck.TrumpSuit)); } else if (aces.Count() > 0) { return(aces.First()); } else if (tenthsWhichAcesAreThrown.Count() > 0) { return(tenthsWhichAcesAreThrown.First()); } else { return(playerCards[rand.Next(playerCards.Count)]); } } } }