Beispiel #1
0
        /// <summary>
        /// Performs multiple checks using blackjack rules to determine if any player has won or busted.
        /// </summary>
        /// <param name="playerID">The player's ID. Needed to query the database.</param>
        /// <returns>A message to the player containing the result of the game.</returns>
        public string CheckWin(int playerID)
        {
            resultDAO = new ResultDAO(ConfigurationManager.ConnectionStrings["myConn"].ConnectionString);

            // If the player has busted, Dealer wins and game is over
            if (CheckHandStatus(player) == 0)
            {
                this.GameResult = DBLibrary.GameResult.AIWIN;
                resultDAO.AddResult(new Result(this.GameID, playerID, 0));
                return("You busted!");
            }
            // Dealer has busted, player wins and game is over
            else if (CheckHandStatus(dealer) == 0)
            {
                this.GameResult = DBLibrary.GameResult.PLAYERWIN;
                resultDAO.AddResult(new Result(this.GameID, playerID, 1));
                return("Dealer busted. You win!");
            }
            // If both dealer and player have completed their turns, check for highest hand
            else if (player.TurnComplete && dealer.TurnComplete)
            {
                // If player and dealer have the same hand value(including blackjacks), its a draw
                if (player.PlayerHand.HandValue == dealer.PlayerHand.HandValue)
                {
                    this.GameResult = DBLibrary.GameResult.PUSH;
                    return("It's a push!");
                }
                // Player's hand is higher than the dealers hand
                else if (player.PlayerHand.HandValue > dealer.PlayerHand.HandValue)
                {
                    this.GameResult = DBLibrary.GameResult.PLAYERWIN;
                    resultDAO.AddResult(new Result(this.GameID, playerID, 1));
                    return("You win!");
                }
                // Dealers hand is higher than players hand
                else if (dealer.PlayerHand.HandValue > player.PlayerHand.HandValue)
                {
                    this.GameResult = DBLibrary.GameResult.AIWIN;
                    resultDAO.AddResult(new Result(this.GameID, playerID, 0));
                    return("You lose!");
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Modifies the GameResult to indicate who won the game, push is a tie.
        /// </summary>
        /// <param name="owner">Symbolizes who won the game</param>
        public void EndGame(int owner)
        {
            ResultDAO dao = new ResultDAO(ConfigurationManager.ConnectionStrings["myConn"].ConnectionString);

            if (owner == 1)
            {
                this.GameResult = DBLibrary.GameResult.PLAYERWIN;
                dao.AddResult(new Result("CON", player.PlayerID, 1));
            }
            else if (owner == 2)
            {
                this.GameResult = DBLibrary.GameResult.AIWIN;
                dao.AddResult(new Result("CON", player.PlayerID, 0));
            }
            else
            {
                this.GameResult = DBLibrary.GameResult.PUSH;
            }
        }