Skip to content

Commit 298043c

Browse files
committed
refactor(plugin): plugin-specific MoveMistake class naming without dots in strings
1 parent 82c920f commit 298043c

File tree

17 files changed

+90
-85
lines changed

17 files changed

+90
-85
lines changed

plugin/src/main/kotlin/sc/plugin2024/GameState.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import sc.plugin2024.actions.Advance
99
import sc.plugin2024.actions.Push
1010
import sc.plugin2024.actions.Turn
1111
import sc.plugin2024.mistake.AdvanceProblem
12-
import sc.plugin2024.mistake.MoveMistake
12+
import sc.plugin2024.mistake.MQMoveMistake
1313
import sc.plugin2024.util.MQConstants
1414
import sc.plugin2024.util.MQConstants.POINTS_PER_SEGMENT
1515
import sc.plugin2024.util.MQWinReason
@@ -90,7 +90,7 @@ data class GameState @JvmOverloads constructor(
9090
* @throws InvalidMoveException wenn der Zug ungültig ist
9191
*/
9292
override fun performMoveDirectly(move: Move) {
93-
if(move.actions.isEmpty()) throw InvalidMoveException(MoveMistake.NO_ACTIONS)
93+
if(move.actions.isEmpty()) throw InvalidMoveException(MQMoveMistake.NO_ACTIONS)
9494

9595
val actions = move.actions.fold(ArrayList<Action>()) { acc, act ->
9696
val last = acc.lastOrNull()
@@ -103,16 +103,16 @@ data class GameState @JvmOverloads constructor(
103103
}
104104
actions.forEachIndexed { index, action ->
105105
when {
106-
board[currentShip.position] == Field.SANDBANK && index != 0 -> throw InvalidMoveException(MoveMistake.SAND_BANK_END, move)
107-
mustPush && action !is Push -> throw InvalidMoveException(MoveMistake.PUSH_ACTION_REQUIRED, move)
108-
action is Accelerate && index != 0 -> throw InvalidMoveException(MoveMistake.FIRST_ACTION_ACCELERATE, move)
106+
board[currentShip.position] == Field.SANDBANK && index != 0 -> throw InvalidMoveException(MQMoveMistake.SAND_BANK_END, move)
107+
mustPush && action !is Push -> throw InvalidMoveException(MQMoveMistake.PUSH_ACTION_REQUIRED, move)
108+
action is Accelerate && index != 0 -> throw InvalidMoveException(MQMoveMistake.FIRST_ACTION_ACCELERATE, move)
109109
else -> action.perform(this)?.let { throw InvalidMoveException(it, move) }
110110
}
111111
}
112112

113113
when {
114-
currentShip.movement > 0 -> throw InvalidMoveException(MoveMistake.MOVEMENT_POINTS_LEFT, move)
115-
currentShip.movement < 0 -> throw InvalidMoveException(MoveMistake.MOVEMENT_POINTS_MISSING, move)
114+
currentShip.movement > 0 -> throw InvalidMoveException(MQMoveMistake.MOVEMENT_POINTS_LEFT, move)
115+
currentShip.movement < 0 -> throw InvalidMoveException(MQMoveMistake.MOVEMENT_POINTS_MISSING, move)
116116
}
117117

118118
board.pickupPassenger(currentShip)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package sc.plugin2024.mistake
2+
3+
import sc.shared.IMoveMistake
4+
5+
enum class MQMoveMistake(override val message: String) : IMoveMistake {
6+
NO_ACTIONS("Der Zug enthält keine Aktionen"),
7+
PUSH_ACTION_REQUIRED("Wenn du auf einem gegnerischen Schiff landest, muss darauf eine Abdrängaktion folgen"),
8+
SAND_BANK_END("Zug auf eine Sandbank muss letzte Aktion sein"),
9+
FIRST_ACTION_ACCELERATE("Du kannst nur in der ersten Aktion beschleunigen"),
10+
MOVEMENT_POINTS_LEFT("Es sind noch Bewegungspunkte übrig"),
11+
MOVEMENT_POINTS_MISSING("Nicht genug Bewegungspunkte");
12+
}

plugin/src/main/kotlin/sc/plugin2024/mistake/MoveMistake.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.

plugin/src/main/kotlin/sc/plugin2025/Advance.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Advance(@XStreamAsAttribute val distance: Int, vararg val cards: Card): Hu
2626
var bought = false
2727
return cards.firstNotNullOfOrNull {
2828
if(bought)
29-
return MoveMistake.MUST_BUY_ONE_CARD
29+
return HuIMoveMistake.MUST_BUY_ONE_CARD
3030
if(state.currentField == Field.MARKET) {
3131
return@firstNotNullOfOrNull player.consumeCarrots(10) ?: run {
3232
bought = true
@@ -35,13 +35,13 @@ class Advance(@XStreamAsAttribute val distance: Int, vararg val cards: Card): Hu
3535
}
3636
}
3737
if(state.currentField != Field.HARE || lastCard?.moves == false)
38-
return MoveMistake.CANNOT_PLAY_CARD
38+
return HuIMoveMistake.CANNOT_PLAY_CARD
3939
lastCard = it
4040
it.perform(state)
41-
} ?: MoveMistake.MUST_BUY_ONE_CARD.takeIf {
41+
} ?: HuIMoveMistake.MUST_BUY_ONE_CARD.takeIf {
4242
// On Market field and no card bought or just moved there through card
4343
state.currentField == Field.MARKET && !bought
44-
} ?: MoveMistake.MUST_PLAY_CARD.takeIf {
44+
} ?: HuIMoveMistake.MUST_PLAY_CARD.takeIf {
4545
// On Hare field and no card played or just moved there through card
4646
state.currentField == Field.HARE && lastCard?.moves != false
4747
}

plugin/src/main/kotlin/sc/plugin2025/Card.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ import sc.shared.IMoveMistake
55

66
/** Mögliche Aktionen, die durch das Ausspielen einer Karte ausgelöst werden können. */
77
@XStreamAlias(value = "card")
8-
enum class Card(val moves: Boolean, val playable: (GameState) -> MoveMistake?, val play: (GameState) -> Unit): HuIMove {
8+
enum class Card(val moves: Boolean, val playable: (GameState) -> HuIMoveMistake?, val play: (GameState) -> Unit): HuIMove {
99
/** Falle hinter den Gegenspieler. */
1010
FALL_BACK(true,
1111
{ state ->
12-
MoveMistake.CANNOT_PLAY_FALL_BACK.takeUnless { state.isAhead() }
12+
HuIMoveMistake.CANNOT_PLAY_FALL_BACK.takeUnless { state.isAhead() }
1313
?: state.validateTargetField(state.otherPlayer.position - 1)
1414
},
1515
{ it.moveToField(it.otherPlayer.position - 1) }),
1616
/** Rücke vor den Gegenspieler. */
1717
HURRY_AHEAD(true,
1818
{ state ->
19-
MoveMistake.CANNOT_PLAY_HURRY_AHEAD.takeIf { state.isAhead() }
19+
HuIMoveMistake.CANNOT_PLAY_HURRY_AHEAD.takeIf { state.isAhead() }
2020
?: state.validateTargetField(state.otherPlayer.position + 1)
2121
},
2222
{ it.moveToField(it.otherPlayer.position + 1) }),
2323
/** Friss sofort einen Salat. */
2424
EAT_SALAD(
2525
false,
26-
{ state -> MoveMistake.NO_SALAD.takeUnless { state.currentPlayer.salads > 0 } },
26+
{ state -> HuIMoveMistake.NO_SALAD.takeUnless { state.currentPlayer.salads > 0 } },
2727
{ it.eatSalad() }),
2828
/** Karottenvorrat mit dem Gegner tauschen. */
2929
SWAP_CARROTS(false,
@@ -36,9 +36,9 @@ enum class Card(val moves: Boolean, val playable: (GameState) -> MoveMistake?, v
3636

3737
override fun perform(state: GameState): IMoveMistake? {
3838
if(state.currentField != Field.HARE)
39-
return MoveMistake.CANNOT_PLAY_CARD
39+
return HuIMoveMistake.CANNOT_PLAY_CARD
4040
if(!state.currentPlayer.removeCard(this))
41-
return MoveMistake.CARD_NOT_OWNED
41+
return HuIMoveMistake.CARD_NOT_OWNED
4242
return playable(state) ?: run {
4343
play(state)
4444
null

plugin/src/main/kotlin/sc/plugin2025/EatSalad.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object EatSalad: HuIMove {
1818
state.eatSalad()
1919
return null
2020
} else {
21-
return MoveMistake.CANNOT_EAT_SALAD
21+
return HuIMoveMistake.CANNOT_EAT_SALAD
2222
}
2323
}
2424

plugin/src/main/kotlin/sc/plugin2025/ExchangeCarrots.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ data class ExchangeCarrots(val value: Int): HuIMove {
1515
state.currentPlayer.carrots += value
1616
return null
1717
} else {
18-
return MoveMistake.CANNOT_EXCHANGE_CARROTS
18+
return HuIMoveMistake.CANNOT_EXCHANGE_CARROTS
1919
}
2020
}
2121
}

plugin/src/main/kotlin/sc/plugin2025/FallBack.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import com.thoughtworks.xstream.annotations.XStreamAlias
1010
*/
1111
@XStreamAlias(value = "fallBack")
1212
object FallBack: HuIMove {
13-
override fun perform(state: GameState): MoveMistake? {
13+
override fun perform(state: GameState): HuIMoveMistake? {
1414
val previousFieldIndex = state.nextFallBack()
1515
if(previousFieldIndex != null) {
1616
state.currentPlayer.carrots += 10 * (state.currentPlayer.position - previousFieldIndex)
1717
state.currentPlayer.position = previousFieldIndex
1818
return null
1919
} else {
20-
return MoveMistake.CANNOT_FALL_BACK
20+
return HuIMoveMistake.CANNOT_FALL_BACK
2121
}
2222
}
2323

plugin/src/main/kotlin/sc/plugin2025/GameState.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ data class GameState @JvmOverloads constructor(
131131

132132
override fun performMoveDirectly(move: HuIMove) {
133133
val mist =
134-
MoveMistake.MUST_EAT_SALAD.takeIf {
134+
HuIMoveMistake.MUST_EAT_SALAD.takeIf {
135135
mustEatSalad() && move != EatSalad
136136
}.also { currentPlayer.saladEaten = false } ?: move.perform(this)
137137
if(mist != null)
@@ -160,37 +160,37 @@ data class GameState @JvmOverloads constructor(
160160
}
161161
}
162162

163-
fun moveToField(newPosition: Int, player: Hare = currentPlayer): MoveMistake? =
163+
fun moveToField(newPosition: Int, player: Hare = currentPlayer): HuIMoveMistake? =
164164
validateTargetField(newPosition, player) ?: run {
165165
player.position = newPosition
166166
null
167167
}
168168

169169
/** Basic validation whether a player may move forward by that distance.
170170
* Does not validate whether a card can be played on hare field. */
171-
fun checkAdvance(distance: Int, player: Hare = currentPlayer): MoveMistake? {
171+
fun checkAdvance(distance: Int, player: Hare = currentPlayer): HuIMoveMistake? {
172172
return validateTargetField(
173173
player.position + distance,
174174
player,
175-
(player.carrots - calculateCarrots(distance)).takeIf { it >= 0 } ?: return MoveMistake.MISSING_CARROTS
175+
(player.carrots - calculateCarrots(distance)).takeIf { it >= 0 } ?: return HuIMoveMistake.MISSING_CARROTS
176176
)
177177
}
178178

179179
/** Basic validation whether a field may be entered via a jump that is not backward.
180180
* Does not validate whether a card can be played on hare field. */
181-
fun validateTargetField(newPosition: Int, player: Hare = currentPlayer, carrots: Int = player.carrots): MoveMistake? {
181+
fun validateTargetField(newPosition: Int, player: Hare = currentPlayer, carrots: Int = player.carrots): HuIMoveMistake? {
182182
if(newPosition == 0)
183-
return MoveMistake.CANNOT_ENTER_FIELD
183+
return HuIMoveMistake.CANNOT_ENTER_FIELD
184184
val field = board.getField(newPosition)
185185
if(field != Field.GOAL && newPosition == player.opponent.position)
186-
return MoveMistake.FIELD_OCCUPIED
186+
return HuIMoveMistake.FIELD_OCCUPIED
187187
when(field) {
188-
Field.SALAD -> player.salads > 0 || return MoveMistake.NO_SALAD
189-
Field.MARKET -> carrots >= 10 || return MoveMistake.MISSING_CARROTS
190-
Field.HARE -> player.getCards().isNotEmpty() || return MoveMistake.CARD_NOT_OWNED
191-
Field.GOAL -> carrots <= 10 && player.salads == 0 || return MoveMistake.GOAL_CONDITIONS
192-
Field.HEDGEHOG -> return MoveMistake.HEDGEHOG_ONLY_BACKWARDS
193-
null -> return MoveMistake.FIELD_NONEXISTENT
188+
Field.SALAD -> player.salads > 0 || return HuIMoveMistake.NO_SALAD
189+
Field.MARKET -> carrots >= 10 || return HuIMoveMistake.MISSING_CARROTS
190+
Field.HARE -> player.getCards().isNotEmpty() || return HuIMoveMistake.CARD_NOT_OWNED
191+
Field.GOAL -> carrots <= 10 && player.salads == 0 || return HuIMoveMistake.GOAL_CONDITIONS
192+
Field.HEDGEHOG -> return HuIMoveMistake.HEDGEHOG_ONLY_BACKWARDS
193+
null -> return HuIMoveMistake.FIELD_NONEXISTENT
194194
else -> return null
195195
}
196196
return null

plugin/src/main/kotlin/sc/plugin2025/Hare.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ data class Hare(
3232
position += distance
3333
}
3434

35-
fun consumeCarrots(count: Int): MoveMistake? =
35+
fun consumeCarrots(count: Int): HuIMoveMistake? =
3636
if(carrots < count) {
37-
MoveMistake.MISSING_CARROTS
37+
HuIMoveMistake.MISSING_CARROTS
3838
} else {
3939
carrots -= count
4040
null

0 commit comments

Comments
 (0)