Skip to content

Commit 2ae7465

Browse files
committed
Add ability to try specific locations again
1 parent 6789939 commit 2ae7465

File tree

7 files changed

+105
-48
lines changed

7 files changed

+105
-48
lines changed

app.py

Lines changed: 80 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,46 @@ def game():
121121
"""Start a game"""
122122

123123
# Print to debug
124-
# print("GAME() function call")
124+
print("GAME() function call")
125125

126-
page = session["current_page"] = request.form.get("page")
127-
goto = session["current_goto"] = request.form.get("goto")
126+
if request.method == "POST":
128127

129-
# Print to debug
130-
# print("\nGAME:")
131-
# print(f"page: {page}")
132-
# print(f"goto: {goto}")
128+
# Print to debug
129+
print("GAME() function call -> method POST")
130+
131+
page = session["current_page"] = request.form.get("page")
132+
goto = session["current_goto"] = request.form.get("goto")
133+
try_again = session["try_again"] = request.form.get("try-again")
134+
135+
if "current_game_id" not in session:
136+
session["current_game_id"] = 0
137+
138+
# Print to debug
139+
# print("\nGAME:")
140+
# print(f"page: {page}")
141+
# print(f"goto: {goto}")
142+
# print(f"try_again: {try_again}")
143+
# print(f"current_game_id: {session['current_game_id']}")
144+
145+
else:
146+
147+
# Print to debug
148+
print("GAME() function call -> method GET")
149+
150+
page = session["current_page"]
151+
goto = session["current_goto"]
152+
try_again = session["try_again"]
153+
154+
if "current_game_id" not in session:
155+
session["current_game_id"] = 0
156+
157+
# Print to debug
158+
# print("\nGAME:")
159+
# print(f"page: {page}")
160+
# print(f"goto: {goto}")
161+
# print(f"try_again: {try_again}")
162+
# print(f"current_game_id: {session['current_game_id']}")
133163

134-
if "try_again" not in session:
135-
session["try_again"] = 0
136164

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

160188
# Get playable location
161-
if session["try_again"] == 1:
189+
if (session["try_again"] == "1") or (session["try_again"] == 1):
190+
# Get specific location to try again
162191
location = queries.get_playable_location_again(db, session["current_game_loc_id"])
163192
else:
193+
# Get random location as new game
164194
location = queries.get_playable_location(db, session["user_id"])
165195

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

644-
# Print to debug
645-
# print("\nRESULTS:")
646-
# print(f"page: {page}")
647-
# print(f"goto: {goto}")
648-
649674
try:
650-
session["try_again"] = request.form.get("try-again")
675+
try_again = session["try_again"] = request.form.get("try-again")
651676
except KeyError:
652-
session["try_again"] = 0
677+
try_again = session["try_again"] = 0
678+
679+
# Set current_game_loc_id if Try Again clicked from Search History page
680+
if request.form.get("try-again-loc-id"):
681+
try_again_loc_id = session["current_game_loc_id"] = request.form.get("try-again-loc-id")
682+
else:
683+
try_again_loc_id = 0
653684

654685
if "current_game_id" not in session:
655686
session["current_game_id"] = 0
656687

657688
# Print to debug
658689
# print("\nTRAFFIC:")
659-
# print(f"Current Page: {session['current_page']}")
660-
# print(f"Request Go To: {session['current_goto']}")
661-
# print(f"Try Again: {session['try_again']}")
662-
# print(f"Current Game ID: {session['current_game_id']}\n")
690+
# print(f"page: {page}")
691+
# print(f"goto: {goto}")
692+
# print(f"try_again: {try_again}")
693+
# print(f"try_again_loc_id: {try_again_loc_id}")
694+
# print(f"current_game_id: {session['current_game_id']}\n")
663695

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

765-
if goto == "about":
766-
return redirect("/about")
767-
768-
if goto == "howto":
769-
return redirect("/howto")
770-
771-
if goto == "index":
772-
return redirect("/")
773-
774-
if goto == "history":
775-
return redirect("/history")
776-
777-
# Not rendered if session has user_id
778-
# if goto == "register":
779-
# return redirect("/register")
780-
781-
# Not rendered if session has user_id
782-
# if goto == "login":
783-
# return redirect("/login")
797+
if (page == "history") and (goto == "game_again"):
798+
799+
return redirect("/game")
784800

785-
if goto == "logout":
786-
return redirect("/logout")
801+
else:
802+
803+
if goto == "about":
804+
return redirect("/about")
805+
806+
if goto == "howto":
807+
return redirect("/howto")
808+
809+
if goto == "index":
810+
return redirect("/")
811+
812+
if goto == "history":
813+
return redirect("/history")
814+
815+
# Not rendered if session has user_id
816+
# if goto == "register":
817+
# return redirect("/register")
818+
819+
# Not rendered if session has user_id
820+
# if goto == "login":
821+
# return redirect("/login")
822+
823+
if goto == "logout":
824+
return redirect("/logout")
787825

788826
elif page == "game":
789827

@@ -879,7 +917,6 @@ def traffic_in():
879917

880918
return redirect("/")
881919

882-
883920
elif page == "result":
884921

885922
# If user "Quit Game", redirects to index

geo.db

0 Bytes
Binary file not shown.

static/scripts_map1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ async function initMap() {
5454
const contentIndex =
5555
'<div class="infowindow-index">' +
5656
'<form name="submit" action="/game" method="post">' +
57-
'<input type="hidden" name="try-again" class="hidden-field" value="0"></input>' +
5857
'<input type="hidden" name="current-game-id" class="hidden-field" value="0"></input>' +
5958
'<input type="hidden" name="page" class="hidden-field" value="index"></input>' +
6059
'<input type="hidden" name="goto" class="hidden-field" value="game"></input>' +
60+
'<input type="hidden" name="try-again" class="hidden-field" value="0"></input>' +
6161
'<button class="btn btn-primary" type="submit">Start Game</button>' +
6262
'</form>'
6363
'</div>';

static/scripts_map3.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ async function initMap() {
6767
if (current_game_answer_user_validation == 'quit') {
6868
try_again =
6969
'<div class="infowindow-result-footer-try">' +
70-
'<form name="router" action="/traffic" method="post">' +
71-
'<input type="hidden" name="page" class="hidden-field" value="result"></input>' +
72-
'<input type="hidden" name="goto" class="hidden-field" value="zero"></input>' +
70+
'<form name="router">' +
7371
'<button name="router" class="btn btn-primary btn-sm" type="submit" disabled>Try Again</button>' +
7472
'</form>' +
7573
'</div>';

static/styles.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,13 @@ td {
562562
text-align: center;
563563
}
564564

565-
565+
.btn-xs
566+
{
567+
padding: 1px 5px !important;
568+
font-size: 12px !important;
569+
line-height: 1.5 !important;
570+
border-radius: 3px !important;
571+
}
566572

567573

568574

templates/game.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@
5959
<form name="submit" action="/traffic" method="post">
6060
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
6161
<input type="hidden" name="goto" class="hidden-field" value="game"></input>
62+
<input type="hidden" name="try-again" class="hidden-field" value="0"></input>
6263
<button name="router" class="btn btn-primary btn-sm" type="submit">New Search</button>
6364
</form>
6465
</div>
6566
<div class="container-bottom-image-buttons-stop">
6667
<form name="submit" action="/traffic" method="post">
6768
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
6869
<input type="hidden" name="goto" class="hidden-field" value="index"></input>
70+
<input type="hidden" name="try-again" class="hidden-field" value="0"></input>
6971
<button name="router" class="btn btn-link btn-sm" type="submit">Stop Game</button>
7072
</form>
7173
</div>
@@ -75,6 +77,7 @@
7577
<form name="submit" action="/traffic" method="post">
7678
<input type="hidden" name="page" class="hidden-field" value="{{ page }}"></input>
7779
<input type="hidden" name="goto" class="hidden-field" value="zero"></input>
80+
<input type="hidden" name="try-again" class="hidden-field" value="0"></input>
7881
<button name="router" class="btn btn-link btn-sm" type="submit">Quit Location</button>
7982
</form>
8083
</div>

templates/history.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<th class="text-start">Location ID</th>
5757
<th class="text-start">Search Area</th>
5858
<th class="text-start-center">Found</th>
59+
<th class="text-start-center"></th>
5960
<th class="text-start-center">Attempts</th>
6061
<th class="text-start-center">Total <br>Time (min)</th>
6162
<th class="text-start-center">Avg Time <br>per Attempt</th>
@@ -70,6 +71,18 @@
7071
<td class="text-start">{{ h.loc_id }}</td>
7172
<td class="text-start">{{ h.loc_city }}, {{ h.loc_state }}, {{ h.loc_country }}</td>
7273
<td class="text-start-center">{{ h.found.upper() }}</td>
74+
<td class="text-start-center">
75+
{% if h.found|default("-", True) == "-" %}
76+
<form name="router" action="/traffic" method="post">
77+
<input type="hidden" name="page" class="hidden-field" value="history"></input>
78+
<input type="hidden" name="goto" class="hidden-field" value="game_again"></input>
79+
<input type="hidden" name="try-again" class="hidden-field" value="1"></input>
80+
<input type="hidden" name="try-again-loc-id" class="hidden-field" value="{{ h.loc_id }}"></input>
81+
<button class="btn btn-primary btn-xs" type="submit">Try Again</button>
82+
</form>
83+
{% else %}
84+
{% endif %}
85+
</td>
7386
<td class="text-start-center">{{ h.total_attempts }}</td>
7487
<td class="text-start-center">{% if h.found|default("-", True) == "-" %}-{% else %}{{ h.total_duration }}{% endif %}</td>
7588
<td class="text-start-center">{% if h.found|default("-", True) == "-" %}-{% else %}{{ h.avg_time }}{% endif %}</td>

0 commit comments

Comments
 (0)