-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandUi.java
115 lines (114 loc) · 3.34 KB
/
CommandUi.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import java.util.*;
public class CommandUi implements Ui{
Scanner scan;
public CommandUi(){
scan = new Scanner(System.in);
}
public String getPlayer(){
System.out.print("Please enter the name of the player: ");
return scan.nextLine();
}
public int removePlayer(){
System.out.print("Please enter the Player ID: ");
int id = scan.nextInt();
scan.nextLine();
System.out.print("Dropping player " + id + ". Are you sure? y/n ");
String input = scan.nextLine();
while(true){
if(input.equals("y")) return id;
else if(input.equals("n")) return -1;
else input = scan.nextLine();
}
}
/*
public boolean getOrRemove(){
System.out.println("Add or remove player? a/r");
String input = scan.nextLine();
while(true){
if(input.equals("a")) return true;
else if(input.equals("r")) return false;
else input = scan.nextLine();
}
}
*/
public int getOrRemoveOrDone(){
System.out.print("Add or remove player, or finish: a/r/f ");
String input = scan.nextLine();
while(true){
if(input.equals("a")) return 1;
else if(input.equals("r")) return -1;
else if(input.equals("f")) return 0;
else input = scan.nextLine();
}
}
/*
public boolean reportOrFinish(){
System.out.print("Report match or finish round? r/f ");
String input = scan.nextLine();
while(true){
if(input.equals("r")) return true;
else if(input.equals("f")) return false;
else input = scan.nextLine();
}
}
*/
public int reportOrDropOrFinish(){
System.out.print("Report match, drop player, or finish round: r/d/f ");
String input = scan.nextLine();
while(true){
if(input.equals("r")) return 1;
else if(input.equals("d")) return 0;
else if(input.equals("f")) return -1;
else input = scan.nextLine();
}
}
public int getTable(){
System.out.print("Which table? ");
int num = scan.nextInt();
scan.nextLine();
return num;
}
public int getWin(){
System.out.print("Player 1 wins? ");
int num = scan.nextInt();
scan.nextLine();
return num;
}
public int getLoss(){
System.out.print("Player 1 loss? ");
int num = scan.nextInt();
scan.nextLine();
return num;
}
public int getDraw(){
System.out.print("Player 1 draw? ");
int num = scan.nextInt();
scan.nextLine();
return num;
}
public void showPlayers(LinkedList<Player> players){
for(Player p : players){
System.out.println("ID: " + p.getId() + " Name: " + p.getName());
}
}
public void displayRound(Round rnd){
System.out.println("::Round " + rnd.getRoundNum() + "::");
for(Match a : rnd.getMatches()){
if(a.getPlayer2() != null && a.getDone() == false){
System.out.println("Table " + a.getTable() + ": " + a.getPlayer1().getName() + " vs. " + a.getPlayer2().getName());
} else if(a.getPlayer2() != null){
System.out.println("done ::Table " + a.getTable() + ": " + a.getPlayer1().getName() + " vs. " + a.getPlayer2().getName() + "::");
} else {
System.out.println(a.getPlayer1().getName() + " has a bye");
}
}
}
public void displayResult(LinkedList<Player> players){
System.out.println("::Results::");
Iterator<Player> plit = players.stream().sorted((a1, a2) -> Integer.compare(a2.getMatchPoints(), a1.getMatchPoints())).sorted((a1, a2) -> Integer.compare(a2.getGamePoints(), a1.getGamePoints())).iterator();
while(plit.hasNext()){
Player p = plit.next();
System.out.println(p.getName() + " -- " + p.getMatchPoints());
}
}
}