0
私は右上隅と左上隅の私のDISPLAYSURFウィンドウでpWinとdWin変数を表示する方法を理解しようとしています。どのくらい私はこれを行うだろうか?ここに私のコードは私の21ゲームのためのPygameの表示スコアとテキスト
##21 Card Game
##Wattel
##2016 Spring
import pygame, sys, random
from pygame.locals import *
from random import *
import random
from random import shuffle, randint
Green = (0,200,0)
CARDPOINTS = {'AD': 11,'AH': 11,'AC': 11,'AS': 11,
'KD': 10,'KH': 10,'KC': 10,'KS': 10,
'QD': 10,'QH': 10,'QC': 10,'QS': 10,
'JD': 10,'JH': 10,'JC': 10,'JS': 10,
'10D': 10,'10H': 10,'10C': 10,'10S': 10,
'9D': 9,'9H': 9,'9C': 9,'9S': 9,
'8D': 8,'8H': 8,'8C': 8,'8S': 8,
'7D': 7,'7H': 7,'7C': 7,'7S': 7,
'6D': 6,'6H': 6,'6C': 6,'6S': 6,
'5D': 5,'5H': 5,'5C': 5,'5S': 5,
'4D': 4,'4H': 4,'4C': 4,'4S': 4,
'3D': 3,'3H': 3,'3C': 3,'3S': 3,
'2D': 2,'2H': 2,'2C': 2,'2S': 2,}
def shuffleDeck():
List = ['AD','AH','AC','AS',
'KD','KH','KC','KS',
'QD','QH','QC','QS',
'JD','JH','JC','JS',
'10D','10H','10C','10S',
'9D','9H','9C','9S',
'8D','8H','8C','8S',
'7D','7H','7C','7S',
'6D','6H','6C','6S',
'5D','5H','5C','5S',
'4D','4H','4C','4S',
'3D','3H','3C','3S',
'2D','2H','2C','2S',]
CardPile = len(List)
random.shuffle(List)
return List
def want2play():
Hit2Play = input(" Hit 'y' to begin your game of 21): ")
print ("")
return Hit2Play
def deckCheck(DECK):
print (DECK)
print("There are:",len(DECK),"cards in the deck.")
if len(DECK) < 20:
DECK = shuffleDeck()
return DECK
else:
return DECK
def openingDeal(DECK):
PHAND = []
DHAND = []
DHANDT = []
PHAND, DECK = dealOneCard(PHAND, DECK)
DHAND, DECK = dealOneCard(DHAND, DECK)
DHANDT.append(DHAND[0])
PHAND, DECK = dealOneCard(PHAND, DECK)
DHAND, DECK = dealOneCard(DHAND, DECK)
DHANDT.append("back of card")
PPOINTS = scoreHAND(PHAND)
printScores_0(PPOINTS, PHAND, DHANDT)
return PHAND, DHAND, DHANDT, DECK
def pLoop(PHAND, DHAND, DHANDT, DECK):
while scoreHAND(PHAND) < 21:
PlayHH = input('Please hit or hold to continue: ')
if PlayHH == 'hit':
dealOneCard(PHAND, DECK)
printScores_0(scoreHAND(PHAND), PHAND, DHANDT)
elif PlayHH == 'hold':
print('Player holds')
printScores_0(scoreHAND(PHAND), PHAND, DHANDT)
break
return PHAND, DHAND, DECK
def dLoop(PHAND, DHAND, DECK):
printScores_1(scoreHAND(PHAND), scoreHAND(DHAND), PHAND, DHAND)
if scoreHAND(DHAND) < 18 or scoreHAND(DHAND) < 21 or scoreHAND(DHAND) < scoreHAND(PHAND) or scoreHAND(PHAND) < 22 or scoreHAND(DHAND) < 21:
dealOneCard(DHAND, DECK)
printScores_1(scoreHAND(PHAND), scoreHAND(DHAND), PHAND, DHAND)
return scoreHAND(PHAND), scoreHAND(DHAND), PHAND, DHAND
else:
return scoreHAND(PHAND), scoreHAND(DHAND), PHAND, DHAND
def checkScore(pWin, dWin, PPOINTS, DPOINTS):
if PPOINTS == DPOINTS and PPOINTS < 21:
dWin += 1
print (' ')
print ("Dealer Win")
return pWin, dWin
elif PPOINTS > 21:
dWin += 1
print(' ')
print("Dealer Win")
return pWin, dWin
elif DPOINTS > 21:
pWin += 1
print(' ')
print("Player Win")
return pWin, dWin
elif DPOINTS > PPOINTS and DPOINTS < 22:
dWin += 1
print (' ')
print ("Dealer Win")
return pWin, dWin
elif PPOINTS == 21 and DPOINTS == 21:
print(' ')
print("Tie")
return pWin, dWin
elif PPOINTS > 21 and DPOINTS > 21:
dWin += 1
print (' ')
print ("Dealer Win")
return pWin, dWin
else:
PPOINTS < 22 and DPOINTS > 21
pWin += 1
print (' ')
print ("Player Win")
return pWin, dWin
def dealOneCard(HAND,DECK):
theCard = DECK.pop(0)
HAND.append(theCard)
return HAND, DECK
def scoreHAND(HAND):
points = addScore(HAND)
aceCount=0
if points > 21:
aceCount += HAND.count('AS')
aceCount += HAND.count('AH')
aceCount += HAND.count('AC')
aceCount += HAND.count('AD')
while points > 21 and aceCount > 0:
points -= 10
aceCount -= 1
return points
else:
return points
def addScore(HAND):
tempScore = 0
for i in HAND:
tempScore += CARDPOINTS[i]
return tempScore
def printScores_0(POINTS, HAND, HAND1):
print("Player's cards: ", HAND, "Player's hand score: ", POINTS)
print("Dealer's cards: ", HAND1)
def printScores_1(PPOINTS, DPOINTS, PHAND, DHAND):
print("Player's cards: ", PHAND, "Player's hand score: ", PPOINTS)
print("Dealer's cards: ", DHAND, "Dealer's hand score: ", DPOINTS)
def main():
pygame.init()
gamex,gamey=(500,500)
DISPLAYSURF = pygame.display.set_mode((gamex,gamey))
DISPLAYSURF.fill(Green)
pygame.display.update()
DECK = shuffleDeck()
pWin = 0
dWin = 0
while True:
Hit2Play = want2play()
if Hit2Play == 'y':
DECK = deckCheck(DECK)
PHAND, DHAND, DHANDT, DECK = openingDeal(DECK)
PHAND, DHAND, DECK = pLoop(PHAND, DHAND, DHANDT, DECK)
PPOINTS, DPOINTS, PHAND, DHAND = dLoop(PHAND, DHAND, DECK)
pWin, dWin = checkScore(pWin, dWin, PPOINTS, DPOINTS)
print("")
print("Player's Wins:", pWin, "Dealer's Wins:",dWin)
print("")
else:
print("Player's Wins:", pWin, "Dealer's Wins:",dWin)
break
main()