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
|
- [ ] Clean up constants and private fields
|
||||||
- [ ] Move move() into Heading.move(Position)
|
- [ ] Move move() into Heading.move(Position)
|
||||||
- [ ] Move turnLeft() into Heading.turnLeft()
|
- [ ] Move turnLeft() into Heading.turnLeft()
|
||||||
- [ ] Move turnRight() into Heading.turnRight()
|
- [x] Move turnRight() into Heading.turnRight()
|
||||||
- [x] Remove HEADING_* constants
|
- [x] Remove HEADING_* constants
|
||||||
- [x] in move() compare to heading enum
|
- [x] in move() compare to heading enum
|
||||||
- [x] in turnRight() compare to heading enum
|
- [x] in turnRight() compare to heading enum
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,13 @@ enum class Heading(val symbol: Char) {
|
||||||
WEST('W'),
|
WEST('W'),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
fun turnRight() = when (this) {
|
||||||
|
EAST -> SOUTH
|
||||||
|
SOUTH -> WEST
|
||||||
|
WEST -> NORTH
|
||||||
|
NORTH -> EAST
|
||||||
|
}
|
||||||
|
|
||||||
override fun toString(): String = symbol.toString()
|
override fun toString(): String = symbol.toString()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,7 @@ class Rover {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun turnRight() {
|
private fun turnRight() {
|
||||||
when (state.heading) {
|
state.heading = state.heading.turnRight()
|
||||||
Heading.EAST -> state.heading = Heading.SOUTH
|
|
||||||
Heading.SOUTH -> state.heading = Heading.WEST
|
|
||||||
Heading.WEST -> state.heading = Heading.NORTH
|
|
||||||
Heading.NORTH -> state.heading = Heading.EAST
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun turnLeft() {
|
private fun turnLeft() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue