當前位置: 首頁>>代碼示例>>Python>>正文


Python Bag.num_letters_left方法代碼示例

本文整理匯總了Python中bag.Bag.num_letters_left方法的典型用法代碼示例。如果您正苦於以下問題:Python Bag.num_letters_left方法的具體用法?Python Bag.num_letters_left怎麽用?Python Bag.num_letters_left使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bag.Bag的用法示例。


在下文中一共展示了Bag.num_letters_left方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from bag import Bag [as 別名]
# 或者: from bag.Bag import num_letters_left [as 別名]
class Game:
    """Game where everything comes together"""

    def __init__(self, players, computers, dictionary='sowpods.txt'):
        """Sets up initial game state with player names given"""

        self.bag = Bag()
        self.board = Board()
        self.player_order = players + sorted(computers.keys())
        self.computers = computers
        self.players = {}
        for player in players:           
            self.players[player] = Player(player,self)
        for computer in computers:
            self.players[computer] = AI(computer, self, computers[computer])
        self.turn = 0
        self.played = False
        self.dictionary = Dictionary(dictionary)

    def display(self, compact=True):
        """displays home screen with board and player scores"""

        if compact:
            self.board.display_compact()
        else:
            self.board.display()
        for player in self.players.values():
            player.display()
        print ''
        print "Letters left: ", self.bag.num_letters_left()
        print ''
        sys.stdout.flush()

    def display_rack(self, player):
        """displays the rack of player"""

        self.players[player].display_rack()

    def display_player_screen(self, compact=True):
        """Displays the screen each player will see when it is their turn"""

        self.display(compact)
        curr_player = self.player_order[self.turn % len(self.player_order)]
        raw_input(curr_player + ": Press enter to see your letters")
        print '\n' + curr_player + "'s letters:"
        self.display_rack(curr_player)
        
    def save_game(self):
        '''Save the game in its current to a file'''

        # save bag, board, and player_order
        with open('bag.data', 'wb') as save_file:
            pickle.dump(self.bag(), save_file)
        with open('board.data', 'wb') as save_file:
            pickle.dump(self.board(), save_file)
        with open('player_order.data', 'wb') as save_file:
            pickle.dump(self.player_order, save_file)

        # save players
        numAI = 1
        for index, player in enumerate(self.players):
            if self.players[player].isAI:
                player_data = [player, \
                               self.players[player].rack(), \
                               self.players[player].score, \
                               self.computers[player]]
                with open('AI_' + str(numAI) + '.data', 'wb') as save_file:
                    pickle.dump(player_data, save_file)
                numAI += 1
            else:
                player_data = [player, \
                               self.players[player].rack(), \
                               self.players[player].score]
                with open('player' + str(index + 1) + '.data', 'wb') as save_file:
                    pickle.dump(player_data, save_file)

        # save turn, num_players, num_computers            
        with open('game_info.data', 'wb') as save_file:
            num_real_players = len(self.players) - len(self.computers)
            pickle.dump([self.turn, num_real_players, len(self.computers)], \
                         save_file)
開發者ID:merlinpatt,項目名稱:scrabble,代碼行數:83,代碼來源:gameWithTimeOut.py


注:本文中的bag.Bag.num_letters_left方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。