-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
84 lines (69 loc) · 2.86 KB
/
Main.java
File metadata and controls
84 lines (69 loc) · 2.86 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
// CLASS: Main
//
// Author: Huayi Chen
//
// REMARKS: initialize game and call Model to run game
//
//----------------------------------------
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
private static HumanPlayer hPlayer;
private static ComputerPlayer cPlayer;
private static ArrayList<IPlayer> players=new ArrayList<>();
private static ArrayList<Card> suspect=new ArrayList<>();
private static ArrayList<Card> location=new ArrayList<>();
private static ArrayList<Card> weapon=new ArrayList<>();
public static void main(String[] args) {
initializeGame();
Model newGame=new Model(players, suspect, location, weapon);
newGame.startPlay();
}
public static void initializeGame(){
System.out.println("Welcome to \"whodunnit?\"");
System.out.println("How many computer opponents would you like?");
suspect.add(new Card("suspect", "<Suspect A>"));
suspect.add(new Card("suspect", "<Suspect B>"));
suspect.add(new Card("suspect", "<Suspect C>"));
suspect.add(new Card("suspect", "<Suspect D>"));
suspect.add(new Card("suspect", "<Suspect E>"));
suspect.add(new Card("suspect", "<Suspect F>"));
suspect.add(new Card("suspect", "<Suspect G>"));
location.add(new Card("location", "<garden>"));
location.add(new Card("location", "<roof>"));
location.add(new Card("location", "<balcony>"));
location.add(new Card("location", "<basement>"));
location.add(new Card("location", "<garage>"));
location.add(new Card("location", "<toilet>"));
weapon.add(new Card("weapon", "<axe>"));
weapon.add(new Card("weapon", "<gun>"));
weapon.add(new Card("weapon", "<knife>"));
weapon.add(new Card("weapon", "<bomb>"));
weapon.add(new Card("weapon", "<poison>"));
// get how many computer players
boolean isValid=false;
int numCompPlayer=-1;
while (!isValid){
Scanner keyBoard=new Scanner(System.in);
if (keyBoard.hasNextInt()){
numCompPlayer=keyBoard.nextInt();
if (numCompPlayer>0){
isValid=true;
}else {
System.out.println("Invalid number of computer players. Try again.");
}
} else {
System.out.println("Please enter a number. Try again.");
}
}
hPlayer=new HumanPlayer();
players.add(hPlayer);
for (int i = 0; i < numCompPlayer; i++) {
cPlayer=new ComputerPlayer();
players.add(cPlayer);
}
// make players random order to sit around table
Collections.shuffle(players);
}
}