您如何创建具有有效投注功能的游戏?

问题描述 投票:0回答:1

我是Python和编码的新手。我想知道有人可以看看我需要更改的内容...

    # Amount of chips player has

    starting_chips = 1000

    print('Player 1 has {}\n'.format(starting_chips))

    # Amount of chips player wants to bet
    try:
        placed_bet = int(input('Place your bet: '))
    except ValueError:
        print("Sorry, I didn't understand that.")
        continue
    print('')

    if placed_bet > starting_chips:
        print("You don't have enough funds")
        continue
    else:
        break

# A deduction from players total chips of the total bet
total_chips = (starting_chips - placed_bet)

losing_total = (starting_chips - placed_bet)

print('You now have: {}\n'.format(total_chips))

#If the player wins the hand
total_chips = ((placed_bet * 2) + starting_chips)

此处链接到整个代码-> https://github.com/Joeet33/CardGame

python python-3.x pygame integer blackjack
1个回答
0
投票

而不是拥有starting_chips,为什么不只使用total_chips并在while循环之前对其进行初始化?最终,您要修改的变量是“玩家拥有多少筹码”。 starting_chips可以用作脚本STARTING_CHIPS = 1000顶部提供的常量,然后将total_chips = STARTING_CHIPS放在while循环的上方。

最终,每次while循环返回顶部时,它将所有值重置为原始值1000。

© www.soinside.com 2019 - 2024. All rights reserved.