Esempio n. 1
0
def loadGame(file_name=constants.SAVE_FILE, redraw=True):
    #Load game info
    saved_state = fileHandler.loadVariable(constants.VARIABLE_STATE, file_name)
    saved_move_num = fileHandler.loadVariable(constants.VARIABLE_MOVE,
                                              file_name)

    #Write loaded variables to variables file
    fileHandler.saveVariable(constants.VARIABLE_STATE, saved_state)
    fileHandler.saveVariable(constants.VARIABLE_MOVE, saved_move_num)

    #Convert state from string to list
    saved_state = converter.toList(saved_state)

    if redraw:
        #Load board configuration
        listInterpret.listToPiece(saved_state)

    #Write turn number
    screenWriter.writeTurn(saved_move_num)

    #Update the scoreboard
    updateScoreBoard(saved_state)

    #Reset valid moves from turtleMove
    turtleMove.SHOWN_MOVES = []

    #Show possible moves
    displayValidMoves(saved_state, int(saved_move_num))
Esempio n. 2
0
def saveGame():
    #Get current game info
    current_state = fileHandler.loadVariable(constants.VARIABLE_STATE)
    current_move_num = fileHandler.loadVariable(constants.VARIABLE_MOVE)

    #Save game info
    fileHandler.saveVariable(constants.VARIABLE_STATE, current_state,
                             constants.SAVE_FILE)
    fileHandler.saveVariable(constants.VARIABLE_MOVE, current_move_num,
                             constants.SAVE_FILE)
Esempio n. 3
0
def startMove():
    #Save variable
    fileHandler.saveVariable(constants.VARIABLE_MOVING,
                             constants.VARIABLE_BOOL_TRUE)

    #Load the variables we need
    game_state = converter.toList(
        fileHandler.loadVariable(constants.VARIABLE_STATE))
    move_num = int(fileHandler.loadVariable(constants.VARIABLE_MOVE))

    #Return game_state and move_num as a tuple
    return (game_state, move_num)
Esempio n. 4
0
def placePiece(x, y):
    #Make sure a move is not being made
    if fileHandler.loadVariable(
            constants.VARIABLE_MOVING) == constants.VARIABLE_BOOL_FALSE:
        #Get the variables for the start of the move
        game_state, move_num = startMove()

        #Make sure the game is not over
        if not victoryStatus.endGameStatus(game_state):
            #Check if the player tried to pass or if the click was valid
            passing_turn = isPassClicked(x, y)
            click_valid = (isValidSquare(x, y) and \
                          isValidMove(game_state, getMove(x, y), move_num))

            if passing_turn or click_valid:
                #Make the player's move
                move_num = playerTurn(x, y, game_state, move_num, passing_turn)

                #Make the computer's move
                game_state, move_num = makeComputerTurn(
                    game_state, move_num, passing_turn)

                #End the move
                endMove(game_state, move_num)
        else:
            #End the game
            finishGame(game_state)

        #Save variable
        fileHandler.saveVariable(constants.VARIABLE_MOVING,
                                 constants.VARIABLE_BOOL_FALSE)
Esempio n. 5
0
def endMove(game_state, move_num):
    #Save the variables
    fileHandler.saveVariable(constants.VARIABLE_STATE,
                             converter.toString(game_state))
    fileHandler.saveVariable(constants.VARIABLE_MOVE, str(move_num))

    #Reload the board
    loadGame(constants.TEMP_FILE, False)

    #Update the scoreboard
    updateScoreBoard(
        converter.toList(fileHandler.loadVariable(constants.VARIABLE_STATE)))

    #Update the window
    constants.WINDOW.update()