-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
510 lines (470 loc) · 11.7 KB
/
Copy pathPlayer.java
File metadata and controls
510 lines (470 loc) · 11.7 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
//Bret Owens - bto14
//Alex Sumner - acs14k
//imports for Player
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Random;
public class Player extends JPanel{
private int [] Upper = new int[6]; //scores of upper section
private int [] Lower = new int[8]; //scores of lower section
public int FScore = 0; //Final score
public JPanel chart = new JPanel(); //chart for displaying scores and combos
public ArrayList<JButton> Panels = new ArrayList<JButton>(); //AL of buttons for combos
public ArrayList<JLabel> Points = new ArrayList<JLabel>(); //AL of labels for score received
public int PLnum; //player number
//temp values for each
private int aceval = 0;
private int twoval = 0;
private int threeval = 0;
private int fourval = 0;
private int fiveval = 0;
private int sixval = 0;
private int TOKval = 0;
private int FOKval = 0;
private int YAHval = 0;
private int SSval = 0;
private int LSval = 0;
private int FHval = 0;
private int CHval = 0;
private int Ranval = 0;
public Player(int x)
{
PLnum = x + 1; //assign player number
for(int i = 0; i < Upper.length; i++)
{
Upper[i] = -1; //values for not-filled upper
}
for(int i = 0; i < Lower.length; i++)
{
Lower[i] = -1; //values for not filled lower
}
for(int i = 0; i < 14; i++)
{
Panels.add(new JButton());
Points.add(new JLabel(" "));
} //Simple adding of new buttons and labels to ALs
GridLayout bob = new GridLayout(15,3); //Layout for charts
chart.setLayout(bob);
chart.add(new JLabel("Combo")); //Headers
chart.add(new JLabel("Points Earned"));
chart.add(new JLabel("Points possible on current roll"));
chart.add(new JLabel("Aces")); //Start of combo and points earned and points possible
chart.add(Points.get(0));
chart.add(Panels.get(0));
chart.add(new JLabel("Twos"));
chart.add(Points.get(1));
chart.add(Panels.get(1));
chart.add(new JLabel("Threes"));
chart.add(Points.get(2));
chart.add(Panels.get(2));
chart.add(new JLabel("Fours"));
chart.add(Points.get(3));
chart.add(Panels.get(3));
chart.add(new JLabel("Fives"));
chart.add(Points.get(4));
chart.add(Panels.get(4));
chart.add(new JLabel("Sixes"));
chart.add(Points.get(5));
chart.add(Panels.get(5));
chart.add(new JLabel("Three of a Kind"));
chart.add(Points.get(6));
chart.add(Panels.get(6));
chart.add(new JLabel("Four of a Kind"));
chart.add(Points.get(7));
chart.add(Panels.get(7));
chart.add(new JLabel("Yahtzee"));
chart.add(Points.get(8));
chart.add(Panels.get(8));
chart.add(new JLabel("Full House"));
chart.add(Points.get(9));
chart.add(Panels.get(9));
chart.add(new JLabel("Small Straight"));
chart.add(Points.get(10));
chart.add(Panels.get(10));
chart.add(new JLabel("Large Straight"));
chart.add(Points.get(11));
chart.add(Panels.get(11));
chart.add(new JLabel("Chance"));
chart.add(Points.get(12));
chart.add(Panels.get(12));
chart.add(new JLabel("Random"));
chart.add(Points.get(13));
chart.add(Panels.get(13));
//Start of action listeners for buttons
Panels.get(0).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Points.get(0).setText(Integer.toString(aceval));
Upper[0] = aceval;
Panels.get(0).setEnabled(false);
Panels.get(0).setVisible(false);
FinalP.roll = 4;
}
});
Panels.get(1).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Points.get(1).setText(Integer.toString(twoval));
Upper[1] = twoval;
Panels.get(1).setEnabled(false);
Panels.get(1).setVisible(false);
FinalP.roll = 4;
}
});
Panels.get(2).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Points.get(2).setText(Integer.toString(threeval));
Upper[2] = threeval;
Panels.get(2).setEnabled(false);
Panels.get(2).setVisible(false);
FinalP.roll = 4;
}
});
Panels.get(3).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Points.get(3).setText(Integer.toString(fourval));
Upper[3] = fourval;
Panels.get(3).setEnabled(false);
Panels.get(3).setVisible(false);
FinalP.roll = 4;
}
});
Panels.get(4).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Points.get(4).setText(Integer.toString(fiveval));
Upper[4] = fiveval;
Panels.get(4).setEnabled(false);
Panels.get(4).setVisible(false);
FinalP.roll = 4;
}
});
Panels.get(5).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Points.get(5).setText(Integer.toString(sixval));
Upper[5] = sixval;
Panels.get(5).setEnabled(false);
Panels.get(5).setVisible(false);
FinalP.roll = 4;
}
});
Panels.get(6).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Points.get(6).setText(Integer.toString(TOKval));
Lower[0] = TOKval;
Panels.get(6).setEnabled(false);
Panels.get(6).setVisible(false);
FinalP.roll = 4;
}
});
Panels.get(7).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Points.get(7).setText(Integer.toString(FOKval));
Lower[1] = FOKval;
Panels.get(7).setEnabled(false);
Panels.get(7).setVisible(false);
FinalP.roll = 4;
}
});
Panels.get(8).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Points.get(8).setText(Integer.toString(YAHval));
Lower[2] = YAHval;
Panels.get(8).setEnabled(false);
Panels.get(8).setVisible(false);
FinalP.roll = 4;
}
});
Panels.get(9).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Points.get(9).setText(Integer.toString(FHval));
Lower[3] = FHval;
Panels.get(9).setEnabled(false);
Panels.get(9).setVisible(false);
FinalP.roll = 4;
}
});
Panels.get(10).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Points.get(10).setText(Integer.toString(SSval));
Lower[4] = SSval;
Panels.get(10).setEnabled(false);
Panels.get(10).setVisible(false);
FinalP.roll = 4;
}
});
Panels.get(11).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Points.get(11).setText(Integer.toString(LSval));
Lower[5] = LSval;
Panels.get(11).setEnabled(false);
Panels.get(11).setVisible(false);
FinalP.roll = 4;
}
});
Panels.get(12).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Points.get(12).setText(Integer.toString(CHval));
Lower[6] = CHval;
Panels.get(12).setEnabled(false);
Panels.get(12).setVisible(false);
FinalP.roll = 4;
}
});
Panels.get(13).addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Random rand = new Random();
Ranval = rand.nextInt(50) + 1;
Points.get(13).setText(Integer.toString(Ranval));
Lower[7] = Ranval;
Panels.get(13).setEnabled(false);
Panels.get(13).setVisible(false);
FinalP.roll = 4;
}
});
chart.setBorder(BorderFactory.createLineBorder(Color.WHITE, 10));
chart.setVisible(true);
}
//check to change button labels when valid roll is made
public void check(String s)
{
if(JDice.Aces(s))
{
int charCount = 0;
for( int i = 0; i < s.length( ); i++ )
{
char temp = s.charAt( i );
if( temp == '1' )
charCount++;
}
Panels.get(0).setText("Points gained: " + charCount);
aceval = charCount;
}
else
{
Panels.get(0).setText("No points gained");
aceval = 0;
}
if(JDice.Twos(s))
{
int charCount = 0;
for( int i = 0; i < s.length( ); i++ )
{
char temp = s.charAt( i );
if( temp == '2' )
charCount++;
}
Panels.get(1).setText("Points gained: " + (charCount * 2));
twoval = charCount * 2;
}
else
{
Panels.get(1).setText("No points gained");
twoval = 0;
}
if(JDice.Threes(s))
{
int charCount = 0;
for( int i = 0; i < s.length( ); i++ )
{
char temp = s.charAt( i );
if( temp == '3' )
charCount++;
}
Panels.get(2).setText("Points gained: " + (charCount * 3));
threeval = charCount * 3;
}
else
{
Panels.get(2).setText("No points gained");
threeval = 0;
}
if(JDice.Fours(s))
{
int charCount = 0;
for( int i = 0; i < s.length( ); i++ )
{
char temp = s.charAt( i );
if( temp == '4' )
charCount++;
}
Panels.get(3).setText("Points gained: " + (charCount * 4));
fourval = charCount * 4;
}
else
{
Panels.get(3).setText("No points gained");
fourval = 0;
}
if(JDice.Fives(s))
{
int charCount = 0;
for( int i = 0; i < s.length( ); i++ )
{
char temp = s.charAt( i );
if( temp == '5' )
charCount++;
}
Panels.get(4).setText("Points gained: " + (charCount * 5));
fiveval = charCount * 5;
}
else
{
Panels.get(4).setText("No points gained");
fiveval = 0;
}
if(JDice.ThreeOfAKind(s))
{
int Count = 0;
String x;
for( int i = 0; i < s.length( ); i++ )
{
x = "" + s.charAt(i);
Count += Integer.parseInt(x);
}
Panels.get(6).setText("Points gained: " + (Count));
TOKval = Count;
}
else
{
Panels.get(6).setText("No points gained");
TOKval = 0;
}
if(JDice.Sixes(s))
{
int charCount = 0;
for( int i = 0; i < s.length( ); i++ )
{
char temp = s.charAt( i );
if( temp == '6' )
charCount++;
}
Panels.get(5).setText("Points gained: " + (charCount * 6));
sixval = charCount * 6;
}
else
{
Panels.get(5).setText("No points gained");
sixval = 0;
}
if(JDice.FourOfAKind(s))
{
int Count = 0;
String x;
for( int i = 0; i < s.length( ); i++ )
{
x = "" + s.charAt(i);
Count += Integer.parseInt(x);
}
Panels.get(7).setText("Points gained: " + (Count));
FOKval = Count;
}
else
{
Panels.get(7).setText("No points gained");
FOKval = 0;
}
if(JDice.Yaht(s))
{
Panels.get(8).setText("Points gained: 50");
YAHval = 50;
}
else
{
Panels.get(8).setText("No points gained");
YAHval = 0;
}
if(JDice.SmallStraight(s))
{
Panels.get(10).setText("Points gained: 30");
SSval = 30;
}
else
{
Panels.get(10).setText("No points gained");
SSval = 0;
}
if(JDice.LargeStraight(s))
{
Panels.get(11).setText("Points gained: 40");
LSval = 40;
}
else
{
Panels.get(11).setText("No points gained");
LSval = 0;
}
if(JDice.FullHouse(s))
{
Panels.get(9).setText("Points gained: 25");
FHval = 25;
}
else
{
Panels.get(9).setText("No points gained");
FHval = 0;
}
int Count = 0;
String x;
for( int i = 0; i < s.length( ); i++ )
{
x = "" + s.charAt(i);
Count += Integer.parseInt(x);
}
Panels.get(12).setText("Points gained: " + (Count));
CHval = Count;
Panels.get(13).setText("Random Number!");
}
//calculate final score for a player
public void calc_final()
{
int top = 0;
for (int i = 0; i < 6; i++)
{
top += Upper[i];
}
if(top >= 63)
{
top += 35;
}
int bottom = 0;
for (int i = 0; i < 8; i++)
{
bottom += Lower[i];
}
FScore = top + bottom;
}
}