Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2 . Create a class BlackJack. The class should derive from Tk or Frame ( either one is fine ) and should contain the following

2. 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
1) Pressing the Hit button will call a function that will deal the player a card 2) Pressing the Stay button will calculate the player and dealer totals.
3) If the dealer's total is UNDER 15 then the dealer must take a card until his total EXCEEDS 15.
ii. Create two labels and two text entry boxes.
1) The labels should read "Player Score" and "Dealer Score"
2) The text entry boxes will contain the actual score of the player and Dealer
3) 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 3 parameters with default values, rangeStart=0, rangeEnd=4 and
rangeInterval =1
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.
1) For every card that is dealt you will have to align it correctly in the GUI.
2) 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
3) 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
4) If the cards the dealer has exceed 21 show a tkinter popup window which states that you won. If the cards the player has exceeds 21 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:
1) 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 21
2) If the players score is
3) Otherwise the player wins (this assumes the above criteria has not been met)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions