Commit a23e6484 authored by Qi LI's avatar Qi LI
Browse files

put player back on game (new set) after quit

parent ecdbb3a4
......@@ -35,38 +35,38 @@ public class Game {
if (!next.isOff())
{
int point = -1;
while (point < 0 || point > 10) {
System.out.format("%n%s, please enter the point: ", next.getName());
if (!inputReader.hasNextInt()) {
String command = inputReader.next();
inputReader.nextLine();
if (command.equals("score")) {
for (int i = 0; i < players.size(); ++i) {
Player player = players.get(i);
System.out.format("%s's score table:%n%s%n", player.getName(), newSet.getScoreTable(player));
int point = -1;
while (point < 0 || point > 10) {
System.out.format("%n%s, please enter the point: ", next.getName());
if (!inputReader.hasNextInt()) {
String command = inputReader.next();
inputReader.nextLine();
if (command.equals("score")) {
for (int i = 0; i < players.size(); ++i) {
Player player = players.get(i);
System.out.format("%s's score table:%n%s%n", player.getName(), newSet.getScoreTable(player));
}
} else if (command.equals("quit")) {
next.quitNow();
System.out.format("%n%s has quit the game !", next.getName());
break;
}
} else if (command.equals("quit")) {
next.quitNow();
System.out.format("%n%s has quit the game !", next.getName());
break;
} else {
point = inputReader.nextInt();
inputReader.nextLine();
try {
String info = newSet.enterPoint(point);
if (info != null) System.out.println(info);
System.out.format("%s's score table:%n%s%n", next.getName(), newSet.getScoreTable(next));
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
} else {
point = inputReader.nextInt();
inputReader.nextLine();
try {
String info = newSet.enterPoint(point);
if (info != null) System.out.println(info);
System.out.format("%s's score table:%n%s%n", next.getName(), newSet.getScoreTable(next));
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}
else
{
int point =0;
......@@ -88,10 +88,18 @@ public class Game {
return inputReader.next().equals("quit");
}
public void enrollAllPlayers() {
for (Player player : players) {
if (player.isOff())
player.onGame();
}
}
public static void main (String[] args) {
Game game = new Game();
while(true) {
game.enterPlayers();
game.enrollAllPlayers();
Player winner = game.startSet();
System.out.println("Congratulations " + winner.getName() + "! You win!");
......
......@@ -26,4 +26,8 @@ public class Player {
public Boolean isOff() {
return quit;
}
public void onGame() {
this.quit = false;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment