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 @@ -16,4 +16,12 @@ void check(int guess) {
1616 throw new IllegalArgumentException ("Invalid number!" );
1717 }
1818 }
19+
20+ void quit (int input ) {
21+ // 0 is quit
22+ // 1 is continue
23+ if (input != 0 || input != 1 ) {
24+ throw new IllegalArgumentException ("Invalid number!" );
25+ }
26+ }
1927}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ void run() {
66 DebugInfo debugInfo = new DebugInfo ();
77 GameInfo gameInfo = new GameInfo ();
88 GameLogic logic = new GameLogic ();
9+ CheckGuess check = new CheckGuess ();
910
1011 debugInfo .launchDebug ();
1112 gameInfo .about ();
@@ -25,13 +26,10 @@ void run() {
2526 System .out .print ("\n Play again? (1 -> Y / 0 -> N) " );
2627 try {
2728 play = scan .userGuess ();
28- if (play == 0 ) {
29- break ;
30- } else if (play != 1 ) {
31- throw new IllegalArgumentException ("" );
32- }
29+ check .quit (play );
3330 } catch (Exception e ) {
34- System .out .println ("Error reading input!" );
31+ debugInfo .gameCrash ();
32+ e .printStackTrace ();
3533 break ;
3634 }
3735 }
Original file line number Diff line number Diff line change 11package io .github .project516 .NumberGuessingGame ;
22
3+ import java .io .IOException ;
4+ import java .nio .file .Files ;
5+ import java .nio .file .Paths ;
6+
37/**
48 * Reads version information for the Number Guessing Game. Currently returns a placeholder version
59 * string.
@@ -12,6 +16,13 @@ public class ReadVersionFile {
1216 * @return the version string
1317 */
1418 public String readVersion () {
15- return "rolling" ;
19+ String filePath = "version.txt" ;
20+ String content = "rolling" ; // Placeholder version
21+ try {
22+ content = new String (Files .readAllBytes (Paths .get (filePath )));
23+ } catch (IOException e ) {
24+ System .err .println ("Error reading file: " + e .getMessage ());
25+ }
26+ return content ;
1627 }
1728}
You can’t perform that action at this time.
0 commit comments