Skip to content

Commit

Permalink
feat - 이동 가능 여부 역할 플레이어 객체에게 위임
Browse files Browse the repository at this point in the history
  • Loading branch information
Stark-Industries0417 committed Feb 3, 2025
1 parent 3a4f5f0 commit 6bec6a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 5 additions & 0 deletions game-server/src/main/kotlin/game/server/Player.kt
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
}
}

0 comments on commit 6bec6a8

Please sign in to comment.