diff --git a/game-server/src/main/kotlin/game/server/Player.kt b/game-server/src/main/kotlin/game/server/Player.kt index 334bba2..a4ee28d 100644 --- a/game-server/src/main/kotlin/game/server/Player.kt +++ b/game-server/src/main/kotlin/game/server/Player.kt @@ -1,6 +1,8 @@ package game.server import game.server.domain.Position +import game.server.handler.CANVAS_HEIGHT +import game.server.handler.CANVAS_WIDTH import org.springframework.stereotype.Component @@ -11,4 +13,7 @@ class Player( val speed: Int = 5 ) { var position = Position(400, 300) + + fun isMoveAllowed(x: Int, y: Int) = + x in 0 until CANVAS_WIDTH && y in 0 until CANVAS_HEIGHT } \ No newline at end of file diff --git a/game-server/src/main/kotlin/game/server/handler/PlayerMoveHandler.kt b/game-server/src/main/kotlin/game/server/handler/PlayerMoveHandler.kt index 25f49d1..7249c92 100644 --- a/game-server/src/main/kotlin/game/server/handler/PlayerMoveHandler.kt +++ b/game-server/src/main/kotlin/game/server/handler/PlayerMoveHandler.kt @@ -28,7 +28,7 @@ class PlayerMoveHandler( val (currentX, currentY) = request.data.currentPosition val (newX, newY) = calculateNewPosition(currentX, currentY, request.data.direction, request.data.speed) - val isAllowed = isMoveAllowed(newX, newY) + val isAllowed = player.isMoveAllowed(newX, newY) return if (isAllowed) { player.position = Position(newX, newY) Response( @@ -51,8 +51,4 @@ class PlayerMoveHandler( RIGHT -> Position(x + speed, y) } } - - private fun isMoveAllowed(x: Int, y: Int): Boolean { - return x in 0 until CANVAS_WIDTH && y in 0 until CANVAS_HEIGHT - } } \ No newline at end of file