当前位置: 首页>>代码示例>>Python>>正文


Python Display.print_display方法代码示例

本文整理汇总了Python中display.Display.print_display方法的典型用法代码示例。如果您正苦于以下问题:Python Display.print_display方法的具体用法?Python Display.print_display怎么用?Python Display.print_display使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在display.Display的用法示例。


在下文中一共展示了Display.print_display方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Game

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import print_display [as 别名]
class Game():
    def __init__(self):
        self.player = Player()
        self.dealer = Dealer()
        self.display = Display(8)
        self.pot = 0

    def print_display(self, wait=False):
        self.update_display()
        self.display.print_display()
        if wait:
            self.get_continue()

    def update_display(self, hidden=True):
        display_list = ["Dealer:", self.dealer.display_hand(),
                        "Score: " + str(self.dealer.get_hand_value()) +
                        " | Pot: " + str(self.pot),
                        "- "*20, "You:", self.player.display_hand(),
                        "Score: " + str(self.player.get_hand_value()) +
                        " | Money: " + str(self.player.score)]
        for index, string in enumerate(display_list):
            self.display.set_display(string, index)

    def start_round(self):
        self.deck = Deck()
        self.player.start_game()
        self.dealer.start_game()
        self.add_message("Welcome to Blackjack!")
        self.print_display(True)
        self.pot = self.player.bet(self.get_input("bet"))
        self.initial_deal()
        if self.dealer.has_blackjack() and self.player.has_blackjack():
            self.dealer.hidden = False
            self.push("Both dealer and player have Blackjack.")
            return self.get_input("hand")
        elif self.player.has_blackjack():
            self.player_wins("You have Blackjack!")
            return self.get_input("hand")
        elif self.dealer.has_blackjack():
            self.dealer.hidden = False
            self.dealer_wins("Dealer has Blackjack.")
            return self.get_input("hand")
        return self.play()

    def initial_deal(self):
        for i in range(2):
            self.player.add_card(self.deal())
            self.print_display(True)
            self.dealer.add_card(self.deal())
            self.print_display(True)

    def get_input(self, type):
        self.print_display()
        if type == "hand":
            return self.get_hand_input()
        elif type == "bet":
            return self.get_bet_input()
        elif type == "choice":
            return self.get_stand_or_hit()

    def get_hand_input(self):
        if not self.enough_money():
            return False
        while True:
            string = "Do you want to play another hand? (y/n) > "
            value = input(string).lower()
            if value in ("y", "n"):
                return value
            self.add_message("Please enter 'y' or 'n'")
            self.print_display()

    def get_bet_input(self):
        while True:
            bet = input("How much do you want to bet? > ")
            if bet.isdigit() and bet != "0":
                if int(bet) > self.player.score:
                    self.add_message("You don't have that much.")
                    self.print_display()
                    continue
                return int(bet)
            self.add_message("Please enter a positive integer.")
            self.print_display()

    def get_stand_or_hit(self):
        while True:
            string = "Do you want to stand, hit, or double down? > "
            value = input(string).lower()
            if value in ("stand", "hit", "double down"):
                return value
            self.add_message("Please enter 'stand', 'hit', or 'double down'.")
            self.print_display()

    def add_message(self, message):
        self.display.add_messages(message)

    def get_continue(self):
        input("Press Enter to continue.")

    def deal(self):
        return self.deck.draw()
#.........这里部分代码省略.........
开发者ID:pjpassa,项目名称:blackjack,代码行数:103,代码来源:game.py


注:本文中的display.Display.print_display方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。