Exemplo n.º 1
0
def runGame():
    pygame.init()
    screen = pygame.display.set_mode(size)
    board = Board()

    selected = None
    team = False
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                pos = event.dict['pos']
                
                # convert to i,j
                i,j = pos[0]//dx, pos[1]//dy
                
                # check if this matches an actual piece
                if board.grid[i][j] is not None and board.grid[i][j].color == team:
                    selected = (i,j)
                    
            elif event.type == pygame.MOUSEBUTTONUP and selected is not None:
                pos = event.dict['pos']
                
                # convert to i,j
                i,j = pos[0]//dx, pos[1]//dy
                if board.executeMove(selected, (i,j)):
                    team = not team
                selected = None
            
            drawBoard(screen, team, board, selected)
            pygame.display.flip()
Exemplo n.º 2
0
                elif event.type == pygame.MOUSEBUTTONDOWN:
                    pos = event.dict['pos']
                    
                    # convert to i,j
                    i,j = pos[0]//dx, pos[1]//dy
                    
                    # check if this matches an actual piece
                    if board.grid[i][j] is not None and board.grid[i][j].color == team:
                        selected = (i,j)
                        
                elif event.type == pygame.MOUSEBUTTONUP and selected is not None:
                    pos = event.dict['pos']
                    
                    # convert to i,j
                    i,j = pos[0]//dx, pos[1]//dy
                    if board.executeMove(selected, (i,j)):
                        team = not team
                    selected = None
                    
                    # send the board
                    if args.server:
                        clientsock.send(pickle.dumps((team, board.grid)))
                    elif args.client:
                        sock.send(pickle.dumps((team, board.grid)))

        else: # not your turn
            print("waiting for other turn")
            if args.server:
                try:
                    data = clientsock.recv(BUFSIZE)
                    if not data: