Exemplo n.º 1
0
 def __init__(self, map, *players):
     self.window = Window()
     self.event_handler = EventHandlerKey()
     self.players = players
     self.map = map
     self.dest = Dest()
     self.server = None
Exemplo n.º 2
0
class Match:
    def __init__(self, map, *players):
        self.window = Window()
        self.event_handler = EventHandlerKey()
        self.players = players
        self.map = map
        self.dest = Dest()
        self.server = None

    def set_server(self, server):
        self.server = server

    def draw(self):
        self.window.draw()
        self.map.draw(self.window.screen)
        for player in self.players:
            player.draw(self.window.screen)
        self.current_player.draw(self.window.screen, True)
        self.dest.draw(self.window.screen, self.current_player.get_next_pos())
        pygame.display.flip()
        if self.server:
            self.server.send_screen(self.window.screen)

    def start(self):
        if self.server:
            self.server.send_start()
        self.running = True
        self.turn = -1
        self.change_turn()
        self.draw()
        self.loop()
        if self.server:
            self.server.send_end()

    def change_turn(self):
        self.turn = (self.turn + 1) % len(self.players)
        self.current_player = self.players[self.turn]

    def events(self):
        if self.server:
            v = self.server.get_event()
        else:
            v = self.event_handler.start()
        if v == "quit":
            self.running = False
        self.last_choice = v

    def update(self):
        if self.last_choice and not self.last_choice == "quit":
            self.current_player.set_dest(self.last_choice)
            self.change_turn()

    def loop(self):
        while self.running:
            self.events()
            self.update()
            self.draw()
Exemplo n.º 3
0
class Bridge:
    def __init__(self):
        self.src = ''
        self.weight = 0.0
        self.to = Dest()
    def parsing(self,value):
        if 'src' in value:
            self.src = value['src']
        if 'weight' in value:
            self.weight = value['weight']
        if 'to' in value:
            self.to.parsing(value['to'])
Exemplo n.º 4
0
class Bridge:
    def __init__(self):
        self.src = ''
        self.weight = 0.0
        self.to = Dest()

    def parsing(self, value):
        if 'src' in value:
            self.src = value['src']
        if 'weight' in value:
            self.weight = value['weight']
        if 'to' in value:
            self.to.parsing(value['to'])
Exemplo n.º 5
0
 def __init__(self):
     self.src = ''
     self.weight = 0.0
     self.to = Dest()
Exemplo n.º 6
0
 def __init__(self):
     self.src = ''
     self.weight = 0.0
     self.to = Dest()
Exemplo n.º 7
0
        pygame.display.set_caption(conf.TITLE)

        # grid
        self.grid = pygame.Surface(conf.SIZE)
        self.grid.fill(conf.COLOR_KEY)
        for x in range(0,conf.WIDTH+1,conf.TILE):
            pygame.draw.line(self.grid,conf.COLOR_GRID,(x,0),(x,conf.HEIGHT),1)
        for y in range(0,conf.HEIGHT+1,conf.TILE):
            pygame.draw.line(self.grid,conf.COLOR_GRID,(0,y),(conf.WIDTH,y),1)
        self.grid.set_colorkey(conf.COLOR_KEY)

    def draw(self):
        self.screen.fill(conf.COLOR_BGROUND)
        self.screen.blit(self.grid, (0,0))
        pygame.display.flip()

    def flip(self):
        pygame.display.flip()

if __name__ == "__main__":
    # test
    w = Window()
    w.draw()
    d = Dest(5,5)
    d.draw(w.screen)
    pygame.display.flip()


    import time
    time.sleep(2)