-
Notifications
You must be signed in to change notification settings - Fork 0
/
SumAllRow.java
43 lines (37 loc) · 1.07 KB
/
SumAllRow.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
/**
* {@link SumAllRow} is an abstraction of {@link ScoreRow} that generalizes
* the score calculations in {@link #calculateScore(Dice)}.
*
* @see #calculateScore(Dice)
* @see ChanceRow
* @see NumOfAKindRow
*/
public abstract class SumAllRow extends ScoreRow {
/**
* Represent rows who's score is the sum of dices.
* {@link SumAllRow#calculateScore(Dice)} determines this scoring.
*
* @param name The scoring row's name.
*/
public SumAllRow(String name) {
super(name);
}
/**
* {@inheritDoc} {@link SumAllRow}'s score is the sum of all dice.
*
* @see ScoreRow#calculateScore(Dice)
*/
public void calculateScore(Dice dice) {
if (!this.isValid(dice)) {
this.setScore(0);
return;
}
// initialized the score to 0
int score = 0;
// loop though each dice an add their value to score
for (int i = 0; i < Yahtzee.DICE_COUNT; i++)
score += dice.getDie(i).getValue();
// set the score
this.setScore(score);
}
}