所以我正在使用Python开发卡片游戏项目,并且我已经获得了一些初学者代码。我们有一个名为assignCard
的函数,它应该在52" card"的数组中分配一个索引位置。到甲板,播放器或计算机。
以下是代码:
""" cardGame.py
basic card game framework
keeps track of card locations for as many hands as needed
"""
NUMCARDS = 52
DECK = 0
PLAYER = 1
COMP = 2
cardLoc = [0] * NUMCARDS
suitName = ("hearts", "diamonds", "spades", "clubs")
rankName = ("Ace", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Jack", "Queen", "King")
playerName = ("deck", "player", "computer")
def main():
clearDeck()
for i in range(5):
assignCard(PLAYER)
assignCard(COMP)
showDeck()
showHand(PLAYER)
showHand(COMP)
def clearDeck():
cardLoc[0] * NUMCARDS
def assignCard(playerName):
def showDeck():
print("# card location")
def showHand(playerName):
main()
我们不应该编辑主函数末尾之外的任何内容,我们唯一要编写的是main函数内的函数。
我们正在向每位玩家发放五张牌,所以我的问题是,使用for i in range(5)
处理五张牌,我怎么能独家向每位玩家发牌五张牌?我在关联数组和索引方面遇到了一些麻烦,所以任何建议或提示都会非常感激!
答案 0 :(得分:0)
生成一个从0到51的数字数组,将每个数字映射到一张卡片。洗牌阵。在每个回合中,给玩家阵列中的第一张牌并将其删除。