[英]Black Jack game multiple round system
所以我和我的朋友正在做一个二十一点游戏,我无法让游戏长时间进行多轮,所以在一轮结束后,下一轮开始。 我不知道该怎么做。 这是我的代码:
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")
在此之后,我想开始下一轮。
你基本上想用一个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.")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.