@@ -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
0 commit comments