R: Heading turnLeft()
This commit is contained in:
parent
3e71bcf1af
commit
a56304bc77
3 changed files with 9 additions and 7 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
# Mikado
|
# Mikado
|
||||||
- [ ] 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()
|
- [x] Move turnLeft() into Heading.turnLeft()
|
||||||
- [x] 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
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,13 @@ enum class Heading(val symbol: Char) {
|
||||||
WEST('W'),
|
WEST('W'),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
fun turnLeft() = when (this) {
|
||||||
|
EAST -> NORTH
|
||||||
|
NORTH -> WEST
|
||||||
|
WEST -> SOUTH
|
||||||
|
SOUTH -> EAST
|
||||||
|
}
|
||||||
|
|
||||||
fun turnRight() = when (this) {
|
fun turnRight() = when (this) {
|
||||||
EAST -> SOUTH
|
EAST -> SOUTH
|
||||||
SOUTH -> WEST
|
SOUTH -> WEST
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,7 @@ class Rover {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun turnLeft() {
|
private fun turnLeft() {
|
||||||
when (state.heading) {
|
state.heading = state.heading.turnLeft()
|
||||||
Heading.EAST -> state.heading = Heading.NORTH
|
|
||||||
Heading.NORTH -> state.heading = Heading.WEST
|
|
||||||
Heading.WEST -> state.heading = Heading.SOUTH
|
|
||||||
Heading.SOUTH -> state.heading = Heading.EAST
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val position: String
|
val position: String
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue