Exemplo n.º 1
0
 public static void AddAces(Player player, int card)
 {
     if (card == 11)
     {
         player.Aces++;
     }
 }
Exemplo n.º 2
0
        public static bool HasAces(Player player)
        {
            if (player.Aces > 0)
            {
                player.Aces--;
                player.Score -= 10;
                return true;
            }

            return false;
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
 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();
     }
 }
Exemplo n.º 5
0
 public static void AddAcesSplit(Player player, int card, bool leftDeck)
 {
     if (card == 11)
     {
         if (leftDeck)
         {
             player.SplitDeck.AcesLeft++;
         }
         else
         {
             player.SplitDeck.AcesRight++;
         }
     }
 }
Exemplo n.º 6
0
        /// <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;
        }
Exemplo n.º 7
0
        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";
        }
Exemplo n.º 8
0
        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;
        }
Exemplo n.º 9
0
 public void DisplayMoney(Player one, Player two)
 {
     PlayerMoney.Content = one.Money;
     ComputerMoney.Content = two.Money;
 }
Exemplo n.º 10
0
        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;
        }
Exemplo n.º 11
0
 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 });
 }
Exemplo n.º 12
0
 public void AddCards(Player one, Player two)
 {
     AddImages(one, PlayerImages);
     AddImages(two, ComputerImages);
 }
Exemplo n.º 13
0
 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);
     }
 }
Exemplo n.º 14
0
 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);
     }
 }
Exemplo n.º 15
0
 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;
         }
     }
 }
Exemplo n.º 16
0
 public static void ResetGame(Player one, Player two)
 {
     one.Reset();
     two.Reset();
     one.ResetSplitDeck();
 }
Exemplo n.º 17
0
 public void DisplayPoints(Player player)
 {
     if (player.Name == "Computer")
     {
         ComputerPoints.Content = player.Score;
     }
     else
     {
         PlayerPoints.Content = player.Score;
     }
 }
Exemplo n.º 18
0
 public void DisplayPointsSplit(Player player)
 {
     PlayerPoints.Content = player.SplitDeck.ScoreLeft + " : " + player.SplitDeck.ScoreRight;
 }
Exemplo n.º 19
0
 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;
         }
     }
 }