Commit 82e8bfa1 authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch5] Improvements to SimpleStartup (not put in book yet). Adding GameHelper

parent e88826c4
Loading
Loading
Loading
Loading
+20 −0
Changes for src/main/java/ch5/GameHelper.java: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
package ch5;

import java.io.*;

public class GameHelper {
  public String getUserInput(String prompt) {
    String inputLine = null;
    System.out.print(prompt + "  ");
    try {
      BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
      inputLine = is.readLine();
      if (inputLine.length() == 0) {
        return null;
      }
    } catch (IOException e) {
      System.out.println("IOException: " + e);
    }
    return inputLine;
  }
}
 No newline at end of file
+3 −3
Changes for src/main/java/ch5/SimpleStartupTestDrive.java: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -7,13 +7,14 @@ public class SimpleStartupTestDrive {
    dot.setLocationCells(locations);
    String userGuess = "2";
    String result = dot.checkYourself(userGuess);
    System.out.println(result);
  }
}


class SimpleStartup {
  int[] locationCells;
  int numOfHits = 0;
  private int[] locationCells;
  private int numOfHits = 0;

  public void setLocationCells(int[] locs) {
    locationCells = locs;
@@ -34,7 +35,6 @@ class SimpleStartup {
        locationCells.length) {
      result = "kill";
    }
    System.out.println(result);
    return result;
  } // close method
} // close class
 No newline at end of file