R: Heading.turnRight()
This commit is contained in:
parent
9243088b88
commit
3e71bcf1af
3 changed files with 9 additions and 7 deletions
|
|
@ -7,7 +7,7 @@
|
|||
- [ ] Clean up constants and private fields
|
||||
- [ ] Move move() into Heading.move(Position)
|
||||
- [ ] Move turnLeft() into Heading.turnLeft()
|
||||
- [ ] Move turnRight() into Heading.turnRight()
|
||||
- [x] Move turnRight() into Heading.turnRight()
|
||||
- [x] Remove HEADING_* constants
|
||||
- [x] in move() compare to heading enum
|
||||
- [x] in turnRight() compare to heading enum
|
||||
|
|
|
|||
|
|
@ -7,6 +7,13 @@ enum class Heading(val symbol: Char) {
|
|||
WEST('W'),
|
||||
;
|
||||
|
||||
fun turnRight() = when (this) {
|
||||
EAST -> SOUTH
|
||||
SOUTH -> WEST
|
||||
WEST -> NORTH
|
||||
NORTH -> EAST
|
||||
}
|
||||
|
||||
override fun toString(): String = symbol.toString()
|
||||
|
||||
companion object {
|
||||
|
|
|
|||
|
|
@ -30,12 +30,7 @@ class Rover {
|
|||
}
|
||||
|
||||
private fun turnRight() {
|
||||
when (state.heading) {
|
||||
Heading.EAST -> state.heading = Heading.SOUTH
|
||||
Heading.SOUTH -> state.heading = Heading.WEST
|
||||
Heading.WEST -> state.heading = Heading.NORTH
|
||||
Heading.NORTH -> state.heading = Heading.EAST
|
||||
}
|
||||
state.heading = state.heading.turnRight()
|
||||
}
|
||||
|
||||
private fun turnLeft() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue