Beispiel #1
0
def startgame():
    data = GameData()
    screen = pygame.display.set_mode(data.size)
    game = ConnectGame(data, GameRenderer(screen, data))

    game.print_board()
    game.draw()

    pygame.display.update()
    pygame.time.wait(1000)

    # Processes mouse and keyboard events, dispatching events to the event bus.
    # The events are handled by the ConnectGame and GameRenderer classes.
    while not game.game_data.game_over:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                game.quit()

            if event.type == pygame.MOUSEMOTION:
                bus.emit("mouse:hover", game.renderer,
                         MouseHoverEvent(event.pos[0]))

            pygame.display.update()

            if event.type == pygame.MOUSEBUTTONDOWN:
                bus.emit("mouse:click", game, MouseClickEvent(event.pos[0]))

            if event.type == KEYDOWN:
                if event.key == pygame.K_z:
                    mods: int = pygame.key.get_mods()
                    if mods & pygame.KMOD_CTRL:
                        bus.emit("game:undo", game)

            game.update()
            game.draw()
Beispiel #2
0
 def update(self):
     char = self.scrn.getch()
     # was returned as an integer (ASCII); make it a character
     if char != -1:
         if char == curses.KEY_MOUSE:
             #device_id, x, y, z, button = self.system.getmouse()
             ret = curses.getmouse()
             x = ret[1]
             y = ret[2]
             button = ret[4]
             self.evm.Post(MouseClickEvent(button, Vector(x, y)))
         else:
             char = chr(char)
             self.evm.Post(KeyPressEvent(char))
Beispiel #3
0
def start():
    print("+++++++++++++++ start +++++++++++++++++++++++")

    #NOTE: None means Human player
    p1 = None  # red
    p2 = None  # yellow
    if args.player1 != HUMAN:
        # print ("p1 is NOT human")
        p1 = getAgent(args.player1)
    if args.player2 != HUMAN:
        # print ("p2 is NOT human")
        p2 = getAgent(args.player2)

    data = GameData()
    screen = pygame.display.set_mode(data.size)
    game = ConnectGame(data, GameRenderer(screen, data))

    game.print_board()
    game.draw()

    pygame.display.update()
    pygame.time.wait(1000)

    #NOTE: data.turn of 0 == player 1
    #      data.turn of 1 == player 2

    # Processes mouse and keyboard events, dispatching events to the event bus.
    # The events are handled by the ConnectGame and GameRenderer classes.
    p_is_human, p = getPlayer(p1, p2, data)

    #TODO - better way to clean screen?
    bus.emit("mouse:hover", game.renderer, MouseHoverEvent(-50))

    while not game.game_data.game_over:
        pygame.time.wait(10)
        if p_is_human:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    game.quit()

                if event.type == pygame.MOUSEMOTION:
                    bus.emit("mouse:hover", game.renderer,
                             MouseHoverEvent(event.pos[0]))

                pygame.display.update()

                if event.type == pygame.MOUSEBUTTONDOWN:
                    # print("HUMAN: Mouse:",PLAYER(data.turn),p_is_human,p)
                    bus.emit("mouse:click", game,
                             MouseClickEvent(event.pos[0]))
                    p_is_human, p = getPlayer(p1, p2, data)

                # if event.type == KEYDOWN:
                #     if event.key == pygame.K_z:
                #         mods: int = pygame.key.get_mods()
                #         if mods & pygame.KMOD_CTRL:
                #             bus.emit("game:undo", game)
        else:
            #AI
            print("AI:", PLAYER(data.turn), p.get_name())
            game.make_movement(p.get_move(data), p.get_name())
            p_is_human, p = getPlayer(p1, p2, data)
            #keep pygame happy - otherwise freezes
            for event in pygame.event.get():
                pass

        game.update()
        game.draw()
    print("--------------------- GAME OVER ----------------------------")
    pygame.display.update()
Beispiel #4
0
game.print_board()
game.draw()

pygame.display.update()
pygame.time.wait(1000)


# Processes mouse and keyboard events, dispatching events to the event bus.
# The events are handled by the ConnectGame and GameRenderer classes.
while not game.game_data.game_over:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            game.quit()

        if event.type == pygame.MOUSEMOTION:
            bus.emit("mouse:hover", game.renderer, MouseHoverEvent(event.pos[0]))

        pygame.display.update()

        if event.type == pygame.MOUSEBUTTONDOWN:
            bus.emit("mouse:click", game, MouseClickEvent(event.pos[0]))

        if event.type == KEYDOWN:
            if event.key == pygame.K_z:
                mods: int = pygame.key.get_mods()
                if mods & pygame.KMOD_CTRL:
                    bus.emit("game:undo", game)

        game.update()
        game.draw()