def game():
    global passedEncounter

    print("Day " + str(userJourney[0]))
    #PLANET 0
    if (userJourney[1] >= userJourney[2]):
        print("PLANET 0")
        userJourney[2] += 1000
        return render_template("planet.html",
                               name="Gemini",
                               image=hubble.hubbleAPI())
    #PLANET 1
    if (userJourney[1] >= userJourney[3]):
        print("PLANET 1")
        userJourney[3] += 1000
        return render_template("planet.html",
                               name="Soupy",
                               image=hubble.hubbleAPI())
    #PLANET 2
    if (userJourney[1] >= userJourney[4]):
        print("PLANET 2")
        userJourney[4] += 1000
        return render_template("planet.html",
                               name="Vader",
                               image=hubble.hubbleAPI())
    #PLANET 3
    if (userJourney[1] >= userJourney[5]):
        print("PLANET 3")
        userJourney[5] += 1000
        return render_template("planet.html",
                               name="Termina",
                               image=hubble.hubbleAPI())
    #FINISH
    if (userJourney[1] >= userJourney[6]):
        print("Congratulations! You have finished the game")
        return render_template("fin.html")
        #return endScreen()

        #return endScreen()
    ######################
    #print("Day " + str(userJourney[0]))
    #print("0. Continue\n1. Inventory\n2. Crew Status\n3. Settings")
    #INVENTORY AND CREW STATUS
    response = int(request.form["input"])
    while (response != 0):
        if (response == 1):
            return render_template("settings.html",
                                   settings=userSettings,
                                   image=hubble.hubbleAPI())
        print("Day " + str(userJourney[0]))
        print("0. Continue\n1. Inventory\n2. Crew Status\n3. Settings")
        return returnToGame()
        #response = askUser()

    userJourney[0] += 1
    dayPasses()
    print(passedEncounter)
    return encounter()
def checkPlanet():
    response = int(request.form["input"])
    while (response != 0):
        if (response == 1):
            return render_template("settings.html",
                                   settings=userSettings,
                                   image=hubble.hubbleAPI())
        if (response == 2):
            return render_template("shop.html",
                                   message="Welcome to my shop!",
                                   stat=userInventory,
                                   image=hubble.hubbleAPI())
        print("Day " + str(userJourney[0]))
        print("0. Continue\n1. Inventory\n2. Crew Status\n3. Settings")
        return render_template("planet.html", image=hubble.hubbleAPI())
    return returnToGame()
def startGame():
    print("STARTGAME!!!")
    # BANDAGES, FOOD, FUEL, MONEY, SHIP PARTS, WEAPONS
    #     0       1    2      3        4         5
    userInventory = [200, 200, 200, 1000, 200, 200]

    # DIFFICULTY, NAME, CREW0, CREW1, CREW2,
    #     0        1      2      3      4
    userData = [0, "name", "crew0", "crew1", "crew2"]

    # USER SETTINGS
    #  FOOD(TXT), SPEED(TXT), FOOD(LVL), SPEED(LVL)
    #   0             1            2            3
    userSettings = ["Normal", "Steady", 1, 1]

    # userJourney
    #  DAY, TRAVELED, PLANET 1, PLANET 2, PLANET 3, PLANET 4, FINISH
    #   0      1         2         3         4        5         6
    userJourney = [0, 0, 40, 100, 150, 225, 300]

    # crewStatus
    #  food    speed  bandages
    # HUNGER, ENERGY, HEALTH, SHIP HEALTH
    #   0       1       2         3
    crewStatus = [200, 100, 100, 100]

    passedEncounter = True
    return render_template("difficulty.html", image=hubble.hubbleAPI())
def chooseYourName():  #Choose your character name
    response = request.form['input']
    try:
        name = int(response)
        return redirect(url_for(chooseYourDifficulty))
    except:
        global userData
        userData[1] = response
        return render_template("crew.html", image=hubble.hubbleAPI())
def chooseYourCrew():
    crew0 = request.form['input0']
    crew1 = request.form['input1']
    crew2 = request.form['input2']
    userData[2] = crew0
    userData[3] = crew1
    userData[4] = crew2
    return render_template("shop.html",
                           stat=userInventory,
                           image=hubble.hubbleAPI())
def changeSettings():
    response = int(request.form["input"])
    while (response != 6):
        if (response == 0): userSettings[0] = "Meager"
        if (response == 1): userSettings[0] = "Normal"
        if (response == 2): userSettings[0] = "Banquet"
        if (response == 3): userSettings[1] = "Slow"
        if (response == 4): userSettings[1] = "Steady"
        if (response == 5): userSettings[1] = "Fast"
        return render_template("settings.html",
                               settings=userSettings,
                               image=hubble.hubbleAPI())
    return returnToGame()
def chooseYourDifficulty():  #Choose difficulty
    print("HERE!!!")
    print(request.form['input'])
    response = int(request.form['input'])
    global userData
    global userInventory
    if (response == 0):
        userInventory[3] = 1500
    elif (response == 1):
        userInventory[3] = 1000
    elif (response == 2):
        userInventory[3] = 500
    else:
        return "Broke"
    userData[0] = response
    print(userInventory)
    print(userData)
    return render_template("name.html", image=hubble.hubbleAPI())
def encounter():
    global crewStatus
    #determine which aspect
    typeEncounter = random.randint(0, 3)
    #HUNGER
    if (typeEncounter == 0):
        if (crewStatus[0] >= 50):
            result = DBMethods.getNormHunger()[random.randint(0, 5)]
        else:
            result = DBMethods.getLowHunger()[random.randint(0, 2)]
    #ENERGY
    if (typeEncounter == 1):
        if (crewStatus[1] >= 20):
            result = DBMethods.getNormEnergy()[random.randint(0, 1)]
        else:
            result = DBMethods.getLowEnergy()[random.randint(0, 4)]
    #HEALTH
    if (typeEncounter == 2):
        if (crewStatus[2] >= 20):
            result = DBMethods.getNormHealth()[random.randint(0, 1)]
        else:
            result = DBMethods.getLowHealth()[random.randint(0, 3)]
    #SHIP HEALTH
    if (typeEncounter == 3):
        if (crewStatus[3] >= 20):
            result = DBMethods.getNormShipHealth()[random.randint(0, 2)]
        else:
            result = DBMethods.getLowShipHealth()[random.randint(0, 2)]
    #SPECIAL ENCOUNTER: SITUATION
    #if (typeEncounter == 4):
    #    result = DBMethods.getSituations()[0]
    #    return result[0]

    char = userData[random.randint(1, 4)]
    print("0. Continue")
    return render_template("encounter.html",
                           day=userJourney[0],
                           char=char,
                           result=result,
                           image=hubble.hubbleAPI())
def returnToGame():
    return render_template("gamescreen.html",
                           day=str(userJourney[0]),
                           crewStatus=crewStatus,
                           image=hubble.hubbleAPI())
def shop():
    system("cls")
    global userInventory
    print("What would you like to do?")
    print("0. Buy Ship Parts         1. Sell Ship Parts")
    print("2. Buy Fuel               3. Sell Fuel")
    print("4. Buy Food               5. Sell Food")
    print("6. Buy Bandages           7. Sell Bandages")
    print("8. Buy Weapons            9. Sell Weapons")
    print("10. Continue\n")
    #print(message)
    print("Balance: " + str(userInventory[3]))
    print("Ship parts: " + str(userInventory[4]))
    print("Fuel: " + str(userInventory[2]))
    print("Food: " + str(userInventory[1]))
    print("Bandages: " + str(userInventory[0]))
    print("Weapons: " + str(userInventory[5]) + "\n")

    response = int(request.form['input'])
    if (response == 10):
        return redirect(url_for("returnToGame"))
    if (response % 2):
        #print("ODD NUMBER")
        if (response == 1):  #SHIP PARTS
            if (userInventory[4] < 50):
                return render_template(
                    "shop.html",
                    message="Invalid request. Ship parts too low.",
                    stat=userInventory,
                    image=hubble.hubbleAPI())
            userInventory[3] += 50
            userInventory[4] -= 50
        if (response == 3):  #FUEL
            if (userInventory[2] < 50):
                return render_template(
                    "shop.html",
                    message="Invalid request. Fuel too low.",
                    stat=userInventory,
                    image=hubble.hubbleAPI())
            userInventory[3] += 50
            userInventory[2] -= 50
        if (response == 5):  #FOOD
            if (userInventory[1] < 50):
                return render_template(
                    "shop.html",
                    message="Invalid request. Food too low.",
                    stat=userInventory,
                    image=hubble.hubbleAPI())
            userInventory[3] += 50
            userInventory[1] -= 50
        if (response == 7):  #Bandages
            if (userInventory[0] < 50):
                return render_template(
                    "shop.html",
                    message="Invalid request. Bandages too low.",
                    stat=userInventory,
                    image=hubble.hubbleAPI())
            userInventory[3] += 50
            userInventory[0] -= 50
        if (response == 9):  #WEAPONS
            if (userInventory[5] < 50):
                return render_template(
                    "shop.html",
                    message="Invalid request. Weapons too low.",
                    stat=userInventory,
                    image=hubble.hubbleAPI())
            userInventory[3] += 50
            userInventory[5] -= 50
    else:
        #print("EVEN NUMBER")
        if (userInventory[3] < 50):
            return render_template("shop.html",
                                   message="Invalid request. Funds too low.",
                                   stat=userInventory,
                                   image=hubble.hubbleAPI())
        if (response == 0):  #SHIP PARTS
            userInventory[3] -= 50
            userInventory[4] += 50
        if (response == 2):  #FUEL
            userInventory[3] -= 50
            userInventory[2] += 50
        if (response == 4):  #FOOD
            userInventory[3] -= 50
            userInventory[1] += 50
        if (response == 6):
            userInventory[3] -= 50
            userInventory[0] += 50
        if (response == 8):
            userInventory[3] -= 50
            userInventory[5] += 50

    #print(userInventory)
    return render_template("shop.html",
                           stat=userInventory,
                           image=hubble.hubbleAPI())