这是我的第一篇 StackOverflow 帖子,如果我做错了什么,请告诉我!我正在尝试用 python 制作纸牌游戏,并被告知使用基于类的系统是最好的。在尝试这样做的同时,当将所有卡片放入一副牌中时,这些类似乎将值复制到代码的 board.cards 部分。#definitions and importsimport randomclass Card: suit = "" base = ""class Hand: cards = [] poweri = 0 powerii = 0class Stack: cards = []#instantiates classesdeck = Stack()board = Stack()player = Hand()dealer = Hand()#creates ordered empty deckdef 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 deckdef shuffle(): random.shuffle(deck.cards)newdeck(deck)#disabled to make debug easier#shuffle()#prints entire deckprint("\nDeck")for i in range(len(deck.cards)): print(deck.cards[i].base, deck.cards[i].suit)print(len(deck.cards))#prints entire boardprint("\nBoard")for i in range(len(board.cards)): print(board.cards[i].base, board.cards[i].suit)板子应该是空的???
添加回答
举报
0/150
提交
取消