@@ -12,13 +12,11 @@ public class Hangman {
1212 private InputHandler inputHandler ;
1313 private UserSession userSession ;
1414
15-
1615 public Hangman () {
1716 this .inputHandler = new InputHandler ();
1817 this .wordManager = new WordManager (this .inputHandler );
1918 this .userSession = new UserSession (this .inputHandler );
2019 this .currGameState = GameState .MENU ;
21-
2220
2321 }
2422
@@ -54,30 +52,35 @@ public void run() {
5452
5553 private void statSession () {
5654
57- userSession .viewTopFiveleaderboard ();
58- inputHandler .waitForAnyKey ();
59- currGameState = GameState .MENU ;
55+ userSession .viewTopFiveleaderboard ();
56+ inputHandler .waitForAnyKey ();
57+ currGameState = GameState .MENU ;
6058
6159 }
6260
6361 private void gameSession () {
6462
65- GameSession gameSession = new GameSession (inputHandler , wordManager .getGameSessionWord (), userSession .getUser ());
63+ GameSession gameSession = new GameSession (inputHandler , wordManager .getGameSessionWord (),
64+ userSession .getUser ());
6665 boolean success = gameSession .play ();
6766 User gameSessionUser = gameSession .getUser ();
67+ handlePostGame (gameSessionUser , success );
68+ }
69+
70+
71+ private void handlePostGame (User gameSessionUser , boolean success ) {
72+
6873 userSession .setUser (gameSessionUser );
69-
74+
7075 if (success ) {
7176 DisplayManager .continuePlay ();
7277 int n = inputHandler .enterInt (2 , false , false );
7378
74-
7579 if (n == 2 ) {
76- userSession .updateScore ();
77- userSession .resetScore ();
78- this .currGameState = GameState .PLAY_MENU ;
79- }
80- else if (n == 1 ){
80+ userSession .updateScore ();
81+ userSession .resetScore ();
82+ this .currGameState = GameState .PLAY_MENU ;
83+ } else if (n == 1 ) {
8184 wordManager .pickWordAgain ();
8285 }
8386
@@ -88,40 +91,39 @@ else if (n == 1){
8891 }
8992
9093 userSession .updatePoints ();
91-
92-
94+
9395 }
9496
9597 private void PlayMenuSession () {
96- DisplayManager .showPlayMenu ();
97- int choice = inputHandler .enterInt (3 , true , false );
98- boolean sucess = false ;
99- switch (choice ) {
100- case 0 :
101- this .currGameState = GameState .MENU ;
102- break ;
103-
104- case 1 :
105- if (userSession .getUser ()==null ){
106- System .out .println ("You must select a user to play." );
98+ DisplayManager .showPlayMenu ();
99+ int choice = inputHandler .enterInt (3 , true , false );
100+ boolean sucess = false ;
101+ switch (choice ) {
102+ case 0 :
103+ this .currGameState = GameState .MENU ;
107104 break ;
108- }
109- sucess = wordManager .pickWordSession ();
110- if (sucess ){
111- currGameState = GameState .GAMESESSION ;
112- }
113-
114- break ;
115-
116- case 2 :
117- wordManager .displayAvailableCategories ();
118- inputHandler .waitForAnyKey ();
119- break ;
120-
121- case 3 :
122- DisplayManager .showRules ();
123-
124- }
105+
106+ case 1 :
107+ if (userSession .getUser () == null ) {
108+ System .out .println ("You must select a user to play." );
109+ break ;
110+ }
111+ sucess = wordManager .pickWordSession ();
112+ if (sucess ) {
113+ currGameState = GameState .GAMESESSION ;
114+ }
115+
116+ break ;
117+
118+ case 2 :
119+ wordManager .displayAvailableCategories ();
120+ inputHandler .waitForAnyKey ();
121+ break ;
122+
123+ case 3 :
124+ DisplayManager .showRules ();
125+
126+ }
125127
126128 }
127129
@@ -133,39 +135,39 @@ private void pickUserSession() {
133135 case 0 :
134136 this .currGameState = GameState .MENU ;
135137 break ;
136-
138+
137139 // createUser
138140 case 1 :
139- success = this .userSession .createUserSession ();
140- if (success ){
141- this .currGameState = GameState .MENU ;
142- }
143- break ;
144-
141+ success = this .userSession .createUserSession ();
142+ if (success ) {
143+ this .currGameState = GameState .MENU ;
144+ }
145+ break ;
146+
145147 case 2 :
146- success = this .userSession .loadUserSession ();
147- if (success ){
148- this .currGameState = GameState .MENU ;
148+ success = this .userSession .loadUserSession ();
149+ if (success ) {
150+ this .currGameState = GameState .MENU ;
149151 }
150152 break ;
151-
153+
152154 case 3 :
153- success = this .userSession .deleteUserSession ();
154- if (success ){
155- this .currGameState = GameState .MENU ;
155+ success = this .userSession .deleteUserSession ();
156+ if (success ) {
157+ this .currGameState = GameState .MENU ;
156158 }
157159 break ;
158-
160+
159161 case 4 :
160162 success = this .userSession .viewCurrUser ();
161- if (success ){
163+ if (success ) {
162164 this .currGameState = GameState .MENU ;
163- }
164- break ;
165+ }
166+ break ;
167+
168+ }
165169
166170 }
167-
168- }
169171
170172 private void menuSession () {
171173 DisplayManager .showMenu ();
@@ -184,7 +186,7 @@ private void menuSession() {
184186 this .currGameState = GameState .EXIT ;
185187 break ;
186188
189+ }
187190 }
188- }
189191
190192}
0 commit comments