// Function to finish the different rounds of game, // The game will be ended if one of player has exceeded // maximum scrore to win. private void endGame() { int differenceScore = GinRummy.Score(HumanCards, ComputerCards); round += 1; if (differenceScore > 0) { firstWinnerScore += differenceScore; RaiseNotification("You win at Round" + round, "Round" + round); } else { secondWinnerScore += (differenceScore * -1); RaiseNotification("Computer wins at Round" + round, "Round" + round); } scoreLabel(firstWinnerScore, secondWinnerScore); if (firstWinnerScore >= winingScore) { RaiseNotification("Congratulations, You have win this game", "You wins"); resetGame(); } else if (secondWinnerScore >= winingScore) { RaiseNotification("Sorry, Computer Player wins this game", "Computer Wins"); resetGame(); } else { resetGame(); } }
private void ComputerTurn() { var takeDiscard = ComputerPlayer.ComputerPickupDiscard(ComputerCards, Discards[Discards.Count - 1], RemainingDeck); if (takeDiscard) { var discardCard = Discards[Discards.Count - 1]; Discards.Remove(discardCard); ComputerCards.Add(discardCard); } else { Cards.Card remainingDeckCards = RemainingDeck[RemainingDeck.Count - 1]; RemainingDeck.Remove(remainingDeckCards); ComputerCards.Add(remainingDeckCards); } var compMove = ComputerPlayer.ComputerMove(ComputerCards); ComputerCards.Remove(compMove.Item2.Value); Discards.Add(compMove.Item2.Value); var scores = GinRummy.Score(ComputerCards, HumanCards); if (compMove.Item1.IsGin) { compScore += scores; if (humanScore < 100 && compScore < 100) { RaiseNotification("Human Score: " + humanScore + ". Computer Score: " + compScore, "Scores So Far"); CleanUpCards(); } } else if (compMove.Item1.IsKnock) { if (scores > 0) { compScore += scores; if (humanScore < 100 && compScore < 100) { RaiseNotification("Human Score: " + humanScore + ". Computer Score: " + compScore, "Scores So Far"); CleanUpCards(); } } else { humanScore += Math.Abs(scores); if (humanScore < 100 && compScore < 100) { RaiseNotification("Human Score: " + humanScore + ". Computer Score: " + compScore, "Scores So Far"); CleanUpCards(); } } } }
private async void ButtonClick() { var scores = GinRummy.Score(HumanCards, ComputerCards); if (scores > 0) { humanScore += scores; } else { compScore += Math.Abs(scores); } RaiseNotification("Human Score: " + humanScore + ". Computer Score: " + compScore, "Scores So Far"); CleanUpCards(); }
private void KnockClick() { if (Deadwood < 10 && dealFinishied) { int currentScore = GinRummy.Score(HumanCards, ComputerCards); int humanDeadwood = GinRummy.Deadwood(HumanCards); int computerDeadwood = GinRummy.Deadwood(ComputerCards); if (currentScore > 0) { HumanScore += currentScore; RaiseNotification("It seems I have underestimated you, I only had a Deadwood of " + computerDeadwood + " while you had a " + humanDeadwood, "Human Knock"); } else { ComputerScore += (currentScore * -1); RaiseNotification("You fell into my trap human I had a score of " + ComputerScore + " while you had a weak score of " + HumanScore, "Human Undercut"); } nextRound(); // Do something to check what the current score is and see if it is the end of the game } }
private void GinClick() { ComputerScore += 50; CheckForEndGame(); if (Deadwood == 0 && dealFinishied) { int currentScore = GinRummy.Score(HumanCards, ComputerCards); if (currentScore > 0) { HumanScore += currentScore; } // Do something to check what the current score is and see if it is the end of the game } else if (!dealFinishied) { RaiseNotification("Go back to 104, script kiddie.", "Can't go Gin during the deal"); } else { RaiseNotification("You don't have a low enough Deadwood to go Gin yet, noob!", "Too much Deadwood!"); } }
static bool Turn(Player player, Player opponent) { Console.WriteLine(player.Name); player.Cards.Sort(); foreach (var card in player.Cards) { Console.Write("{0} ", ToString(card)); } Console.WriteLine(); Console.Write("Thinking ... "); var pickupDiscard = ComputerPlayer.ComputerPickupDiscard(player.Cards, Discards.Peek(), RemainingDeck); Console.WriteLine(); if (pickupDiscard) { var card = Discards.Pop(); player.Cards.Add(card); Console.WriteLine("picks up {0} from Discard pile", ToString(card)); } else { var card = RemainingDeck.Pop(); player.Cards.Add(card); Console.WriteLine("picks up {0} from Remaining Deck", ToString(card)); } var move = ComputerPlayer.ComputerMove(player.Cards); var discard = move.Item2; if (FSharpOption <Cards.Card> .get_IsSome(discard)) { Discards.Push(discard.Value); player.Cards.Remove(discard.Value); Console.WriteLine("Discard {0}", ToString(discard.Value)); } else { Console.WriteLine("Discard nothing"); } Console.WriteLine("deadwood score = {0}", GinRummy.Deadwood(player.Cards)); var action = move.Item1; if (action.IsGin) { Console.WriteLine("Gin!"); } else if (action.IsKnock) { Console.WriteLine("Knock!"); } if (!action.IsContinue) { Console.WriteLine(player.Name + " goes out first ..."); var score = GinRummy.Score(player.Cards, opponent.Cards); if (score > 0) { player.Score += score; } else { opponent.Score -= score; } } return(!action.IsContinue); }