Commit 4786b0b5 authored by Qi LI's avatar Qi LI
Browse files

add user interface

parent edc6f3df
package game;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;
public class Game {
private List<Player> players = new ArrayList<Player>();
private Scanner inputReader = new Scanner(System.in);
public Game() {}
private void enterPlayers(){
int newPlayerNumber = 0;
while(true) {
System.out.format("Number of new players: ");
newPlayerNumber = inputReader.nextInt();
if (newPlayerNumber > 0 || players.size() != 0) break;
}
for (int i = 0; i < newPlayerNumber; ++i) {
System.out.format("Name of player %d (out of %d): ", i + 1, newPlayerNumber);
String name = inputReader.next();
players.add(new Player(name));
}
}
public Player startSet() {
Set newSet = new Set(players);
while(!newSet.isOver()) {
Player next = newSet.getNextPlayer();
System.out.format("%n%s, please enter the point: ", next.getName());
newSet.enterPoint(inputReader.nextInt());
System.out.format("%s's score table:%n%s%n", next.getName(), newSet.getScoreTable(next));
}
return newSet.getWinner();
}
public boolean quitGame() {
System.out.println("%nGo on next set? (Type 'quit' to stop)");
return inputReader.next().equals("quit");
}
public static void main (String[] args) {
Game game = new Game();
while(true) {
game.enterPlayers();
Player winner = game.startSet();
System.out.println("Congratulations " + winner.getName() + "! You win!");
if (game.quitGame()) break;
}
}
}
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