aboutsummaryrefslogtreecommitdiff
path: root/examples/snake.sloth
diff options
context:
space:
mode:
authorNic Gaffney <gaffney_nic@protonmail.com>2023-06-28 16:21:15 -0500
committerNic Gaffney <gaffney_nic@protonmail.com>2023-06-28 16:21:15 -0500
commit73843fa284968b4efb0ae51858cb37d0189c4b83 (patch)
tree278982b5b0b8fdb933d5d57f801145ab7cbf99aa /examples/snake.sloth
parent7d14243f769ad911d7c057b891ed89a95d7c1bfd (diff)
downloadsloth-73843fa284968b4efb0ae51858cb37d0189c4b83.tar.gz
filer added to std
Diffstat (limited to 'examples/snake.sloth')
-rw-r--r--examples/snake.sloth81
1 files changed, 43 insertions, 38 deletions
diff --git a/examples/snake.sloth b/examples/snake.sloth
index c60819d..8283368 100644
--- a/examples/snake.sloth
+++ b/examples/snake.sloth
@@ -1,40 +1,45 @@
-var xPos = 0;
-var yPos = 0;
-# 0=right 1=down 2=left 3=up
-var direction = 0;
+fn main() Int {
+ var xPos: Int = 0;
+ var yPos: Int = 0;
+ # 0=right 1=down 2=left 3=up
+ var direction: Int = 0;
+ var x: Int = 0;
+ var y: Int = 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("*");
+ while true {
+ if direction == 0{
+ x = xPos + 1;
+ xPos = x;
+ }
+ if direction == 1 {
+ y = yPos + 1;
+ yPos = y;
+ }
+ if direction == 2{
+ x = xPos - 1;
+ xPos = x;
+ }
+ if direction == 3 {
+ y = yPos - 1;
+ yPos = y;
+ }
+
+ var input: String = 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;
+ }
+
+ termpos(x, y);
+ print("*");
+ }
+ return 0;
}