黑杰克游戏多轮系统
Black Jack game multiple round system
所以我和我的朋友正在制作一个 21 点游戏,我很难将游戏设置为多轮长,所以在一轮结束后下一轮开始。我不知道该怎么做。这是我的代码:
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.")
所以我和我的朋友正在制作一个 21 点游戏,我很难将游戏设置为多轮长,所以在一轮结束后下一轮开始。我不知道该怎么做。这是我的代码:
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.")