Skip to content

Commit

Permalink
Add ability to try specific locations again
Browse files Browse the repository at this point in the history
  • Loading branch information
ggeerraarrdd committed Oct 28, 2023
1 parent 6789939 commit 2ae7465
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 48 deletions.
123 changes: 80 additions & 43 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,46 @@ def game():
"""Start a game"""

# Print to debug
# print("GAME() function call")
print("GAME() function call")

page = session["current_page"] = request.form.get("page")
goto = session["current_goto"] = request.form.get("goto")
if request.method == "POST":

# Print to debug
# print("\nGAME:")
# print(f"page: {page}")
# print(f"goto: {goto}")
# Print to debug
print("GAME() function call -> method POST")

page = session["current_page"] = request.form.get("page")
goto = session["current_goto"] = request.form.get("goto")
try_again = session["try_again"] = request.form.get("try-again")

if "current_game_id" not in session:
session["current_game_id"] = 0

# Print to debug
# print("\nGAME:")
# print(f"page: {page}")
# print(f"goto: {goto}")
# print(f"try_again: {try_again}")
# print(f"current_game_id: {session['current_game_id']}")

else:

# Print to debug
print("GAME() function call -> method GET")

page = session["current_page"]
goto = session["current_goto"]
try_again = session["try_again"]

if "current_game_id" not in session:
session["current_game_id"] = 0

# Print to debug
# print("\nGAME:")
# print(f"page: {page}")
# print(f"goto: {goto}")
# print(f"try_again: {try_again}")
# print(f"current_game_id: {session['current_game_id']}")

if "try_again" not in session:
session["try_again"] = 0

# Printo to debug
# print(f"Try Again: {session['try_again']}")
Expand All @@ -158,9 +186,11 @@ def game():
# print(f"\nPre-gane session check - AFTER clean-up: \n{session}\n")

# Get playable location
if session["try_again"] == 1:
if (session["try_again"] == "1") or (session["try_again"] == 1):
# Get specific location to try again
location = queries.get_playable_location_again(db, session["current_game_loc_id"])
else:
# Get random location as new game
location = queries.get_playable_location(db, session["user_id"])

# Checks if query returns a playable location
Expand Down Expand Up @@ -641,25 +671,27 @@ def traffic():
page = session["current_page"] = request.form.get("page")
goto = session["current_goto"] = request.form.get("goto")

# Print to debug
# print("\nRESULTS:")
# print(f"page: {page}")
# print(f"goto: {goto}")

try:
session["try_again"] = request.form.get("try-again")
try_again = session["try_again"] = request.form.get("try-again")
except KeyError:
session["try_again"] = 0
try_again = session["try_again"] = 0

# Set current_game_loc_id if Try Again clicked from Search History page
if request.form.get("try-again-loc-id"):
try_again_loc_id = session["current_game_loc_id"] = request.form.get("try-again-loc-id")
else:
try_again_loc_id = 0

if "current_game_id" not in session:
session["current_game_id"] = 0

# Print to debug
# print("\nTRAFFIC:")
# print(f"Current Page: {session['current_page']}")
# print(f"Request Go To: {session['current_goto']}")
# print(f"Try Again: {session['try_again']}")
# print(f"Current Game ID: {session['current_game_id']}\n")
# print(f"page: {page}")
# print(f"goto: {goto}")
# print(f"try_again: {try_again}")
# print(f"try_again_loc_id: {try_again_loc_id}")
# print(f"current_game_id: {session['current_game_id']}\n")

if session.get("user_id") is None:
return redirect("/tout")
Expand Down Expand Up @@ -762,28 +794,34 @@ def traffic_in():
# print(f"page: {page}")
# print(f"goto: {goto}")

if goto == "about":
return redirect("/about")

if goto == "howto":
return redirect("/howto")

if goto == "index":
return redirect("/")

if goto == "history":
return redirect("/history")

# Not rendered if session has user_id
# if goto == "register":
# return redirect("/register")

# Not rendered if session has user_id
# if goto == "login":
# return redirect("/login")
if (page == "history") and (goto == "game_again"):

return redirect("/game")

if goto == "logout":
return redirect("/logout")
else:

if goto == "about":
return redirect("/about")

if goto == "howto":
return redirect("/howto")

if goto == "index":
return redirect("/")

if goto == "history":
return redirect("/history")

# Not rendered if session has user_id
# if goto == "register":
# return redirect("/register")

# Not rendered if session has user_id
# if goto == "login":
# return redirect("/login")

if goto == "logout":
return redirect("/logout")

elif page == "game":

Expand Down Expand Up @@ -879,7 +917,6 @@ def traffic_in():

return redirect("/")


elif page == "result":

# If user "Quit Game", redirects to index
Expand Down
Binary file modified geo.db
Binary file not shown.
2 changes: 1 addition & 1 deletion static/scripts_map1.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ async function initMap() {
const contentIndex =
'<div class="infowindow-index">' +
'<form name="submit" action="/game" method="post">' +
'<input type="hidden" name="try-again" class="hidden-field" value="0"></input>' +
'<input type="hidden" name="current-game-id" class="hidden-field" value="0"></input>' +
'<input type="hidden" name="page" class="hidden-field" value="index"></input>' +
'<input type="hidden" name="goto" class="hidden-field" value="game"></input>' +
'<input type="hidden" name="try-again" class="hidden-field" value="0"></input>' +
'<button class="btn btn-primary" type="submit">Start Game</button>' +
'</form>'
'</div>';
Expand Down
4 changes: 1 addition & 3 deletions static/scripts_map3.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ async function initMap() {
if (current_game_answer_user_validation == 'quit') {
try_again =
'<div class="infowindow-result-footer-try">' +
'<form name="router" action="/traffic" method="post">' +
'<input type="hidden" name="page" class="hidden-field" value="result"></input>' +
'<input type="hidden" name="goto" class="hidden-field" value="zero"></input>' +
'<form name="router">' +
'<button name="router" class="btn btn-primary btn-sm" type="submit" disabled>Try Again</button>' +
'</form>' +
'</div>';
Expand Down
8 changes: 7 additions & 1 deletion static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,13 @@ td {
text-align: center;
}


.btn-xs
{
padding: 1px 5px !important;
font-size: 12px !important;
line-height: 1.5 !important;
border-radius: 3px !important;
}



Expand Down
3 changes: 3 additions & 0 deletions templates/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@
<form name="submit" action="/traffic" method="post">
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
<input type="hidden" name="goto" class="hidden-field" value="game"></input>
<input type="hidden" name="try-again" class="hidden-field" value="0"></input>
<button name="router" class="btn btn-primary btn-sm" type="submit">New Search</button>
</form>
</div>
<div class="container-bottom-image-buttons-stop">
<form name="submit" action="/traffic" method="post">
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
<input type="hidden" name="goto" class="hidden-field" value="index"></input>
<input type="hidden" name="try-again" class="hidden-field" value="0"></input>
<button name="router" class="btn btn-link btn-sm" type="submit">Stop Game</button>
</form>
</div>
Expand All @@ -75,6 +77,7 @@
<form name="submit" action="/traffic" method="post">
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
<input type="hidden" name="goto" class="hidden-field" value="zero"></input>
<input type="hidden" name="try-again" class="hidden-field" value="0"></input>
<button name="router" class="btn btn-link btn-sm" type="submit">Quit Location</button>
</form>
</div>
Expand Down
13 changes: 13 additions & 0 deletions templates/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<th class="text-start">Location ID</th>
<th class="text-start">Search Area</th>
<th class="text-start-center">Found</th>
<th class="text-start-center"></th>
<th class="text-start-center">Attempts</th>
<th class="text-start-center">Total <br>Time (min)</th>
<th class="text-start-center">Avg Time <br>per Attempt</th>
Expand All @@ -70,6 +71,18 @@
<td class="text-start">{{ h.loc_id }}</td>
<td class="text-start">{{ h.loc_city }}, {{ h.loc_state }}, {{ h.loc_country }}</td>
<td class="text-start-center">{{ h.found.upper() }}</td>
<td class="text-start-center">
{% if h.found|default("-", True) == "-" %}
<form name="router" action="/traffic" method="post">
<input type="hidden" name="page" class="hidden-field" value="history"></input>
<input type="hidden" name="goto" class="hidden-field" value="game_again"></input>
<input type="hidden" name="try-again" class="hidden-field" value="1"></input>
<input type="hidden" name="try-again-loc-id" class="hidden-field" value="{{ h.loc_id }}"></input>
<button class="btn btn-primary btn-xs" type="submit">Try Again</button>
</form>
{% else %}
{% endif %}
</td>
<td class="text-start-center">{{ h.total_attempts }}</td>
<td class="text-start-center">{% if h.found|default("-", True) == "-" %}-{% else %}{{ h.total_duration }}{% endif %}</td>
<td class="text-start-center">{% if h.found|default("-", True) == "-" %}-{% else %}{{ h.avg_time }}{% endif %}</td>
Expand Down

0 comments on commit 2ae7465

Please sign in to comment.