-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumberRow.java
52 lines (48 loc) · 1.34 KB
/
NumberRow.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
/**
* {@link NumberRow} extends {@link ScoreRow} for the "Ones", "Twos", ...
* "Sixes" categories and implements the {@link #isValid(Dice)} and
* {@link #calculateScore(Dice)} function.
*
* @see ScoreRow
* @author Arjun Subramanian
*/
public class NumberRow extends ScoreRow {
private int value;
/**
* Construct scoring row for the Full House category.
*
* @param name The scoring row's name.
* @param value Dice value we want.
* <p>
* Ex. Twos is 2.
*/
public NumberRow(String name, int value) {
super(name);
this.value = value;
}
/**
* {@inheritDoc} {@link NumberRow}'s score is the sum of all {@link value} dice.
*
* @see ScoreRow#calculateScore(Dice)
*/
public void calculateScore(Dice dice) {
if (!this.isValid(dice)) {
this.setScore(0);
return;
}
int counter = 0;
for (int i = 0; i < Yahtzee.DICE_COUNT; i++)
// ith dice value is the value i'm seeking
if (dice.getDie(i).getValue() == value)
counter++;
this.setScore(counter * value);
}
/**
* {@inheritDoc} {@link NumberRow} is always valid.
*
* @see ScoreRow#isValid(Dice)
*/
public boolean isValid(Dice dice) {
return true;
}
}