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


Python Board.update方法代码示例

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


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

示例1: Game

# 需要导入模块: import Board [as 别名]
# 或者: from Board import update [as 别名]
class Game(object):
    def __init__(self):
        self.board = Board()
        self.player_1 = Player('x', self.board)
        self.player_2 = Player('o', self.board)
        self.game_over = False
        self.current_player = self.player_1

    def play(self):
        while not self.game_over:
            self.take_turn()
            if self.game_over: break
            self.switch_player()
        self.board.update()
        if self.player_1.winner:
            print "Player 1 wins!"
            return
        if self.player_2.winner:
            print "Player 2 wins!"
            return
        print "No winner."
        return

    def take_turn(self):
        self.board.update()
        if self.current_player == self.player_1:
            print "Player 1's turn"
        else:
            print "Player 2's turn"
        self.current_player.make_move()
        self.board.check_full()
        if self.board.connect_four():
            self.current_player.winner = True
            self.game_over = True
        if self.board.full:
            self.game_over = True


    def switch_player(self):
        if self.current_player == self.player_1:
            self.current_player = self.player_2
        else:
            self.current_player = self.player_1
开发者ID:timsunpang,项目名称:Connect4,代码行数:45,代码来源:Game.py

示例2: Stratego

# 需要导入模块: import Board [as 别名]
# 或者: from Board import update [as 别名]

#.........这里部分代码省略.........
        if((self.active_team.locked)and(self.dormant_team.locked)):
            self.phase += 1
            self.active_team.move_made = False
            self.dormant_team.move_made = False
            self.bars.remove(self.bars[len(self.bars)-1])
            self.buttons = []

    def game_phase(self):
        if(self.phase == None):
            events = [self.make_piece, self.set_team, self.preset]
            temp = S_Piece_set(self.screen, self.size, events)
            for t in temp[0]:
                self.bars.append(t)
            for t in temp[1]:
                self.buttons.append(t)
            self.phase = 0
            self.doors = grande_door(self.screen, self.size, self.setit)
            
        if(self.phase == 0):
            for t in self.teamA.troops:
                if(t.loc != None):
                    if(t.loc[1] > 3):
                        self.teamA.troops.remove(t)
            for t in self.teamB.troops:
                if(t.loc != None):
                    if(t.loc[1] < 6):
                        self.teamB.troops.remove(t)

        if(self.phase == 1):
            if(self.dormant_team.get_amount(11) == 0):
                self.win(self.active_team.user)
            elif(self.active_team.get_amount(11) == 0):
                self.win(self.dormant_team.user)
            elif(self.active_team.move_made):
                self.active_team.move_made = False
                self.doors.close()
                #self.swap_teams()
            
            
                
    def conflict(self):
        for a in self.teamA.troops:
            b = self.teamB.get_piece(a.loc)
            if(b != None):
                a.reveal()
                b.reveal()
                
                victor = None
                if(a.rank > b.rank):
                    t_list = (b, a)
                else:
                    t_list = (a, b)
                
                if((t_list[0].rank == 0)and(t_list[1].rank != 3)):
                    victor = t_list[0]
                elif(t_list[1].rank == 11):
                    victor = t_list[0]
                elif((t_list[0].rank == 1)and(t_list[1].rank == 10)):
                    victor = t_list[0]
                elif(t_list[0].rank != t_list[1].rank):
                    victor = t_list[1]

                if(victor == a):
                    self.teamB.troops.remove(b)
                elif(victor == b):
                    self.teamA.troops.remove(a)
                else:
                    self.teamA.troops.remove(a)
                    self.teamB.troops.remove(b)

    def update(self, interact):
        mouse_pos = interact[7]
        click = interact[0]
        self.board.update(interact)
        self.active_team.update(interact, self.board)
        self.game_phase()
        self.conflict()

        for b in self.buttons:
            b.update(interact)
        for b in self.bars:
            b.update(interact)

        self.doors.update(interact)

    def blitme(self):
        self.board.blitme()
        self.dormant_team.blitme(self.board)
        self.active_team.blitme(self.board)
        
        for b in self.buttons:
            b.blitme()
        for b in self.bars:
            b.blitme()

        if(self.active_team.dragged != None):
            self.active_team.dragged.blitme(self.board, self.active_team.color)

        if((self.doors.right.move)or(self.doors.is_closed())):
            self.doors.blitme()
开发者ID:Dirker27,项目名称:GamesBrowser,代码行数:104,代码来源:Game.py

示例3: Checkers

# 需要导入模块: import Board [as 别名]
# 或者: from Board import update [as 别名]
class Checkers(object):
    def __init__(self, screen, size, users, end):
        self.screen = screen
        self.size = size
        self.users = users
        self.teamA = Check_Team(users[0])
        self.teamB = Check_Team(users[1])
        self.active_team = self.teamA
        self.dormant_team = self.teamB
        self.active_team.set_check(self.screen, False, self.dormant_team)
        self.dormant_team.set_check(self.screen, True, self.active_team)
        self.active_team.active()
        self.dormant_team.dormant()
        self.winner = None
        self.phase = None
        self.width = size[0]
        self.height = size[1]
        self.board = Board(self.screen, (self.width/2, self.height/2), "Checkers")
        self.bars = []
        self.buttons = []
        self.end = end

        self.bars.append(Acc_Bar(self.screen, (self.width - 150, self.height - 75), self.active_team.user))

    def swap_teams(self):
        temp = self.active_team
        self.active_team = self.dormant_team
        self.dormant_team = temp

        self.active_team.active()
        self.dormant_team.dormant()

        self.disp_user()

    def disp_user(self):
        x = 1
        num = 1
        for u in self.users:
            if(u == self.active_team.user):
                num = x
            x += 1

        a = 0
        b = 0
        if((num == 2)or(num == 3)):
            a = 150
        else:
            a = self.width - 150

        if((num == 2)or(num == 4)):
            b = 95
        else:
            b = self.height - 75

        self.bars[0] = Acc_Bar(self.screen, (a,b), self.active_team.user)

    def win(self, winner):
        for u in self.users:
            if(u == winner):
                u.win()
            else:
                u.lose()
                winner.inventory.append(u.dog_tag)
        self.end()

    def update(self, interact):
        mouse_pos = interact[7]
        click = interact[0]
        self.board.update(interact)
        self.active_team.update(interact, self.board)
        if(self.active_team.move_made):
            self.active_team.move_made = False
            self.swap_teams()

        for b in self.buttons:
            b.update(interact)
        for b in self.bars:
            b.update(interact)

        if(len(self.active_team.troops) == 0):
            self.win(self.dormant_team.user)
        elif(len(self.dormant_team.troops) == 0):
            self.win(self.active_team.user)

    def blitme(self):
        self.board.blitme()
        self.dormant_team.blitme(self.board)
        
        for b in self.buttons:
            b.blitme()
        for b in self.bars:
            b.blitme()

        self.active_team.blitme(self.board)
开发者ID:Dirker27,项目名称:GamesBrowser,代码行数:96,代码来源:Game.py

示例4: Ground_War

# 需要导入模块: import Board [as 别名]
# 或者: from Board import update [as 别名]

#.........这里部分代码省略.........
                    if(e.equip == 3):
                        self.active_team.equipment.remove(e)
                        d.equipment.remove(b)
                    if(e.equip == 0):
                        self.active_team.equipment.remove(e)
                        d.equipment.remove(b)   
     
        for a in self.active_team.troops:
            for d in self.dormant_teams:
                b = d.get_piece(a.loc)
                if(b != None):
                    a.reveal()
                    b.reveal()
                    victor = None

                    if(a.rank > b.rank):
                        e = d.get_equip(b.loc)
                        if((e != None)and(e.equip == 2)):
                            r = b.rank + 3
                            if(a.rank < r):
                                victor = b
                            else:
                                victor = a
                        else:
                            victor = a
                            
                    elif(a.rank < b.rank):
                        if(b.rank == 11):
                            victor = a
                        else:
                            victor = b

                    if(a.rank == 1):
                        if(b.rank > 4):
                            victor = a
                            
                    if(victor == a):
                        d.troops.remove(b)
                        if(b.rank == 11):
                            self.capture(self.active_team, d)
                    elif(victor == b):
                        self.active_team.troops.remove(a)
                    else:
                        self.active_team.troops.remove(a)
                        d.troops.remove(b)

                e = d.get_equip(a.loc)
                if(e != None):
                    a.reveal()
                    e.reveal()
                    if(e.equip == 0):
                        self.active_team.troops.remove(a)
                        d.equipment.remove(e)

    def win(self):
        winner = self.teams[0].user

        for u in self.users:
            if(u == winner):
                u.win()
            else:
                u.lose()
                winner.inventory.append(u.dog_tag)

    def update(self, interact):
        mouse_pos = interact[7]
        click = interact[0]
        right_click = interact[1]
        mid_click = interact[2]

        for b in self.buttons:
            b.update(interact)
        for b in self.bars:
            b.update(interact)

        self.board.update(interact)
        if(self.board_drag == False):
            self.active_team.update(interact, self.board)
            self.conflict()
            self.game_phase()
            self.deploy_equip()
        self.move_board(right_click, mouse_pos)
        self.doors.update(interact)

    def blitme(self):
        self.board.blitme()
        for d in self.dormant_teams:
            d.blitme(self.board)
        self.active_team.blitme(self.board)

        for b in self.buttons:
            b.blitme()
        for b in self.bars:
            b.blitme()            

        if(self.active_team.dragged != None):
            self.active_team.dragged.blitme(self.board, self.active_team.color)

        if((self.doors.right.move)or(self.doors.is_closed())):
            self.doors.blitme()
开发者ID:Dirker27,项目名称:GamesBrowser,代码行数:104,代码来源:Game.py

示例5: PlayMode

# 需要导入模块: import Board [as 别名]
# 或者: from Board import update [as 别名]
class PlayMode(GameMode):
    background = pygame.Surface(size)
    attack_sounds = []
    
    def __init__(self):
        GameMode.__init__(self)
        self.eason = Eason(pos)
        PlayMode.background.convert()
        for i in range(4):
            name = 'punch' + str(i) + '.wav'
            PlayMode.attack_sounds.append(load_sound(name))
            PlayMode.attack_sounds[i].set_volume(sound_volume)
        self.so_far = 0
        self.board = Board()
        self.eason.run()
        
    def enter(self):
        ## initializations when entering this mode
        pygame.mixer.music.load(os.path.join(kSrcDir, dirBGM, "beethoven_virus.ogg"))
        pygame.mixer.music.set_volume(bgm_volume)
        pygame.mixer.music.play(-1)
        pygame.mouse.set_visible(False)
        PlayMode.background.fill((255, 255, 255))
        self.eason.reset()
        floor = Floor((0, Y + 80), (700, 2))
        self.floors = [floor]
        self.joes = []
        self.eason.run()
        self.so_far = 0
        self.board.reset()
        self.eason.update()
        
    def exit(self):
        ## clean-ups when exiting
        pygame.mixer.music.stop()
        self.floors = []
        self.joes = []
        pygame.mouse.set_visible(True)
    
    def key_down(self, event):
        ## check input events
        if event.key == K_ESCAPE:
            self.switch_to_mode('start_mode')
        keys = pygame.key.get_pressed()
        if keys[K_SPACE]:
            self.eason.jump()
        if keys[K_a]:
            self.eason.attack()
        if keys[K_k]:
            self.eason.down()
    
    def add_new_floor(self):
        last_floor = self.floors[len(self.floors) - 1]
        dist = width - last_floor.x - last_floor.width
        ## set probabilities of the appearance of floors and joes
        P = 0
        Q = 3 * self.eason.level + 20
        if dist > 320:
            P = 100
        elif dist > 200:
            P = 50
        elif dist > 100:
            P = 15
        elif dist > 50:
            P = 5
        if randint(1, 100) <= P:
            new_floor = Floor((width + 1, Y + 80 + randint(-60, 60)), \
                              (randint(50, 1500), 2))
            self.floors.append(new_floor)
            if new_floor.width > 640:
                Q = 100
            if randint(1, 100) <= Q and new_floor.width > 80:
                self.joes.append(Stupid((new_floor.x + \
                                        randint(0, new_floor.width - 80), \
                                        new_floor.y - 80)))
    
    ## supporting method
    def out_of_sight(self):
        if self.floors[0].out_of_sight():
            tmp = self.floors.pop(0)
            del tmp
        if self.joes:
            if self.joes[0].outOfSight():
                tmp = self.joes.pop(0)
                del tmp
    
    ## set the accelerate if Eason is not stepping on any floors
    def fall(self):
        found = False
        for i in self.floors:
            if self.eason.stepOn(i):
                self.eason.stand()
                self.eason.fixPos(i.y)
                if (not self.eason.acting()) and (not self.eason.isDead()):
                    self.eason.run()
                self.eason.resetJump()
                found = True
                break
        if not found:
            self.eason.fall()
#.........这里部分代码省略.........
开发者ID:jtdressel,项目名称:RunEasonRun,代码行数:103,代码来源:PlayMode.py


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