示例#1
0
        /// <summary>
        /// Constructor for TableVm
        /// </summary>
        public TableVM()
        {
            this.deck    = new DeckVM();
            this.players = new ObservableCollection <PersonVM>();
            this.dealer  = new PersonVM()
            {
                PlayerNumber = 0, PlayerName = "Dealer"
            };
            this.numPlayers = 0;

            this.nextHandButton     = Visibility.Hidden;
            this.playerNameTxtBoxes = Visibility.Hidden;
            this.numPlayersTxtBox   = Visibility.Visible;
            this.playerCards        = Visibility.Hidden;
            this.startGameButton    = Visibility.Hidden;

            this.NextHandCommand = new CommandHelper()
            {
                CanExecuteDelegate = x => true,
                ExecuteDelegate    = x => this.NextHandCmdExecuted()
            };
            this.QuitGameCommand = new CommandHelper()
            {
                CanExecuteDelegate = x => true,
                ExecuteDelegate    = x => this.QuitGameCmdExecuted()
            };
            this.CreatePlayersCommand = new CommandHelper()
            {
                CanExecuteDelegate = x => true,
                ExecuteDelegate    = x => this.CreatePlayersCmdExecuted()
            };
            this.LayoutPlayersCommand = new CommandHelper()
            {
                CanExecuteDelegate = x => this.LayoutPlayersCanExecute(),
                ExecuteDelegate    = x => this.LayoutPlayersCmdExecuted()
            };
            this.StartGameCommand = new CommandHelper()
            {
                CanExecuteDelegate = x => true,
                ExecuteDelegate    = x => this.StartGameCmdExecuted()
            };
            this.StandCommand = new CommandHelper()
            {
                CanExecuteDelegate = x => StandCanExecute(x),
                ExecuteDelegate    = x => this.StandCmdExecuted(x)
            };
            this.HitCommand = new CommandHelper()
            {
                CanExecuteDelegate = x => this.HitCanExecute(x),
                ExecuteDelegate    = x => this.HitCmdExecuted(x)
            };
        }
示例#2
0
        /// <summary>
        /// Creates the number of players determined by the user
        /// </summary>
        private void CreatePlayersCmdExecuted()
        {
            string message;

            if (numPlayers == 0 || numPlayers < 1 || numPlayers > 5)
            {
                message = "Invalid Input. Please enter a number between 1 and 5.";
                MessageBox.Show(message);
            }
            else
            {
                for (int i = 0; i < numPlayers; i++)
                {
                    PersonVM person = new PersonVM()
                    {
                        PlayerNumber = i + 1
                    };
                    players.Add(person);
                }

                this.NumPlayersTxtBox   = Visibility.Hidden;
                this.PlayerNameTxtBoxes = Visibility.Visible;
            }
        }
示例#3
0
        /// <summary>
        /// Ends the players turn and starts the next players turn if there
        /// is another player
        /// </summary>
        public void StandCmdExecuted(object parameter)
        {
            PersonVM person = (PersonVM)parameter;

            person.HandIsVisible = false;
            person.HitAndStand   = Visibility.Hidden;
            int playerNum = this.players.IndexOf(person);
            int index;

            for (index = playerNum + 1; index <= players.Count - 1; index++)
            {
                if (players[index].OutOfMoney == false)
                {
                    players[index].HandIsVisible = true;
                    players[index].HitAndStand   = Visibility.Visible;
                    foreach (CardVM card in players[index].CardsInHand)
                    {
                        card.FaceUp = true;
                    }
                    break;
                }
            }
            if (index > players.Count - 1)
            {
                dealer.HandIsVisible = true;
                foreach (CardVM card in dealer.CardsInHand)
                {
                    card.FaceUp = true;
                }

                bool playing = true;
                while (playing)
                {
                    if (dealer.Bust == false)
                    {
                        if (dealer.Score2 < 17)
                        {
                            dealer.DealCard(deck);
                        }
                        else if (dealer.Score2 <= 21)
                        {
                            dealer.HandIsVisible = false;
                            playing = false;
                        }
                        else if (dealer.Score1 < 17)
                        {
                            dealer.DealCard(deck);
                        }
                        else
                        {
                            dealer.HandIsVisible = false;
                            playing = false;
                        }
                    }
                    else
                    {
                        dealer.BustTextBlock = Visibility.Visible;
                        playing = false;
                    }
                }
                foreach (PersonVM player in players)
                {
                    if (player.Bust == true)
                    {
                        player.Money = player.Money - player.BetText;
                    }
                    else
                    {
                        if (dealer.Bust == true)
                        {
                            if (player.Score1 == 21 || player.Score2 == 21)
                            {
                                player.Money = player.Money + (player.BetText * 1.5);
                            }
                            else
                            {
                                player.Money = player.Money + player.BetText;
                            }
                        }
                        else
                        {
                            if (player.Score2 <= 21)
                            {
                                if (dealer.Score2 <= 21)
                                {
                                    if (player.Score2 < dealer.Score2)
                                    {
                                        player.Money = player.Money - player.BetText;
                                    }
                                    else if (player.Score2 > dealer.Score2)
                                    {
                                        if (player.Score2 == 21)
                                        {
                                            player.Money = player.Money + (player.BetText * 1.5);
                                        }
                                        else
                                        {
                                            player.Money = player.Money + player.BetText;
                                        }
                                    }
                                }
                                else
                                {
                                    if (player.Score2 < dealer.Score1)
                                    {
                                        player.Money = player.Money - player.BetText;
                                    }
                                    else if (player.Score2 > dealer.Score1)
                                    {
                                        if (player.Score2 == 21)
                                        {
                                            player.Money = player.Money + (player.BetText * 1.5);
                                        }
                                        else
                                        {
                                            player.Money = player.Money + player.BetText;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (dealer.Score2 <= 21)
                                {
                                    if (player.Score1 < dealer.Score2)
                                    {
                                        player.Money = player.Money - player.BetText;
                                    }
                                    else if (player.Score1 > dealer.Score2)
                                    {
                                        if (player.Score1 == 21)
                                        {
                                            player.Money = player.Money + (player.BetText * 1.5);
                                        }
                                        else
                                        {
                                            player.Money = player.Money + player.BetText;
                                        }
                                    }
                                }
                                else
                                {
                                    if (player.Score1 < dealer.Score1)
                                    {
                                        player.Money = player.Money - player.BetText;
                                    }
                                    else if (player.Score1 > dealer.Score2)
                                    {
                                        if (player.Score1 == 21)
                                        {
                                            player.Money = player.Money + (player.BetText * 1.5);
                                        }
                                        else
                                        {
                                            player.Money = player.Money + player.BetText;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (player.Money <= 0)
                    {
                        if (player.OutOfMoney == false)
                        {
                            string NoMoney = player.PlayerName + " is out of money and owe's " + (player.Money * -1) + ".";
                            MessageBox.Show(NoMoney);
                            player.OutOfMoney = true;
                            player.BetOnTable = Visibility.Hidden;
                            player.NoMoney    = Visibility.Visible;
                        }
                        else
                        {
                        }
                    }
                }
                this.NextHandButton = Visibility.Visible;
            }
        }