Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jun 14, 2024
1 parent 6e8aa72 commit 0f17e21
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ enum class SnakeMove(val dir: PointInt) {
val isVertical get() = dir.y != 0
}

data class Snake(val pos: List<PointInt>) {
data class Snake(val pos: List<PointInt>, val maxLen: Int = 10) {
fun withExtraMove(move: SnakeMove): Snake {
return Snake((pos + (pos.last() + move.dir)).takeLast(10))
return Snake((pos + (pos.last() + move.dir)).takeLast(maxLen), maxLen)
}

fun pos(index: Int): PointInt = pos.getOrElse(index) { PointInt(0, 0) }
Expand Down Expand Up @@ -183,7 +183,9 @@ data class Snake(val pos: List<PointInt>) {
//println("$p0, $p1")
}
}
map.push(p.x, p.y, tile)
if (map.inside(p.x, p.y)) {
map.push(p.x, p.y, tile)
}
}
}
}

0 comments on commit 0f17e21

Please sign in to comment.