-
Notifications
You must be signed in to change notification settings - Fork 0
/
Human.java
150 lines (131 loc) · 4.31 KB
/
Human.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
/*
* Course: CSC421
* Assignment: #3
* Author: Andrew Seligman
* Date: May 7, 2014
* File: Human.java
*******************************************************************************/
import javax.swing.*;
import java.awt.*;
import java.util.*;
/**
* Human.java implements methods for a human player to score categories.
**/
public class Human extends Player
{
private SoundLib Sounds;
private SoundLib BadPlaySounds;
private SoundLib LowerCheerSounds;
private SoundLib UpperCheerSounds;
private String[] soundFiles;
/**
* Constructor creates a named player and loads sounds related to scoring.
*
* @param name of the player
*
* @param app is the main Yahtzee class
*
* @param isUsingThisApp is a boolean whether the player being instantiated
* is controlling this applet
**/
public Human(String name, Yahtzee app, boolean isUsingThisApp)
{
super(name, app, isUsingThisApp);
soundFiles = new String[1];
soundFiles[0] = new String("kiddinMe.wav");
Sounds = new SoundLib(soundFiles);
soundFiles = new String[4];
soundFiles[0] = new String("murloc.wav");
soundFiles[1] = new String("comeOn.wav");
soundFiles[2] = new String("goblinLaugh.wav");
soundFiles[3] = new String("goblinYell.wav");
BadPlaySounds = new SoundLib(soundFiles);
soundFiles = new String[5];
soundFiles[0] = new String("lowerGood1.wav");
soundFiles[1] = new String("lowerGood2.wav");
soundFiles[2] = new String("lowerGood3.wav");
soundFiles[3] = new String("lowerGood4.wav");
soundFiles[4] = new String("lowerGood5.wav");
LowerCheerSounds = new SoundLib(soundFiles);
soundFiles = new String[5];
soundFiles[0] = new String("upperGood1.wav");
soundFiles[1] = new String("upperGood2.wav");
soundFiles[2] = new String("upperGood3.wav");
soundFiles[3] = new String("upperGood4.wav");
soundFiles[4] = new String("upperGood5.wav");
UpperCheerSounds = new SoundLib(soundFiles);
}
/**
* Get the player's choice for the roll menu (used only by a robot).
*
* @param TheDice are needed by a computer player to make a choice
**/
public void getRollChoice(Dice TheDice)
{
///not used by human player
}
public void simulateRollButton()
{
///not used by human player
}
/**
* Enter a value given by a player for a category.
*
* @param index of the category to score
*
* @param score to place in the category
**/
public void cheatCategory(int index, int score)
{
if(!MyScore.setScore(index, score))
removeTurn();
if(!(score == 50 && index == 11))
MyScore.usedCategory(index);
updateScore();
}
/**
* Enter the score for a category based on the current state
* of the dice.
*
* @param index of the category to score
*
* @param DieValues is a string containing the five Die values
**/
public void setCategory(int index, String DieValues)
{
int score = 0;
if(index < 13)
{
score = MyScore.calculateScore(index, DieValues);
if(MyScore.setScore(index, score))
addTurn();
if(score != 50)
MyScore.usedCategory(index);
}
if(app.muteButton.isEnabled())
{
if(score == 0 && playerUsingThisApplet)
BadPlaySounds.playRandom();
else if(MyScore.wasGoodScore() && playerUsingThisApplet)
{
if(index < 6)
UpperCheerSounds.playRandom();
else
LowerCheerSounds.playRandom();
}
else if(score == 50 && !playerUsingThisApplet)
Sounds.playSound("kiddinMe.wav");
}
lastCategory = index;
lastScore = score;
}
/**
* Choose which dice to hold during a turn
*
* @param TheDice is the set of Die objects
**/
public void chooseHolds(Dice TheDice)
{
///no longer used by human player
}
}