-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDriver.java
More file actions
202 lines (170 loc) · 5.32 KB
/
Driver.java
File metadata and controls
202 lines (170 loc) · 5.32 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package oilRig;
import java.util.HashSet;
//import java.util.HashSet;
import java.util.Scanner;
//import java.util.ArrayList;
public class Driver {
private Scanner input;
private InputReader reader;
private Player player;
private Board board;
// private Responder responder; if doing rules to ask Q&A
}
public Driver(){
input = new Scanner(System.in);
// responder = new Responder();
reader = new InputReader();
}
public static void main(String[] args) {
Driver d = new Driver();
d.printWelcome();
d.runMenu();
d.printGoodbye();
}
private void printWelcome()
{
System.out.println("Welcome to the North Sea Oil game\n");
}
private int mainMenu(){
System.out.println("North Sea Oil");
System.out.println("---------");
System.out.println(" 1) Troubleshoot");
System.out.println(" 2) Instructions");
System.out.println(" 3) Play Game");
System.out.println("-----------------");
System.out.println(" 0) Exit");
System.out.print("==>> ");
boolean goodInput = false;
int option = 0;
do{
try {
option = input.nextInt();
goodInput=true;
}
catch (Exception e){
String throwOut = input.nextLine();
System.out.println("Number required - you entered text");
}
}while(!goodInput);
return option;
}
private void runMenu()
{
int option = mainMenu();
while (option != 0)
{
switch (option)
{
case 1: System.out.println("Please type your question?");
HashSet<String> input = reader.getInput();
while(!input.contains("bye"))
{
String responses = responder.generateResponse(input);
System.out.println(responses);
input = reader.getInput();
}
break;
case 2: responder.instructions();
break;
case 3: secondMenun();
break;
default: System.out.println("Invalid option entered: " + option);
break;
}
System.out.println("\nPress any key to continue...");
input.nextLine();
input.nextLine();
option = mainMenu();
}
System.out.println("Exiting... bye");
System.exit(0);
}
public void addPlayer(){
input.nextLine();
System.out.print("Enter the Players Name: ");
String playerName = input.nextLine();
board.add(player=new Player(playerName));
}
private void processPlayers(){
boolean goodInput = false;
int numberPlayers =0;
do{
try {
System.out.print("How many players would like to play? ");
numberPlayers = input.nextInt();
numberOfPlayers(numberPlayers);
goodInput=true;
}
catch (Exception e){
String throwOut = input.nextLine();
System.out.println("Number required - you entered text");
}
}while(!goodInput);
board=new Board();
for(int i=0; i<numberPlayers;i++){
addPlayer();
}
for(int i=0; i<numberPlayers;i++){
System.out.println(board.getPlayers().get(i)+"\n");
}
}
/**
* Ensures there are only 2-6 players
*/
private void numberOfPlayers(int numberOfPlayers){
if((numberOfPlayers<2)||(numberOfPlayers>6)){
System.out.println("You can only have 2-6 players.");
System.out.print("Please try again\n");
processPlayers();
}
}
public void board() throws Exception{
try{
baord= HandleXML.read("game.xml");
}
catch(Exception e)
{
System.out.println("Error reading from file: " + e);
}
}
private int startMenu()
{
listPlayers();
System.out.println("---------");
System.out.println("Choose a Number From Menu");
System.out.println("---------");
System.out.println(" 1) ....");
System.out.println(" 2) ....");
System.out.println(" 3) ....");
System.out.println(" 4) List Board Squares");
System.out.println("----------");
System.out.println(" 0) Exit");
System.out.print("==>> ");
int option = input.nextInt();
return option;
}
private void secondMenu()
{
int option = startMenu();
while (option != 0)
{
switch (option)
{
case 1: ...
break;
case 2: ...
break;
case 3: board();
break;
default: System.out.println("Invalid option entered: " + option);
break;
}
System.out.println("\nPress any key to continue...");
input.nextLine();
input.nextLine();
option = startMenu();
}
System.out.println("Exiting... bye");
System.exit(0);
}
}