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 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. 3
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. 4
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. 5
0
def finishGame(game_state):
    #Print who won
    game_status = playerVictory.playerWon(game_state)
    screenWriter.writeMessage(game_status)

    #Wait for user
    constants.WINDOW.exitonclick()

    #Reset state and move
    fileHandler.saveVariable(constants.VARIABLE_STATE,
                             constants.VARIABLE_BLANK)
    fileHandler.saveVariable(constants.VARIABLE_MOVE, constants.VARIABLE_BLANK)
Esempio n. 6
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()
Esempio n. 7
0
def run(game_state, move_num, player_move):
    #Allow the computer to make it's move
    if not player_move:
        state = computerTurn(game_state, move_num)
        move_num += 1

    #End the computer's move
    endMove(game_state, move_num)

    #Show possible moves
    displayValidMoves(game_state, move_num)

    #Save variables to be used later
    fileHandler.saveVariable(constants.VARIABLE_STATE,
                             converter.toString(game_state))
    fileHandler.saveVariable(constants.VARIABLE_MOVE, str(move_num))
    fileHandler.saveVariable(constants.VARIABLE_MOVING,
                             constants.VARIABLE_BOOL_FALSE)

    #Set up the window
    wn = constants.WINDOW
    wn.onclick(placePiece)
    wn.onkey(saveGame, constants.SAVE_KEY)
    wn.onkey(loadGame, constants.LOAD_KEY)
    wn.onkey(quitGame, constants.EXIT_KEY)
    wn.listen()
    wn.mainloop()
Esempio n. 8
0
def quitGame():
    #Reset variables
    fileHandler.saveVariable(constants.VARIABLE_STATE,
                             constants.VARIABLE_BLANK)
    fileHandler.saveVariable(constants.VARIABLE_MOVE, constants.VARIABLE_BLANK)
    fileHandler.saveVariable(constants.VARIABLE_MOVING,
                             constants.VARIABLE_BOOL_FALSE)

    #Close the game
    wn = constants.WINDOW
    wn.bye()