Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Modifying lab 8: Lame Game Computer Game Room The existing menu options w

ID: 3869116 • Letter: P

Question

Python

Modifying lab 8: Lame Game Computer Game Room

The existing menu options will stay the same:

1. Make Change

2. High Card

3. Deal Hand

4. Save Dream Hand

5. Display Dream Hand

6. Word Guess

7. Quit

  Make sure you clean up your existing code.

You will implement the class Card and modify your program to work with the card as a class rather than just an integer.

The Card class will have the following:

          Class name:              Card

          Data attributes:        __value

__face_value

          Methods:        __init__() – initialize value to 0 and face_value to an empty string

deal() – generates a random card, assigns the value, calls the
set_face_value method

                               set_value() – assigns an integer card value to the value attribute

                               set_face_value() – sets the face_value based on the what the value
attribute is

                               get_value() – returns the value of the attribute value

                               get_face_value() – returns the value of the attribute face_value

                               __str__() – returns the state of the object

Notes to help you with this lab   

There are several good examples in the book you can use as a guide.

Put the class definition in a separate file. You need to define this first. At the top of your program file you will need an import statement:
import yourClassFileName

Be sure to import random at the top of your class definition file. You will not need it in your program file.

You will define a "deal" method in your class Card:
this method will deal one card (using the random number generator).

Your main(), menu() and make_change() functions will not change.

I would start modifying the high card function first, get that to work, then move to the other functions.
In this function you will create two Card objects - one for each player. You will remove the code that assigns the random number and replace it with the call to the Class method that deals the card:
player1_card = classFileName.Card()
player2_card = clasFileName.Card()
(you do not have to use the same identifier names as I have)

Your class will be called "Card", but use the file name you gave to the file that contains the class definition.

You will need to modify the way your high card function references the card values for purposes of comparing the cards.
ex:
if player1_card.get_value() > player2_card.get_value():
print("Player 1 wins")
etc.......

Once you get this to work, you will move on to your deal hand function.
Instead of putting the integer value for each card in a list, you will create an object of type Card, invoke the deal() method, then append it to your list. There is a good example to refer to on page 448.

Your deal hand function will pass the list of objects to the display hand function and the hand stats function, so you will need to modify the code in each of those functions so they reference the data attributes in the object rather than just an integer value in a list like it currently does.

You will also have to modify your save dream hand and display dream hand functions:

Save dream hand will read values from the user and store them in a list of objects rather than a list of integers. Once you have read and stored all 5 cards, you will go through the list and store the integer value for each card into a file. The logic stays the same, you just change the way you store and access the card value.

Display dream hand will read the integer card values from the file and store them in a list of objects. Then go through the list and display the face value of the card on the screen.

You will turn in the following in Blackboard:

Your program source code named “lab9_Firstname_Lastname.py”

Your class module named “cardClass_Lastname.py”

Explanation / Answer

Class name:              Card

          Data attributes:        __value

__face_value

          Methods:        __init__() – initialize value to 0 and face_value to an empty string

deal() – generates a random card, assigns the value, calls the
set_face_value method

                               set_value() – assigns an integer card value to the value attribute

                               set_face_value() – sets the face_value based on the what the value
attribute is

                               get_value() – returns the value of the attribute value

                               get_face_value() – returns the value of the attribute face_value

                               __str__() – returns the state of the object