From 757d258e3de8cb383b1d66ba7a9d8f74c43a6ce6 Mon Sep 17 00:00:00 2001 From: Vikramb987 <47336882+Vikramb987@users.noreply.github.com> Date: Mon, 25 Feb 2019 19:44:21 -0700 Subject: [PATCH] Update Player.java changes to how the game ends --- src/Player.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Player.java b/src/Player.java index 709c01e..5dfcf7d 100644 --- a/src/Player.java +++ b/src/Player.java @@ -1,3 +1,5 @@ +import java.util.Scanner; + public class Player { private String name = "Taipan"; @@ -211,7 +213,21 @@ public class Player { public void gameOver(){ System.out.flush(); System.out.println("Game over"); - System.exit(0); } -} \ No newline at end of file + public boolean playAgain(){ + Scanner input = new Scanner(System.in); + System.out.println("Would you like to play again? Y/N"); + while(true){ + String response = input.nextLine(); + if(response.equalsIgnoreCase("Y")){ + return true; + }else if(response.equalsIgnoreCase("N")){ + System.exit(0); + }else{ + System.out.println("That is not a valid input."); + } + } + } + +}