小编mar*_*ria的帖子

如何摆脱2个循环?(蟒蛇)

必须有一种更好的方法来执行此操作...有什么想法吗?这是CS1的基本二十一点游戏。

2件困扰我的主要事情:

  1. 如何两次退出循环?例如 发牌人赢了,然后问“保持还是击中?”,因为它仍然在玩家的回合/循环中。
  2. 休息时间似乎很残酷。复制粘贴的代码太多了。

谢谢!任何帮助表示赞赏。

import random
import sys
# game, hand, deck


class Deck:
    theDeck = []
    card = 0

    def createDeck(self):
        for x in range(2, 15):
            for y in range(1, 5):
                self.theDeck.append(x)

    def extractCard(self):
        card = self.theDeck.pop(random.randrange(1, len(self.theDeck) - 1))
        return card


class Game:
    dealerTotal = [0, 0]
    playerTotal = 0
    deck = Deck()
    deck.createDeck()

    def reset(self):
        self.dealerTotal = [0, 0]
        self.playerTotal = 0

    def dealerEnd(self):
        if self.dealerTotal[0] == 21 or self.dealerTotal[1] == 21:
            print("BLACKJACK! Game over.\n\nDEALER'S …
Run Code Online (Sandbox Code Playgroud)

python methods loops break blackjack

5
推荐指数
1
解决办法
707
查看次数

标签 统计

blackjack ×1

break ×1

loops ×1

methods ×1

python ×1