Question: 2 . Create a class BlackJack. The class should derive from Tk or Frame ( either one is fine ) and should contain the following
Create a class BlackJack. The class should derive from Tk or Frame either one is fine and should contain the following methods which perform the following actions:
a Constructor takes the parent as a constructor with a default value set to None
i The constructor should initiate the GUI
ii Call the Setup function
b Setup takes no parameters
i Create two buttons Hit and Stay Each button should have a call back function when
pressed
Pressing the Hit button will call a function that will deal the player a card Pressing the Stay button will calculate the player and dealer totals.
If the dealer's total is UNDER then the dealer must take a card until his total EXCEEDS
ii Create two labels and two text entry boxes.
The labels should read "Player Score" and "Dealer Score"
The text entry boxes will contain the actual score of the player and Dealer
The text entry boxes should be set to readonly iii. Read in the 'fileMap.txt file. This will essentially be your 'deck' of cards iv Call DealCards
c DealCards Takes parameters with default values, rangeStart rangeEnd and
rangeInterval
i Read a random line in from the file which was read in Setup This line will contain
the file name of a specific image
ii Create a widget based on the file name
iii. Create a new card object from this information iv When a card is dealt it should no longer be available to select in future card deals.
You essentially need to remove it from the deck
v The cards should be dealt in alternating fashion. Specifically, a card should be dealt to the player, then to the dealer one at a time.
For every card that is dealt you will have to align it correctly in the GUI.
It is a good idea to store the cards dealt to each player in a data structure of some sort. This will help you keep track of each players card value
To sum the values of the cards you will NOT be able to use the sum function. You will have to iterate through the structure you store the cards in and calculate the values. A good way to do this is to write a separate function which takes a list as a parameter and returns an integer
If the cards the dealer has exceed show a tkinter popup window which states that you won. If the cards the player has exceeds then print a different popup indicating the dealer won.
d Stay takes no parameters
i Determine if the dealer and the player have equal card values. If they do display a popup indicating it is a tie, then return
ii If there is no tie then the dealer must be dealt a card. You will have to determine the correct parameters to pass to the DealCards function in order to have the cards dealt properly. iii. Recalculate the total of the dealer's cards. Determine the winner. Winning is
determined by:
If the total value of the dealer's cards is greater than the total value of the players cards AND the dealer's cards value is less than or equal to
If the players score is
Otherwise the player wins this assumes the above criteria has not been met
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
