Beispiel #1
0
def get_rect_from_player(player, rectList):
    # Loop until the user clicks on a vertex
    validClick = False
    while not validClick:
        # Make sure no other events are on the queue
        pygame.event.clear()
        # Prompt the user for a click and wait for two events
        if player:
            print("{} please click an option.".format(player.name))
        else:
            print("Please click an option.")
        chosenRect = None
        eventA = pygame.event.wait()
        eventB = pygame.event.wait()
        # If the next two events are the mouse being pressed down and then released, move forward
        if eventA.type == pygame.MOUSEBUTTONDOWN and eventB.type == pygame.MOUSEBUTTONUP:
            posA = eventA.__dict__['pos']
            posB = eventB.__dict__['pos']
            # If the mouse actions (pressed down, released) were no more than 10 pixels apart, move forward
            if gf.pp_distance(posA, posB) < 10:
                # Loop through the rects to see if the click occurred inside one
                for rect in rectList:
                    # If both mouse actions occurred inside the current hex, move forward
                    if gf.is_within_rect(rect, posA) and gf.is_within_rect(
                            rect, posB):
                        # Record the rect, switch the boolean to end the while loop, and break the rect loop
                        chosenRect = rect
                        validClick = True
                        break
                if not validClick:
                    print(
                        "That click was not inside a rect. Please try again.")
            else:
                print("The mouse moved while pressed down. Please try again.")
    return chosenRect
Beispiel #2
0
def get_rect_from_player(player, rectList):
    # Loop until the user clicks on a vertex
    validClick = False
    while not validClick:
        # Make sure no other events are on the queue
        pygame.event.clear()
        # Prompt the user for a click and wait for two events
        if player:
            print("{} please click an option.".format(player.name))
        else:
            print("Please click an option.")
        chosenRect = None
        eventA = pygame.event.wait()
        eventB = pygame.event.wait()
        # If the next two events are the mouse being pressed down and then released, move forward
        if eventA.type == pygame.MOUSEBUTTONDOWN and eventB.type == pygame.MOUSEBUTTONUP:
            posA = eventA.__dict__['pos']
            posB = eventB.__dict__['pos']
            # If the mouse actions (pressed down, released) were no more than 10 pixels apart, move forward
            if gf.pp_distance(posA, posB) < 10:
                # Loop through the rects to see if the click occurred inside one
                for rect in rectList:
                    # If both mouse actions occurred inside the current hex, move forward
                    if gf.is_within_rect(rect, posA) and gf.is_within_rect(rect, posB):
                        # Record the rect, switch the boolean to end the while loop, and break the rect loop
                        chosenRect = rect
                        validClick = True
                        break
                if not validClick:
                    print("That click was not inside a rect. Please try again.")
            else:
                print("The mouse moved while pressed down. Please try again.")
    return chosenRect
Beispiel #3
0
def get_hex_from_player(player, hexList, playerKey):
    # Check if the player is an AI or human
    if player.isAI:
        pass
    else:
        # Loop until the user clicks on a vertex
        validClick = False
        while not validClick:
            # Make sure no other events are on the queue
            pygame.event.clear()
            # Prompt the user for a click and wait for two events
            print(
                "{} please click a hex. Or click the Player Key to select nothing."
                .format(player.name))
            chosenHex = None
            eventA = pygame.event.wait()
            eventB = pygame.event.wait()
            # If the next two events are the mouse being pressed down and then released, move forward
            if eventA.type == pygame.MOUSEBUTTONDOWN and eventB.type == pygame.MOUSEBUTTONUP:
                posA = eventA.__dict__['pos']
                posB = eventB.__dict__['pos']
                # If the mouse actions (pressed down, released) were no more than 10 pixels apart, move forward
                if gf.pp_distance(posA, posB) < 10:
                    # If the click was inside the Player Key, return to the previous menu without a selection
                    if gf.is_within_rect(playerKey.box,
                                         posA) and gf.is_within_rect(
                                             playerKey.box, posB):
                        chosenHex = None
                        validClick = True
                        print("{} did not choose a hex.".format(player.name))
                    else:
                        # Loop through the hexes to see if the click occurred inside one
                        for hexTile in hexList:
                            # If both mouse actions occurred inside the current hex, move forward
                            if gf.is_within_hex(hexTile,
                                                posA) and gf.is_within_hex(
                                                    hexTile, posB):
                                # Record the hex, switch the boolean to end the while loop, and break the hex loop
                                chosenHex = hexTile
                                validClick = True
                                break
                        if not validClick:
                            print(
                                "That click was not inside a hex. Please try again."
                            )
                else:
                    print(
                        "The mouse moved while pressed down. Please try again."
                    )
        return chosenHex
Beispiel #4
0
def get_hex_from_player(player, hexList, playerKey):
    # Check if the player is an AI or human
    if player.isAI:
        pass
    else:
        # Loop until the user clicks on a vertex
        validClick = False
        while not validClick:
            # Make sure no other events are on the queue
            pygame.event.clear()
            # Prompt the user for a click and wait for two events
            print("{} please click a hex. Or click the Player Key to select nothing.".format(player.name))
            chosenHex = None
            eventA = pygame.event.wait()
            eventB = pygame.event.wait()
            # If the next two events are the mouse being pressed down and then released, move forward
            if eventA.type == pygame.MOUSEBUTTONDOWN and eventB.type == pygame.MOUSEBUTTONUP:
                posA = eventA.__dict__['pos']
                posB = eventB.__dict__['pos']
                # If the mouse actions (pressed down, released) were no more than 10 pixels apart, move forward
                if gf.pp_distance(posA, posB) < 10:
                    # If the click was inside the Player Key, return to the previous menu without a selection
                    if gf.is_within_rect(playerKey.box, posA) and gf.is_within_rect(playerKey.box, posB):
                        chosenHex = None
                        validClick = True
                        print("{} did not choose a hex.".format(player.name))
                    else:
                        # Loop through the hexes to see if the click occurred inside one
                        for hexTile in hexList:
                            # If both mouse actions occurred inside the current hex, move forward
                            if gf.is_within_hex(hexTile, posA) and gf.is_within_hex(hexTile, posB):
                                # Record the hex, switch the boolean to end the while loop, and break the hex loop
                                chosenHex = hexTile
                                validClick = True
                                break
                        if not validClick:
                            print("That click was not inside a hex. Please try again.")
                else:
                    print("The mouse moved while pressed down. Please try again.")
        return chosenHex