Skip to content

Commit 05ef158

Browse files
TomekRDxeruf
authored andcommitted
feat(plugin26): Added MoveMistake to GameRuleLogic.kt
1 parent 838675f commit 05ef158

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

plugin2026/src/main/kotlin/sc/plugin2026/util/GameRuleLogic.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import sc.plugin2026.Field
77
import sc.plugin2026.FieldState
88
import sc.plugin2026.Move
99
import sc.shared.InvalidMoveException
10+
import sc.shared.MoveMistake
1011

1112
class GameRuleLogic private constructor() {
1213
init {
@@ -45,13 +46,13 @@ class GameRuleLogic private constructor() {
4546

4647
@Throws(InvalidMoveException::class)
4748
fun isValidToMove(
48-
state: sc.plugin2019.GameState,
49+
state: sc.plugin2026.GameState,
4950
x: Int,
5051
y: Int,
5152
direction: Direction,
5253
distance: Int
5354
): Boolean {
54-
if(x >= PiranhaConstants.BOARD_LENGTH || y >= PiranhaConstants.BOARD_LENGTH || x < 0 || y < 0) throw InvalidMoveException("x or y are not within the field range")
55+
if(x >= PiranhaConstants.BOARD_LENGTH || y >= PiranhaConstants.BOARD_LENGTH || x < 0 || y < 0) throw InvalidMoveException(MoveMistake.OUT_OF_BOUNDS)
5556
val board = state.board
5657
val curField: Field = board.getField(x, y)
5758
val curFieldPlayer: java.util.Optional<Team> = curField.piranha
@@ -66,13 +67,13 @@ class GameRuleLogic private constructor() {
6667
y,
6768
direction
6869
) != distance
69-
) throw InvalidMoveException("Move distance was incorrect")
70+
) throw InvalidMoveException(MoveMistake.INVALID_MOVEMENT)
7071

7172
val nextField: Field
7273
try {
7374
nextField = getFieldInDirection(board, x, y, direction, distance)
7475
} catch(e: ArrayIndexOutOfBoundsException) {
75-
throw InvalidMoveException("Move in that direction would not be on the board")
76+
throw InvalidMoveException(MoveMistake.OUT_OF_BOUNDS)
7677
}
7778

7879
val fieldsInDirection = getFieldsInDirection(board, x, y, direction)
@@ -87,7 +88,7 @@ class GameRuleLogic private constructor() {
8788

8889
val nextFieldPlayer: java.util.Optional<Team> = nextField.piranha
8990
if(nextFieldPlayer.isPresent() && nextFieldPlayer.get() === state.getCurrentTeam()) {
90-
throw InvalidMoveException("Field obstructed with own piranha")
91+
throw InvalidMoveException(MoveMistake.DESTINATION_BLOCKED)
9192
}
9293
if(nextField.isObstructed) {
9394
throw InvalidMoveException("Field is obstructed")

0 commit comments

Comments
 (0)