1 | package io.github.mathieusoysal.yatzy_mod; | |
2 | ||
3 | import io.github.mathieusoysal.Dices; | |
4 | import io.github.mathieusoysal.exception.NullDicesException; | |
5 | ||
6 | /** | |
7 | * The {@code YatzyMod} enum represents different scoring categories in the | |
8 | * Yatzy game. Each category has a specific scoring rule associated with it. | |
9 | * | |
10 | * @author MathieuSoysal | |
11 | * @see Dices | |
12 | * @see YatzyModInterface | |
13 | */ | |
14 | public enum YatzyMod { | |
15 | /** | |
16 | * CHANCE | |
17 | * Is the sum of all dice, no matter what they read. | |
18 | * | |
19 | * @see YMChance | |
20 | */ | |
21 | CHANCE(new YMChance()), | |
22 | ||
23 | /** | |
24 | * YATZY | |
25 | * If all dice have the same number, | |
26 | * the player scores 50 points. | |
27 | * | |
28 | * @see YMYatzy | |
29 | */ | |
30 | YATZY(new YMYatzy()), | |
31 | ||
32 | /** | |
33 | * ONES | |
34 | * The player scores the sum of the dice that reads one respectively. | |
35 | * | |
36 | * @see YMOnes | |
37 | */ | |
38 | ONES(new YMOnes()), | |
39 | ||
40 | /** | |
41 | * TWOS | |
42 | * The player scores the sum of the dice that reads two respectively. | |
43 | * | |
44 | * @see YMTwos | |
45 | */ | |
46 | TWOS(new YMTwos()), | |
47 | ||
48 | /** | |
49 | * THREES | |
50 | * The player scores the sum of the dice that reads three respectively. | |
51 | * | |
52 | * @see YMThrees | |
53 | */ | |
54 | THREES(new YMThrees()), | |
55 | ||
56 | /** | |
57 | * FOURS | |
58 | * The player scores the sum of the dice that reads four respectively. | |
59 | * | |
60 | * @see YMFours | |
61 | */ | |
62 | FOURS(new YMFours()), | |
63 | ||
64 | /** | |
65 | * FIVES | |
66 | * The player scores the sum of the dice that reads five respectively. | |
67 | * | |
68 | * @see YMFives | |
69 | */ | |
70 | FIVES(new YMFives()), | |
71 | ||
72 | /** | |
73 | * SIXES | |
74 | * The player scores the sum of the dice that reads six respectively. | |
75 | * | |
76 | * @see YMSixes | |
77 | */ | |
78 | SIXES(new YMSixes()), | |
79 | ||
80 | /** | |
81 | * PAIR | |
82 | * The player scores the sum of the two highest matching dice. | |
83 | * | |
84 | * @see YMPair | |
85 | */ | |
86 | PAIR(new YMPair()), | |
87 | ||
88 | /** | |
89 | * TWO_PAIRS | |
90 | * The player scores the sum of the two pairs of dice with the same number. | |
91 | * | |
92 | * @see YMTwoPairs | |
93 | */ | |
94 | TWO_PAIRS(new YMTwoPairs()), | |
95 | ||
96 | /** | |
97 | * THREE_OF_A_KIND | |
98 | * The player scores the sum of three dice with the same number. | |
99 | * | |
100 | * @see YMThreeOfAKind | |
101 | */ | |
102 | THREE_OF_A_KIND(new YMThreeOfAKind()), | |
103 | ||
104 | /** | |
105 | * FOUR_OF_A_KIND | |
106 | * The player scores the sum of four dice with the same number. | |
107 | * | |
108 | * @see YMFourOfAKind | |
109 | */ | |
110 | FOUR_OF_A_KIND(new YMFourOfAKind()), | |
111 | ||
112 | /** | |
113 | * SMALL_STRAIGHT | |
114 | * The player scores 15 if the dice form a small straight (1, 2, 3, 4, 5). | |
115 | * | |
116 | * @see YMSmallStraight | |
117 | */ | |
118 | SMALL_STRAIGHT(new YMSmallStraight()), | |
119 | ||
120 | /** | |
121 | * LARGE_STRAIGHT | |
122 | * The player scores 20 if the dice form a large straight (2, 3, 4, 5, 6). | |
123 | * | |
124 | * @see YMLargeStraight | |
125 | */ | |
126 | LARGE_STRAIGHT(new YMLargeStraight()), | |
127 | ||
128 | /** | |
129 | * FULL_HOUSE | |
130 | * The player scores the sum of all dice if they form a full house (two of a | |
131 | * kind and three of a kind). | |
132 | * | |
133 | * @see YMFullHouse | |
134 | */ | |
135 | FULL_HOUSE(new YMFullHouse()); | |
136 | ||
137 | private YatzyModInterface mod; | |
138 | ||
139 | /** | |
140 | * Constructor for YatzyMod enum. | |
141 | * | |
142 | * @param mod The YatzyModInterface implementation for the category. | |
143 | */ | |
144 | YatzyMod(YatzyModInterface mod) { | |
145 | this.mod = mod; | |
146 | } | |
147 | ||
148 | /** | |
149 | * Calculate the score for a given set of dice based on the category represented | |
150 | * by this enum value. | |
151 | * | |
152 | * @param dices The set of dice. | |
153 | * @return The calculated score for the category. | |
154 | * @throws NullDicesException If the given set of dice is null. | |
155 | * @see NullDicesException | |
156 | */ | |
157 | public int calculateScore(Dices dices) { | |
158 |
1
1. calculateScore : negated conditional → KILLED |
if (dices == null) |
159 | throw new NullDicesException(); | |
160 |
1
1. calculateScore : replaced int return with 0 for io/github/mathieusoysal/yatzy_mod/YatzyMod::calculateScore → KILLED |
return mod.calculateScore(dices); |
161 | } | |
162 | } | |
Mutations | ||
158 |
1.1 |
|
160 |
1.1 |