这是我的第一篇 StackOverflow 帖子,如果我做错了什么,请告诉我!
我正在尝试用 python 制作纸牌游戏,并被告知使用基于类的系统是最好的。
在尝试这样做的同时,当将所有卡片放入一副牌中时,这些类似乎将值复制到代码的 board.cards 部分。
#definitions and imports
import random
class Card:
suit = ""
base = ""
class Hand:
cards = []
poweri = 0
powerii = 0
class Stack:
cards = []
#instantiates classes
deck = Stack()
board = Stack()
player = Hand()
dealer = Hand()
#creates ordered empty deck
def newdeck(obj):
for x in ["2","3","4","5","6","7","8","9","A","B","C","D","E"]:
for y in ["C","D","H","S"]:
card = Card()
card.base = x
card.suit = y
obj.cards.append(card)
#shuffles deck
def shuffle():
random.shuffle(deck.cards)
newdeck(deck)
#disabled to make debug easier
#shuffle()
#prints entire deck
print("\nDeck")
for i in range(len(deck.cards)):
print(deck.cards[i].base, deck.cards[i].suit)
print(len(deck.cards))
#prints entire board
print("\nBoard")
for i in range(len(board.cards)):
print(board.cards[i].base, board.cards[i].suit)
板子应该是空的???
相关分类