-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamePiece.java
230 lines (195 loc) · 4.52 KB
/
gamePiece.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
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
/*Chris Fortier
* csci e-50b
*
* term project
*
* This file will create an abstract class that controls the game pieces and movements. Two children classes of computer player and human player will be called. My original thought was that the logic to move the computer pieces would come from the child class of gamePieceComputer... however while coding i deteremined it was a lot simpler to include it in the other classes. Therefore gamePieceHuman and gamePieceComputer have the exact same functionality.`
*
*/
import java.util.*;
public abstract class gamePiece
{
//instance variables
private String name;
private char pieceMarker;
private int pieceColorR;
private int pieceColorG;
private int pieceColorB;
//create variables to track if the item is still in play (potential person/weapon/room). follows indexing from cardTracker
private boolean[] weapon = new boolean[9];
private boolean[] room = new boolean[9];
private boolean[] person = new boolean[6];
/*
* initial constructor
* @param n - String name of piece //ended up not using
* @param m - char m to use as the piece marker //ended up not using
* @param colorR - int for red value
* @param colorG - int for green value
* @param colorB - int for blue value
*/
gamePiece(String n, char m, int colorR, int colorG, int colorB)
{
//instance variables
name = n;
pieceMarker = m;
pieceColorR = colorR;
pieceColorG = colorG;
pieceColorB = colorB;
//set all trackers to true indicating they are still in play
for (int i = 0; i < 9; i++) {
weapon[i] = true;
room[i] = true;
}
for (int i = 0; i < 6; i++) {
person[i] = true;
}
}
/*
* default constructor - not used in program
*/
gamePiece()
{
super();
}
/*
* @return pieceMarker
*/
public char getPieceMarker()
{
return pieceMarker;
}
/*
* @return name
*/
public String getName()
{
return name;
}
/*
* @param i - int value for which weapon was viewed/not in play
*/
public void setWeaponViewed(int i)
{
weapon[i] = false;
}
/*
* @param i - int value for which person was viewed/not in play
*/
public void setPersonViewed(int i)
{
person[i] = false;
}
/*
* @param i - int value for which room was viewed/not in play
*/
public void setRoomViewed(int i)
{
room[i] = false;
}
/*
* @return cardsRemaining - get all cards not viewed (still in play)
*/
public String[] getCardsRemaining()
{
String[] output = new String[24];
int outRow = 0;
//get people
for (int i = 0; i < 6; i++) {
if (person[i] == true) {
output[outRow] = "people[" + i + "] == true";
outRow++;
}
}
//get rooms
for (int i = 0; i < 9; i++) {
if (room[i] == true) {
output[outRow] = "room[" + i + "] == true";
outRow++;
}
}
//get weapons
for (int i = 0; i < 9; i++) {
if (weapon[i] == true) {
output[outRow] = "weapon[" + i + "] == true";
outRow++;
}
}
return output;
}
/*
* get all cards
*/
public String[] getAllCards()
{
String[] output = new String[24];
int outRow = 0;
//get people
for (int i = 0; i < 6; i++) {
if (person[i] == true) {
output[outRow] = "people[" + i + "] == true";
} else {
output[outRow] = "people[" + i + "] == false";
}
outRow++;
}
//get rooms
for (int i = 0; i < 9; i++) {
if (room[i] == true) {
output[outRow] = "room[" + i + "] == true";
} else {
output[outRow] = "room[" + i + "] == false";
}
outRow++;
}
//get weapons
for (int i = 0; i < 9; i++) {
if (weapon[i] == true) {
output[outRow] = "weapon[" + i + "] == true";
} else {
output[outRow] = "weapon[" + i + "] ==false";
}
outRow++;
}
return output;
}
/*
* @return rumor - randomly choose a remaining person, room, and weapon as rumor
*/
public int[] makeRumor()
{
//temp variables
int tempPerson = -1;
int tempRoom = -1;
int tempWeapon = -1;
int [] out = {-1, -1, -1};
//generate random number
Random gen = new Random();
//randomly choose a person remaining
do {
int num = gen.nextInt(6);
if (person[num] == true) {
tempPerson = num;
}
} while (tempPerson == -1);
//randomly choose a room remaining
do {
int num = gen.nextInt(9);
if (room[num] == true) {
tempRoom = num;
}
} while (tempRoom == -1);
//randomly choose a weapon remaining
do {
int num = gen.nextInt(6);
if (weapon[num] == true) {
tempWeapon = num;
}
} while (tempWeapon == -1);
//assign to out
out[0] = tempPerson;
out[1] = tempRoom;
out[2] = tempWeapon;
//return
return out;
}
}