mfmerritts / blackjack

0 stars 5 forks source link

Blackjack_Table Class/Functions #1

Closed mfmerritts closed 8 years ago

mfmerritts commented 8 years ago

Write code for the Blackjack_Table Class and it's funcitons.

L007gan commented 8 years ago

image This is the driver class for the game, it serves as the gameworld. Most of the backend will be derived in this class.

L007gan commented 8 years ago

Blackjack_Table variables:

deck: A list of cards that act as the main deck that players will receive cards from. int game_ID : An integer that represents the unique ID of the Blackjack_Table class. int round_Count: An integer that represents how many rounds have been played since the last time new_Deck(int) was called. table : A list of persons that contain all players currently at the table. Blackjack_Table functions: Blackjack_Table(): The creation of the BlackJack_Table is required for each game. At initialization, an ID will be generated and a list will be created to hold each person classes present at the table. A dealer will also be initialized and added to the last element of table list. A round counter will be initialized to zero. A list of cards will also be contained within the Blackjack_Table class. This deck will be initialized by the new_Deck(int) function, which will be called within the constructing function. add_Player(Player): This will add a specific player to the the table. First the function will check to see if the table has an available spot. If so, then a player will be added to the first empty element in the table list. remove_Player(int): This will remove a specific player from the table. It takes an integer from the argument and sets that element to null in the table list. If the argument is invalid (i.e if it tries to remove the dealer, a spot that is already empty, or a spot that does not exist an error message will appear). start_Round(): First it checks if a player is active, which calls the get_Active() function within that player's class. This is done for all players in the table list. Then two cards will be dealt to each active player, and none to those who are not active. Cards are added by calling the add_Card() function within the person class. Sets the first active player’s player_turn variable to true. Dealer always receives two cards. check_Bets(): Checks all players bets by calling the get_Bet() function for each player. If the bet is greater or equal to the minimum bet, then the active variable in the person class is set to true. If player bet is zero or less than the minimum then the active variable is set to false. set_Turn(person): Checks to see if that player is active by calling get_active() function. If true then it calls the start_turn() function for that person which is specified in the argument. This sets the variable players_Turn to true. asks_player(player): Check to see if that player’s player_Turn variable is true by calling the get_Turn() function. It then checks to see if the player’s total variable is 21. If so then a player has a blackjack and adds (2.5 \* bet) to the player’s variable money. Then the players_Turn variable is set to false.If true, but the player’s total is not 21, then it proceeds to ask the player if they want to play, double down, split(if possible) or surrender. It will ask by requiring an input from the user to specify what they would like to do. If they chose to play, it will proceed by then asking the player if they want to hit or stay. Hit add another card to the player’s hand. Stays will end the player's turn by setting player_Tu. If they have not bust, they can continue to choose an action. If a bust occurs, the bet variable is set to zero and the player’s turn is ended by setting the player_Turn and active variable to frn to false. After each input the total is calculated to determine if a player has bust or notalse. If double down is picked, it will run the previous step a second time. if surrender is picked, the player is then awarded half the amount of bet. The bet is then set equal to zero. The active and player_Turn variable for that player are set to false. clean_Up(): For each person in the table list, it will call the take_Cards() function resulting in all hands being empty. It will make sure all bets for each player are set to zero and that the active and players_Turn variable for each player is false. new_Deck(int): This function creates cards and adds them to the list deck. first it will create a card object for each card in a 52 card deck using the card class constructor. Then we repeat this process for the number used in the argument of the function. For example if int is 2, then two 52 card decks will be created and added to the list deck. shuffle_Deck(): This function take the current list deck and “shuffles” the order of the list by implementing the Fisher-Yates shuffle algorithm. check_Player_Vs_Dealer(): This checks the active variable for all players in the list table. If true, then each player’s variable total is checked with the dealer’s variable total. If player’s total is greater than dealer’s total, then that player’s bet is multiplied by two and that value is added to the players variable money (This is done by using the appropriate member functions of the player class). If the dealer’s total is greater than the player’s total then nothing is done (remember, since bet was set by taking from the money variable, the deduction has already occurred). If dealer and player totals are equal then the the value of the bet is added to the player’s variable money. increment_Count(): This adds one to variable round_Count. get_Count(): Returns the value of round_Count. reset_Count(): Sets round_Count to zero. set_Game_Id(): Generates an ID number that is unique from the other currently available. Then it sets the game_Id variable to the generated number. get_Game_Id(): Return the value of game_Id.