public static void AddAces(Player player, int card) { if (card == 11) { player.Aces++; } }
public static bool HasAces(Player player) { if (player.Aces > 0) { player.Aces--; player.Score -= 10; return true; } return false; }
public static Player CalculateWinner(Player one, Player two) { if ((one.Score > two.Score || two.Score > 21 ) && one.Score <= 21) { return one; } if ((two.Score > one.Score || one.Score > 21) && two.Score <= 21) { return two; } return null; }
public void CheckMoney(Player one, Player two) { if (one.Money <= 0) { new EndWindow(two.Name).Show(); Close(); } else if (two.Money <= 0) { new EndWindow(one.Name).Show(); ; Close(); } }
public static void AddAcesSplit(Player player, int card, bool leftDeck) { if (card == 11) { if (leftDeck) { player.SplitDeck.AcesLeft++; } else { player.SplitDeck.AcesRight++; } } }
/// <summary> /// When left and right score is higher than computer's score return one /// When both scores are lower than computer's score return two /// Other outcome is a draw, return null /// </summary> public static Player CalculateWinnerSplit(Player one, Player two) { int scoreLeft = one.SplitDeck.ScoreLeft; int scoreRight = one.SplitDeck.ScoreRight; if (((scoreLeft > two.Score && scoreRight > two.Score) || (two.Score > 21)) && scoreLeft <= 21 && scoreRight <= 21) { return one; } if (scoreLeft < two.Score && scoreRight < two.Score && two.Score <= 21) { return two; } return null; }
public GameViewModel(IView view, string name) { View = view; Random = new Random(); Commands = new Models.Commands(this); Player = new Player(name, 1000, ImagesHelper.CreateImage("player"), 2); Player.CreateSplitDeck(); view.AddSplitDeckCards(Player); Computer = new Player("Computer", 1000, ImagesHelper.CreateImage("computer"), 2); view.DisplayMoney(Player, Computer); view.DisplayName(name); CardImages = ImagesHelper.GetBlackJackCards(); view.AddCards(Player, Computer); Player.ShowBackside(); Computer.ShowBackside(); BetAmount = "100"; }
public static bool HasAcesSplit(Player player, bool leftDeck) { if (leftDeck) { if (player.SplitDeck.AcesLeft > 0) { player.SplitDeck.AcesLeft--; player.SplitDeck.ScoreLeft -= 10; return true; } return false; } if (player.SplitDeck.AcesRight > 0) { player.SplitDeck.AcesRight--; player.SplitDeck.ScoreRight -= 10; return true; } return false; }
public void DisplayMoney(Player one, Player two) { PlayerMoney.Content = one.Money; ComputerMoney.Content = two.Money; }
public static void ResetImages(Player one, Player two) { one.Images.ForEach(x => x.Source = null); two.Images.ForEach(x => x.Source = null); two.Images[0].Source = two.ImageBack; two.Images[1].Source = two.ImageBack; }
public void AddSplitDeckCards(Player player) { player.SplitDeck.ImagesLeft.AddRange(new List<Image>() { Card3Player, Card5Player, CardLeft1, CardLeft2, CardLeft3 }); player.SplitDeck.ImagesRight.AddRange(new List<Image>() { Card4Player, Card6Player, CardRight1, CardRight2, CardRight3 }); }
public void AddCards(Player one, Player two) { AddImages(one, PlayerImages); AddImages(two, ComputerImages); }
private void AddImages(Player player, Grid grid) { for (var i = 0; i < VisualTreeHelper.GetChildrenCount(grid); i++) { var child = VisualTreeHelper.GetChild(grid, i); player.Images.Add((Image)child); } }
public void SplitDeck(Player player, bool activate) { if (activate) { BorderSplit.Visibility = Visibility.Visible; defaultButtons.ToList().ForEach(x => x.Visibility = Visibility.Hidden); splitButtons.ToList().ForEach(x => x.Visibility = Visibility.Visible); } else { BorderSplit.Visibility = Visibility.Hidden; defaultButtons.ToList().ForEach(x => x.Visibility = Visibility.Visible); splitButtons.ToList().ForEach(x => x.Visibility = Visibility.Hidden); } }
public void EndGameSplit(Player one, Player two, int bet) { Player winner = GameHelper.CalculateWinnerSplit(one, two); if (winner == null) { ShowResult("Draw!"); } else { ShowResult(winner.Name + " won the game!"); // Multiply by two because we doubled our wins / loses if (winner == one) { one.Money += bet * 2; two.Money -= bet * 2; } else { two.Money += bet * 2; one.Money -= bet * 2; } } }
public static void ResetGame(Player one, Player two) { one.Reset(); two.Reset(); one.ResetSplitDeck(); }
public void DisplayPoints(Player player) { if (player.Name == "Computer") { ComputerPoints.Content = player.Score; } else { PlayerPoints.Content = player.Score; } }
public void DisplayPointsSplit(Player player) { PlayerPoints.Content = player.SplitDeck.ScoreLeft + " : " + player.SplitDeck.ScoreRight; }
public void EndGame(Player one, Player two, int bet) { Player winner = GameHelper.CalculateWinner(one, two); if (winner == null) { ShowResult("Draw!"); } else { ShowResult(winner.Name + " won the game!"); if (winner == one) { one.Money += bet; two.Money -= bet; } else { two.Money += bet; one.Money -= bet; } } }