Skip to content

Commit

Permalink
refactor - direction String에서 ENUM 선언
Browse files Browse the repository at this point in the history
  • Loading branch information
Stark-Industries0417 committed Jan 31, 2025
1 parent dcbb931 commit 6ce1424
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions game-server/src/main/kotlin/game/server/dto/Direction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package game.server.dto

enum class Direction {
UP, DOWN, LEFT, RIGHT
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import game.server.domain.Position

data class PlayerMoveRequest(
val currentPosition: Position,
val direction: String,
val direction: Direction,
val speed: Int
) : Request
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package game.server.handler

import com.fasterxml.jackson.databind.ObjectMapper
import game.server.Player
import game.server.domain.Position
import game.server.dto.Direction
import game.server.dto.Direction.*
import game.server.dto.PlayerMoveRequest
import game.server.dto.response.ApiResponse
import game.server.dto.response.Error
Expand Down Expand Up @@ -37,13 +38,12 @@ class PlayerMoveHandler(
}
}

private fun calculateNewPosition(x: Int, y: Int, direction: String, speed: Int): Position {
private fun calculateNewPosition(x: Int, y: Int, direction: Direction, speed: Int): Position {
return when (direction) {
"UP" -> Position(x, y - speed)
"DOWN" -> Position(x, y + speed)
"LEFT" -> Position(x - speed, y)
"RIGHT" -> Position(x + speed, y)
else -> Position(x, y)
UP -> Position(x, y - speed)
DOWN -> Position(x, y + speed)
LEFT -> Position(x - speed, y)
RIGHT -> Position(x + speed, y)
}
}

Expand Down

0 comments on commit 6ce1424

Please sign in to comment.