Ejemplo n.º 1
0
def manuallyPlaceShips():
    currentlyPlacedShips = {}
    allShipsPlaced = False
    validMinCoordinate = (SIZE + 2) - SIZE
    validMaxCoordinate = (SIZE + 2) 
    newCoordList = []

    while allShipsPlaced == False:
        newCoord = input("Please enter a coordinate equal to or between ({minCoord}, {minCoord}) and ({maxCoord}, {maxCoord}): ".format(minCoord = str(validMinCoordinate), maxCoord = str(validMaxCoordinate)))
        try:
            newCoord = newCoord.split(",")
            checkIfValidCoord()
        except:
            messages.error_message("That is not a valid coordinate.")
Ejemplo n.º 2
0
def displaySetupGameMenu():
    print("\n  [bold green]1.[/bold green][underline] Manually place ships.[/underline]")
    print("  [bold green]2.[/bold green][underline] Generate ship positions.[/underline]")
    setupOption = input("\nChoose an option (1 or 2): ")
    if setupOption.isdigit():   
        if int(setupOption) == 1:
            manuallyPlaceShips()
        elif int(setupOption) == 2:
            automaticallyPlaceShips()
        else:
            messages.error_message("Please enter a valid number. 1 or 2: ")
            displaySetupGameMenu() 
    else:
        messages.error_message("Please enter a valid number. 1 or 2: ")
        displaySetupGameMenu()
Ejemplo n.º 3
0
def changeDifficulty():
    global DIFFICULTY
    difficultyInput = input(
        "\nWhat would you like to set the difficulty to? (Enter a number 1-3): "
    )
    if difficultyInput.isdigit():
        if (int(difficultyInput) < 1) or (int(difficultyInput) > 3):
            messages.error_message("Please enter a number between 1-3")
            changeDifficulty()
        else:
            DIFFICULTY = int(difficultyInput)
            messages.confirmation_message("Fantastic! Difficulty level " +
                                          str(DIFFICULTY) + " has been set")
            gameMenu(MIN_BOARD_SIZE, SIZE, SHIPS, DIFFICULTY)
    else:
        messages.error_message("Please enter a valid number!")
        changeDifficulty()
Ejemplo n.º 4
0
def changeBoardSize():
    global SIZE
    boardSizeInput = input(
        "\nWhat would you like the size of the board to be? ")
    if boardSizeInput.isdigit():
        if int(boardSizeInput) < MIN_BOARD_SIZE:
            messages.error_message(
                "Please enter a number greater than or equal to " +
                str(MIN_BOARD_SIZE))
            changeBoardSize()
        else:
            SIZE = int(boardSizeInput)
            messages.confirmation_message(
                "Fantastic! Your new board size is: " + str(SIZE))
            gameMenu(MIN_BOARD_SIZE, SIZE, SHIPS, DIFFICULTY)
    else:
        messages.error_message("Please enter a valid number!")
        changeBoardSize()
Ejemplo n.º 5
0
def changeShipLimit():
    global SHIPS
    shipLimitInput = input(
        "\nHow many playable ships would you like access too? (Enter a number between 5-7): "
    )
    if shipLimitInput.isdigit():
        if (int(shipLimitInput) < 5) or (int(shipLimitInput) > 7):
            messages.error_message("Please enter a number between 5-7")
            changeShipLimit()
        else:
            SHIPS = int(shipLimitInput)
            messages.confirmation_message("Fantastic! A total of " +
                                          str(SHIPS) +
                                          " are available to play with")
            gameMenu(MIN_BOARD_SIZE, SIZE, SHIPS, DIFFICULTY)
    else:
        messages.error_message("Please enter a valid number!")
        changeShipLimit()
Ejemplo n.º 6
0
def gameSettingEditor(settingToChangeInStringFormat):
    # this function changes game settings -- usage : gameMenu()
    # 
    global SIZE
    global DIFFICULTY
    global SHIPS

    def localMessageDict(updatedSettingsValue):
        if updatedSettingsValue == "SIZE":
            messageList = ["\n\tWhat would you like the size of the board to be? ", "Please enter a number greater than or equal to " + str(MIN_BOARD_SIZE), "Fantastic! Your new board size is: " + str(SIZE)]
        if updatedSettingsValue == "DIFFICULTY":
            messageList = ["\nWhat would you like to set the difficulty to? (Enter a number 1-3): ", "Please enter a number between 1-3", "Fantastic! Difficulty level " + str(DIFFICULTY) + " has been set"]
        if updatedSettingsValue == "SHIPS":
            messageList = ["\nHow many playable ships would you like access too? (Enter a number between 5-7): ", "Please enter a number between 5-7", "Fantastic! A total of " + str(SHIPS) + " are available to play with"]
        
        return messageList

    this = settingToChangeInStringFormat

    newSettingsInput = input(localMessageDict(this)[0])

    localIfStatements = {
        'SIZE_IF': (int(newSettingsInput) < MIN_BOARD_SIZE) or (int(newSettingsInput) > MAX_BOARD_SIZE),
        'DIFFICULTY_IF': (int(newSettingsInput) < MIN_DIFFICULTY) or (int(newSettingsInput) > MAX_DIFFICULTY),
        'SHIPS_IF': (int(newSettingsInput) < MIN_SHIPS) or (int(newSettingsInput) > MAX_SHIPS)
    }

    if newSettingsInput.isdigit() == False:
        messages.error_message("Please enter a valid number!")
        gameSettingEditor(this)
    else:
        if (localIfStatements[this + "_IF"]) == False: # *the input was possible
            globals()[this] = int(newSettingsInput)
            loading(3)
            messages.confirmation_message(localMessageDict(this)[2])
            gameMenu(MIN_BOARD_SIZE, SIZE, SHIPS, DIFFICULTY)
        else:
            messages.error_message(localMessageDict(this)[1])
            gameSettingEditor(this)