-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoteBook.java
More file actions
231 lines (213 loc) · 10 KB
/
Copy pathNoteBook.java
File metadata and controls
231 lines (213 loc) · 10 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
/**
* A notebook that keeps track of players cards
*
* @Team MAGA
* @Author Gajun Young - 16440714
* @Author Royal Thomas - 16326926
* @Author Richard Otroshchenko - 16353416
*/
public class NoteBook {
private ArrayList<Card> unusedCards; //Undealt cards
private ArrayList<Card> hand; //Player cards
private ArrayList<Card> seenCard = new ArrayList<Card>();
//Someone answered a question and showed you the card
public NoteBook(ArrayList<Card> unusedCards, ArrayList<Card> hand) {
this.unusedCards = unusedCards;
this.hand = hand;
}
//Someone showed u a card, add it as seen
public void addSeenCard(Card card) {
seenCard.add(card);
}
//Testing to see if cards are added
public void getSeenCard() {
for (Card card : seenCard) {
System.out.println(card.toString());
}
}
public String getLatestCard() {
return seenCard.get(seenCard.size() - 1).toString();
}
/**
* Displays the notes of a player
*/
public void showNotes() {
// Ovverride so that the cells are no longer editable
DefaultTableModel model = new DefaultTableModel() {
@Override
// Makes the cells not editable
public boolean isCellEditable(int row, int column) {
return false;
}
};
// Create a new table to store notes.
JTable table = new JTable(model);
// Prevent user from dragging around columns.
table.getTableHeader().setReorderingAllowed(false);
// Add the column names one by one.
model.addColumn("TYPE");
model.addColumn("NAME");
model.addColumn("YOUR HAND");
model.addColumn("UNDEALT/SEEN");
JScrollPane tata = new JScrollPane(table);
// set the size as it was being crowded and didn't look good at all.
tata.setPreferredSize(new Dimension(1000, 170));
// output the table within the pane using joptionpane with the object.
JFrame displayProperties = new JFrame("NoteBook");
// Add the table to the frame
displayProperties.add(tata);
displayProperties.setSize(900, 400);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
displayProperties.setLocation(dim.width / 2 - displayProperties.getSize().width / 2,
dim.height / 2 - displayProperties.getSize().height / 2);
displayProperties.setVisible(true);
for (int count = 0; count < 6;
count++) { //This loop iterates through each of the six characters
boolean found = false; //Checks if a card was found so we dont display it twice
int count2 = 0;
while (count2
< hand.size()) { //This loop iterates through every card owned by the player
if (hand.get(count2).toString().equalsIgnoreCase(Card.suspects[count])) {
model.addRow(new Object[]{"Player", Card.suspects[count], "X", ""});
found = true;
}
count2++;
}
if (!found) { //The following if statements basically find and indicate undealt cards
if (unusedCards.size() == 1) {
if (unusedCards.get(0).toString().equalsIgnoreCase(Card.suspects[count])) {
model.addRow(new Object[]{"Player", Card.suspects[count], "", "A"});
found = true;
}
} else if (unusedCards.size() == 2) {
if (unusedCards.get(0).toString().equalsIgnoreCase(Card.suspects[count]) ||
unusedCards.get(1).toString().equalsIgnoreCase(Card.suspects[count])) {
model.addRow(new Object[]{"Player", Card.suspects[count], "", "A"});
found = true;
}
} else if (unusedCards.size()
== 3) {//There can only be at most 3 undealt cards with 2-6 players
if (unusedCards.get(0).toString().equalsIgnoreCase(Card.suspects[count]) ||
unusedCards.get(1).toString().equalsIgnoreCase(Card.suspects[count]) ||
unusedCards.get(2).toString().equalsIgnoreCase(Card.suspects[count])) {
model.addRow(new Object[]{"Player", Card.suspects[count], "", "A"});
found = true;
}
}
if (!found) { //If a card doesent match the player's cards and isn't undealt,
// it's added normally without a marker
Boolean foundCard = false;
for (Card c : seenCard) {
if (c.getName().equalsIgnoreCase(Card.suspects[count])) {
foundCard = true;
}
}
if (foundCard) {
model.addRow(new Object[]{"Player", Card.suspects[count], "", "V"});
} else {
model.addRow(new Object[]{"Player", Card.suspects[count], "", ""});
}
}
}
}
//The following is much like the previous except with weapon cards instead of players
for (int count = 0; count < 6; count++) {
boolean found = false;
int count2 = 0;
while (count2 < hand.size()) {
if (hand.get(count2).toString().equalsIgnoreCase(Card.weapons[count])) {
model.addRow(new Object[]{"Weapon", Card.weapons[count], "X", ""});
found = true;
}
count2++;
}
if (!found) {
if (unusedCards.size() == 1) {
if (unusedCards.get(0).toString().equalsIgnoreCase(Card.weapons[count])) {
model.addRow(new Object[]{"Weapon", Card.weapons[count], "", "A"});
found = true;
}
} else if (unusedCards.size() == 2) {
if (unusedCards.get(0).toString().equalsIgnoreCase(Card.weapons[count]) ||
unusedCards.get(1).toString().equalsIgnoreCase(Card.weapons[count])) {
model.addRow(new Object[]{"Weapon", Card.weapons[count], "", "A"});
found = true;
}
} else if (unusedCards.size() == 3) {
if (unusedCards.get(0).toString().equalsIgnoreCase(Card.weapons[count]) ||
unusedCards.get(1).toString().equalsIgnoreCase(Card.weapons[count]) ||
unusedCards.get(2).toString().equalsIgnoreCase(Card.weapons[count])) {
model.addRow(new Object[]{"Weapon", Card.weapons[count], "", "A"});
found = true;
}
}
if (!found) {
Boolean foundCard = false;
for (Card c : seenCard) {
if (c.getName().equalsIgnoreCase(Card.weapons[count])) {
foundCard = true;
}
}
if (foundCard) {
model.addRow(new Object[]{"Weapon", Card.weapons[count], "", "V"});
} else {
model.addRow(new Object[]{"Weapon", Card.weapons[count], "", ""});
}
}
}
}
//The following is much like the previous except with room cards instead of players
for (int count = 0; count < 9; count++) {
boolean found = false;
int count2 = 0;
while (count2 < hand.size()) {
if (hand.get(count2).toString().equalsIgnoreCase(Card.rooms[count])) {
model.addRow(new Object[]{"Room", Card.rooms[count], "X", ""});
found = true;
}
count2++;
}
if (!found) {
if (unusedCards.size() == 1) {
if (unusedCards.get(0).toString().equalsIgnoreCase(Card.rooms[count])) {
model.addRow(new Object[]{"Room", Card.rooms[count], "", "A"});
found = true;
}
} else if (unusedCards.size() == 2) {
if (unusedCards.get(0).toString().equalsIgnoreCase(Card.rooms[count]) ||
unusedCards.get(1).toString().equalsIgnoreCase(Card.rooms[count])) {
model.addRow(new Object[]{"Room", Card.rooms[count], "", "A"});
found = true;
}
} else if (unusedCards.size() == 3) {
if (unusedCards.get(0).toString().equalsIgnoreCase(Card.rooms[count]) ||
unusedCards.get(1).toString().equalsIgnoreCase(Card.rooms[count]) ||
unusedCards.get(2).toString().equalsIgnoreCase(Card.rooms[count])) {
model.addRow(new Object[]{"Room", Card.rooms[count], "", "A"});
found = true;
}
}
if (!found) {
Boolean foundCard = false;
for (Card c : seenCard) {
if (c.getName().equalsIgnoreCase(Card.rooms[count])) {
foundCard = true;
}
}
if (foundCard) {
model.addRow(new Object[]{"Room", Card.rooms[count], "", "V"});
} else {
model.addRow(new Object[]{"Room", Card.rooms[count], "", ""});
}
}
}
}
}
}