【发布时间】:2020-09-26 06:05:32
【问题描述】:
我需要制作一个黑杰克游戏,它分为 2 个文件,一个处理洗牌,另一个处理实际游戏
我的问题是我可以获得为玩家和庄家打印两张牌的代码,尽管我需要以这样的格式打印
玩家的手牌是 3:1 of Clubs |红心2
不是这样的
['1C', '2H']
显示总数和分牌
这是管理游戏的第一个文件,另一个是卡片
import playing_cards
import random
player_hand = []
dealers_hand = []
#
# Testing code for step 1
##card = playing_cards.deal_one_card()
##print(card)
# Player
# Deal first card
card = playing_cards.deal_one_card()
# Append it to the player_hand list
player_hand.append(card)
# Deal second card
card = playing_cards.deal_one_card()
# Append it to the player_hand list
player_hand.append(card)
#ADDING UP BOTH CARDS
# Display the player's hand to the screen using a simple print statement
print("Player's hand is ", player_hand)
#Stage 3 - dealer
# Deal first card
card = playing_cards.deal_one_card()
# Append it to the player_hand list
dealers_hand.append(card)
# Deal second card
card = playing_cards.deal_one_card()
# Append it to the player_hand list
dealers_hand.append(card)
# Display the player's hand to the screen using a simple print statement
print(dealers_hand)
这是另一个文件,但任务说我不能修改它,我只是添加它以使其更容易理解
deck = ['AH','2H','3H','4H','5H','6H','7H','8H','9H','TH','JH','QH','KH',
'AD','2D','3D','4D','5D','6D','7D','8D','9D','TD','JD','QD','KD',
'AS','2S','3S','4S','5S','6S','7S','8S','9S','TS','JS','QS','KS',
'AC','2C','3C','4C','5C','6C','7C','8C','9C','TC','JC','QC','KC']
# Playing deck in use
playing_deck = []
# Function to determine whether there are any cards left in the
# deck of playing cards
# Parameters: No parameters
# Returns: True if the deck is empty, False otherwise
def is_empty_deck():
# Check to see whether playing deck is empty
return len(playing_deck) == 0
# Function to rebuild and shuffle the deck
# Parameters: No parameters
# Returns: Nothing is returned from the function.
def reset_deck():
global playing_deck
# Create new playing deck
playing_deck = deck.copy()
# Shuffle deck
random.shuffle(playing_deck)
# Function to deal one card
# Parameters: No parameters
# Returns: A string (containing two characters) representing
# the card delt, i.e. '2H' meaning 2 of Hearts
def deal_one_card():
# Check to see whether there are any cards left
if is_empty_deck():
# Rebuild and shuffle deck
reset_deck()
# Return a card (string of two characters)
return playing_deck.pop(0)
【问题讨论】:
-
请不要通过破坏您的帖子为他人增加工作量。通过在 Stack Exchange (SE) 网络上发帖,您已在 CC BY-SA license 下授予 SE 分发内容的不可撤销的权利(无论您未来的选择如何)。根据 SE 政策,分发非破坏版本。因此,任何此类破坏性编辑都将被还原。请参阅How does deleting work?,了解有关删除本网站内容如何运作的更多信息。