diff options
| author | nic-gaffney <gaffney_nic@protonmail.com> | 2023-04-27 17:19:54 -0500 |
|---|---|---|
| committer | nic-gaffney <gaffney_nic@protonmail.com> | 2023-04-27 17:19:54 -0500 |
| commit | ac8c9abab30d66ff208a623d0a6de8869373a554 (patch) | |
| tree | 8d2d20d9a5312a1e2fad73d9a6ee7294b0c27dc2 /examples/snake.sloth | |
| parent | 757e804671ef3dcb2e0f1295e385780b5feae2ca (diff) | |
| parent | af02ccd056754c60131d13d74b9fac0e23b2af31 (diff) | |
| download | sloth-ac8c9abab30d66ff208a623d0a6de8869373a554.tar.gz | |
Merge branch 'standard-library' of github.com-Nic:slothlang/sloth into standard-library
Diffstat (limited to 'examples/snake.sloth')
| -rw-r--r-- | examples/snake.sloth | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/snake.sloth b/examples/snake.sloth new file mode 100644 index 0000000..c60819d --- /dev/null +++ b/examples/snake.sloth @@ -0,0 +1,40 @@ +var xPos = 0; +var yPos = 0; +# 0=right 1=down 2=left 3=up +var direction = 0; + +while true { + if direction == 0{ + var x = xPos + 1; + xPos = x; + } + if direction == 1 { + var y = yPos + 1; + yPos = y; + } + if direction == 2{ + var x = xPos - 1; + xPos = x; + } + if direction == 3 { + var y = yPos - 1; + yPos = y; + } + + var input = readln(); + if input == "w" && direction != 1 { + direction = 3; + } + if input == "a" && direction != 0 { + direction = 2; + } + if input == "s" && direction != 3 { + direction = 1; + } + if input == "d" && direction != 2 { + direction = 0; + } + + term_setpos(x, y); + print("*"); +} |
