我是一个快乐的业余爱好者,他试图创造一个“或多或少”的游戏。我在积分分配上是不对的。我的 if 语句无法正常工作。我没有收到错误消息,但一切都在“其他”中运行。条件永远不会满足,尽管 K、Q、J、Ace 是随机的……为什么?
class Card(object):
totPoints = 0
VALUE = {"A":1, "2":2, "3":3, "4":4, "5":5, "6":6, "7":7, "8":8, "9":9, "10":10, "J":10, "Q":10, "K":10}
RANKS = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
SUIT = ["Python/projekt/bilder/hearts.png", "Python/projekt/bilder/spades.png", "Python/projekt/bilder/diamond.png", "Python/projekt/bilder/clubs.png"]
def __init__(self, rank, suit):
self.rank = rank
self.suit = suit
def __str__(self):
rep = self.rank + self.suit
return rep
def draw(self):
bg = ImageTk.PhotoImage(Image.open(self.suit).resize((10, 10)))
cardGraph = Canvas(win, width=70, height=100, bg="White", bd=1, relief='solid', highlightthickness=2)
cardGraph.photo=bg
cardGraph.pack(side = "left", anchor=NW)
class Hand(object):
def __init__(self):
self.cards = []
def __str__ (self):
if self.cards:
rep = ""
for card in self.cards:
rep += str(card) + " "
else:
rep = "<empty>"
return rep
def clear(self):
self.cards = []
def add(self, card):
self.cards.append(card)
def give(self, card, other_hand):
self.cards.remove(card)
other_hand.add(card)
class Deck(Hand):
def populate(self):
for suit in Card.SUIT:
for rank in Card.RANKS:
self.add(Card(rank, suit))
def shuffle(self):
import random
random.shuffle(self.cards)
DrawCard = self.cards[0]
DrawCard.draw()
def deal(self, hands, per_hand = 0):
for rounds in range(per_hand):
for hand in hands:
if self.cards:
top_card = self.cards[0]
self.give(top_card, hand)
else:
print("Cant continue deck. Out of cards!!")
def setValue(self):
if self.cards[0] == "K":
Card.totPoints += 10
print Card.totPoints
elif self.cards[0] == "Q":
Card.totPoints += 10
elif self.cards[0] == "J":
Card.totPoints += 10
elif self.cards[0] == "A":
Card.totPoints += 10
else:
Card.totPoints += self.cards
print Card.totPoints