【问题标题】:Black Jack game multiple round system二十一点游戏多轮系统
【发布时间】:2021-07-19 07:01:26
【问题描述】:
所以我和我的朋友正在制作二十一点游戏,我无法让游戏长时间进行多轮,所以在一轮结束后,下一轮开始。我不知道该怎么做。这是我的代码:
starter_chips = 500
print(f"You have {starter_chips} chips")
bet = int(input("How much do you want to bet: "))
input_chips = starter_chips - bet
even_score_chips = input_chips + bet
print(f"You have {input_chips} left")
dealer_cards = 17
player_cards = 17
if player_cards == dealer_cards:
print(f"You get your bet back and have {even_score_chips} chips")
之后我想开始下一轮。
【问题讨论】:
标签:
python
python-3.x
blackjack
【解决方案1】:
您基本上想用while 循环将现有代码包装成一手牌,该循环询问该游戏是否要继续玩。以您的代码为起点,您可能会这样做:
user_chips = int(input("How many chips do you start with?: "))
## --------------------------
## continue playing until you "break" out of this loop
## You could do also loop based on a variable that is initially true but changes to false to stop
## --------------------------
while True:
print(f"You have {user_chips} chips")
user_bet = int(input("How much do you want to bet: "))
## --------------------------
## adjust the player's chip total based on bet
## --------------------------
user_chips -= user_bet
## --------------------------
## --------------------------
## deal out several rounds of cards
## --------------------------
dealer_total = 17
player_total = 17
## --------------------------
## --------------------------
## Act on final totals
## --------------------------
if player_total == dealer_total:
print(f"You and the dealer both have {player_total}. Your bet of {user_bet} is returned to you")
user_chips += user_bet
## --------------------------
## --------------------------
## Ask the user if they would like to continue playing and if not "break" to force an exit from the while loop.
## --------------------------
if input("Play again? (y|n): ").lower() != "y":
break
## --------------------------
## --------------------------
print(f"You leave the table with {user_chips} chips.")