diff --git a/TECHDEBT.md b/TECHDEBT.md index f6b4d03..a6bdd83 100644 --- a/TECHDEBT.md +++ b/TECHDEBT.md @@ -6,7 +6,7 @@ # Mikado - [ ] Clean up constants and private fields - [ ] Move move() into Heading.move(Position) - - [ ] Move turnLeft() into Heading.turnLeft() + - [x] Move turnLeft() into Heading.turnLeft() - [x] Move turnRight() into Heading.turnRight() - [x] Remove HEADING_* constants - [x] in move() compare to heading enum diff --git a/src/main/kotlin/org/example/Heading.kt b/src/main/kotlin/org/example/Heading.kt index 98d7ece..87a5088 100644 --- a/src/main/kotlin/org/example/Heading.kt +++ b/src/main/kotlin/org/example/Heading.kt @@ -7,6 +7,13 @@ enum class Heading(val symbol: Char) { WEST('W'), ; + fun turnLeft() = when (this) { + EAST -> NORTH + NORTH -> WEST + WEST -> SOUTH + SOUTH -> EAST + } + fun turnRight() = when (this) { EAST -> SOUTH SOUTH -> WEST diff --git a/src/main/kotlin/org/example/Rover.kt b/src/main/kotlin/org/example/Rover.kt index ba57605..3afa41b 100644 --- a/src/main/kotlin/org/example/Rover.kt +++ b/src/main/kotlin/org/example/Rover.kt @@ -34,12 +34,7 @@ class Rover { } private fun turnLeft() { - when (state.heading) { - Heading.EAST -> state.heading = Heading.NORTH - Heading.NORTH -> state.heading = Heading.WEST - Heading.WEST -> state.heading = Heading.SOUTH - Heading.SOUTH -> state.heading = Heading.EAST - } + state.heading = state.heading.turnLeft() } val position: String