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

add 'quit' fonctionnality

parent da614def
......@@ -33,6 +33,8 @@ public class Game {
while(!newSet.isOver()) {
Player next = newSet.getNextPlayer();
if (!next.isOff())
{
int point = -1;
while (point < 0 || point > 10) {
System.out.format("%n%s, please enter the point: ", next.getName());
......@@ -47,7 +49,9 @@ public class Game {
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 {
point = inputReader.nextInt();
......@@ -62,7 +66,18 @@ public class Game {
}
}
}
}
else
{
int point =0;
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());
}
}
}
return newSet.getWinner();
......
package game;
public class Player {
private final String name;
private Boolean quit = false;
public Player(String name) {
this.name = name;
......@@ -16,4 +18,12 @@ public class Player {
public String toString() {
return this.name;
}
public void quitNow() {
this.quit = true;
}
public Boolean isOff() {
return quit;
}
}
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