File tree Expand file tree Collapse file tree
app/src/main/java/io/github/project516/NumberGuessingGame Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,27 +13,7 @@ public class Main {
1313 * @param args command line arguments (not currently used)
1414 */
1515 public static void main (String [] args ) {
16-
17- ScannerHelper scan = new ScannerHelper ();
18- DebugInfo debugInfo = new DebugInfo ();
19- GameInfo gameInfo = new GameInfo ();
20- GameLogic logic = new GameLogic ();
21-
22- debugInfo .launchDebug ();
23-
24- try {
25-
26- gameInfo .about ();
27- logic .game ();
28-
29- } catch (Exception e ) {
30-
31- debugInfo .gameCrash ();
32- e .printStackTrace ();
33-
34- } finally {
35-
36- scan .close ();
37- }
16+ NumberGuessingGame game = new NumberGuessingGame ();
17+ game .run ();
3818 }
3919}
Original file line number Diff line number Diff line change 1+ package io .github .project516 .NumberGuessingGame ;
2+
3+ public class NumberGuessingGame {
4+ void run () {
5+ ScannerHelper scan = new ScannerHelper ();
6+ DebugInfo debugInfo = new DebugInfo ();
7+ GameInfo gameInfo = new GameInfo ();
8+ GameLogic logic = new GameLogic ();
9+
10+ debugInfo .launchDebug ();
11+ gameInfo .about ();
12+ int play = 1 ;
13+ while (play != 0 ) {
14+
15+ try {
16+
17+ logic .game ();
18+
19+ } catch (Exception e ) {
20+
21+ debugInfo .gameCrash ();
22+ e .printStackTrace ();
23+
24+ } finally {
25+ System .out .print ("\n Play again? (1 -> Y / 0 -> N) " );
26+ try {
27+ play = scan .userGuess ();
28+ if (play == 0 ) {
29+ break ;
30+ } else if (play != 1 ) {
31+ throw new IllegalArgumentException ("" );
32+ }
33+ } catch (Exception e ) {
34+ System .out .println ("Error reading input!" );
35+ break ;
36+ }
37+ }
38+ }
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments