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


Python Board.display_tiles方法代码示例

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


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

示例1: set_new_game_id

# 需要导入模块: import Board [as 别名]
# 或者: from Board import display_tiles [as 别名]
class Game:
    def set_new_game_id(self):        
        previous_ids = []
        for filename in os.listdir("games"):
            previous_ids.append(int(filename))
        if len(previous_ids) == 0:
            self.game_id = 1
        else:
            self.game_id = max(previous_ids) + 1

    def is_game_in_progress(gid):
        for filename in os.listdir("games"):
            if str(gid) == filename:
                return True
        return False

    def start_new_game(self,player):
        self.set_new_game_id()

        # Create the board
        self.board = Board(400,400,player,Player("Player 2",""))
        self.board.refill(player)
        self.board.display_tiles()

        # Set up the rest of the current game state
        self.current_player = player # Default to the first person
        self.prev_result = None        

    def run(self):
        self.players = []
        # Read the players from the database
        self.db = Database("db.txt")
        self.db.read()
        # From our tic-tac-toe game, we need to have the user login
        start_screen = StartScreen()
        while True:
            result = start_screen.login(self.db)
            if result == "new":
                self.start_new_game(start_screen.getPlayer())
                break
            elif result == "quit": # Quit was hit, so end the game
                return
            else: # Must be a game id
                self.load(result,start_screen.getPlayer())
        
        while True:
            self.result = self.board.take_turn(self.current_player)
            if self.result == "pass" and self.prev_result == "pass":
                break # Show result
            if self.result == "quit":
                return
            if self.result == "submit":
                self.current_player.refill()
                
            self.prev_result = self.result

    def load(self,game_id,player):
        return
开发者ID:itsallvoodoo,项目名称:csci-school,代码行数:60,代码来源:Game.py

示例2: set_new_game_id

# 需要导入模块: import Board [as 别名]
# 或者: from Board import display_tiles [as 别名]
class Game:
    def set_new_game_id(self): # adds current game to directory of game_ids       
        previous_ids = []
        for filename in os.listdir("games"):
            previous_ids.append(int(filename))
        if len(previous_ids) == 0:
            self.game_id = 1
        else:
            self.game_id = max(previous_ids) + 1

    def start_new_game(self,player):
        self.set_new_game_id()

        # Create the board
        player2 = Player("Player 2","")
        self.board = Board(400,400,player,player2,self.game_id)
        self.board.refill(player)
        self.board.display_tiles()

        # Set up the rest of the current game state
        self.current_player = player # Default to the first person
        self.players.append(player) # Add the first player to the list of players
        self.prev_result = None

    def run(self):
        self.players = []
        # Read the players from the database
        self.db = Database("db.txt")
        self.db.read()
        # From our tic-tac-toe game, we need to have the user login
        start_screen = StartScreen()
        while True:
            result = start_screen.login(self.db)
            if result == "new":
                self.start_new_game(start_screen.getPlayer())
                break
            elif result == "quit": # Quit was hit, so end the game
                return
            else: # Must be a game id
                # TODO
                # First start a new game. This will create window that we can adjust
                # Then call the load function, passing in the game id that was entered and
                # the player that logged in using the start_screen
                break

        # TODO: Save the game (should be one line)
        
        while True:
            self.result = self.board.take_turn(self.current_player)
            if self.result == "pass" and self.prev_result == "pass":
                break # Show result
            if self.result == "quit":
                return
            if self.result == "submit":
                self.board.refill(self.current_player)
                self.board.update_screen()
            elif self.result == "refresh":
                # TODO: Call the load function with the correct player being shown for this screen
                continue # A refresh was issued, that does not constitute a turn, so continue

            #TODO: Change players to the other player
            
            #TODO: Save the same
                
            self.prev_result = self.result

    def save(self):
        outfile = open("games/"+str(self.game_id),"wb")
        game_state = {};
        game_state['db'] = self.db
        game_state['players'] = self.players
        game_state['board'] = self.board
        game_state['prev_result'] = self.prev_result
        game_state['current_player'] = self.current_player
        game_state['game_id'] = self.game_id
        outfile.write(pickle.dumps(game_state))
        outfile.close()

    def load(self,game_id,player):
        self.game_id = game_id
        infile = open("games/"+str(game_id),'rb')
        game_state_pickled = infile.read()
        infile.close()
        game_state = pickle.loads(game_state_pickled)
        # Make sure there is a spot for this player or they are already part of the game
        joined = False
        for i in range(len(game_state['players'])):
            if player.getName() == game_state['players'][i].getName():
                joined = True
                player = game_state['players'][i] # Set to the actual player
            else:
                player2 = game_state['players'][i] # Other player
            
        if not joined and len(game_state['players']) == 2: # Cannot join
            return False

        # Now load up the game
        self.board.undraw()
        self.players = game_state['players']
        if not joined:
#.........这里部分代码省略.........
开发者ID:itsallvoodoo,项目名称:csci-school,代码行数:103,代码来源:Game.py


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