aboutsummaryrefslogtreecommitdiff
path: root/examples/snake.sloth
blob: 8283368247e25956d6c47508000359d6c9328ca5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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{
            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;
}