Moving re-playability to other script

This commit is contained in:
Thomas Kwashnak
2022-01-06 10:02:44 -05:00
committed by GitHub
parent e19a4aef19
commit 821ae4befe

View File

@@ -9,9 +9,9 @@ public class HighIQ {
private PrintStream out; private PrintStream out;
private Scanner scanner; private Scanner scanner;
public HighIQ() { public HighIQ(Scanner sccanner) {
out = System.out; out = System.out;
scanner = new Scanner(System.in); this.scanner = scanner;
board = new HashMap<>(); board = new HashMap<>();
//Set of all locations to put initial pegs on //Set of all locations to put initial pegs on
@@ -26,6 +26,7 @@ public class HighIQ {
board.put(41, false); board.put(41, false);
} }
public boolean move() { public boolean move() {
System.out.println("MOVE WHICH PIECE"); System.out.println("MOVE WHICH PIECE");
int from = scanner.nextInt(); int from = scanner.nextInt();
@@ -62,7 +63,6 @@ public class HighIQ {
} }
public void play() { public void play() {
do {
do { do {
while(!move()) { while(!move()) {
System.out.println("ILLEGAL MOVE, TRY AGAIN..."); System.out.println("ILLEGAL MOVE, TRY AGAIN...");
@@ -83,14 +83,12 @@ public class HighIQ {
out.println("SAVE THIS PAPER AS A RECORD OF YOUR ACCOMPLISHMENT!"); out.println("SAVE THIS PAPER AS A RECORD OF YOUR ACCOMPLISHMENT!");
} }
} while(playAgain());
out.println("SO LONG FOR NOW.");
} }
private boolean playAgain() { // private boolean playAgain() {
out.println("PLAY AGAIN (YES OR NO)"); // out.println("PLAY AGAIN (YES OR NO)");
return scanner.nextLine().toLowerCase().equals("yes"); // return scanner.nextLine().toLowerCase().equals("yes");
} // }
public boolean isGameFinished() { public boolean isGameFinished() {