I have set up a code in a class but i am not sure if this is the class that i would use.I have to put the logic of the game in a Class and then use the methods from the class to run the game.Right now i have some methods in a class but i am not sure on how i would go on getting it to work and calling the functions.I would like help on Possible telling me if i need another class and how to fix my methods in the class.Also if you would point me in the right direction on how i would use the methods and then call them in another file so i can make the BlackJack Program work. please and thanks for the help
from random import *
class DeckOfCards:
def __init__(self):
#Make the Deck Of Cards
self.__cards = [2,3,4,5,6,7,8,9,10,10,10,10,11] * 4
#keeps the score for the player and computer
playerScore = 0
computerScore = 0
#holds the cards
player = []
computer =[]
#boolean to see who wins
PlayerLoser = False
ComputerLoser = False
def drawCard(self):
#draw a card for the player
player.append(choice(self.__cards))
def drawCardComp(self):
#draw a card for the computer
computer.append(choice(self.__cards))
def totalOfPlayer(self):
#the total the player has in his hands
self.__totalOfP = total(player)
return self.__totalOfP
def totalOfComputer(self):
#the total the computer has in his hands
self.__totalOfC = total(computer)
return self.__totalOfC
def playGame(self):#i dunno if this is the method i am going to use here
while True:
#i want it to call the function in the class to draw a card
drawCard()
drawCard()
if self.__totalOfP > 21:
print 'You Lost'
playerLoser = True
elif self.totalOfP == 21:
print 'hey congrats you got BlackJack :)'
else:
goAgain = raw_input("Hit or Stand (h or s): ").lower()
if goAgain == 'h':
#i want it to call the function in the class to get another class
drawCard()
while True:
# loop for the computer's play
#draw the computer cards
drawCardComp()
drawCardComp()
while True:
if totalOfC < 18:
#draw the card if its less than 18
print "the computer has %s for a total of %d" % (computer, self.__totalOfComputer)
# now figure out who won ...
if self.__totalOfComputer > 21:
print "The computer is busted!"
ComputerLoser = True
if PlayerLoser == False:
print 'The Player Wins'
playerScore += 1
elif totalOfC > totalOfP:
print 'the Computer wins'
computerScore += 1
elif totalOfC == totalOfP:
print 'TIE'
elif totalOfP > totalOfC:
if PlayerLoser == False:
print 'The Player Wins'
playerScore += 1
elif ComputerLoser == False:
print 'The Computer Wins'
computerScore += 1
print
print "Wins, player = %d computer = %d" % (playerScore, computerScore)
exit = raw_input("Press Enter (q to quit): ").lower()
print