aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2020-08-31 04:44:24 +0200
committerJoop Kiefte <ikojba@gmail.com>2020-08-31 04:44:24 +0200
commitd4ba62ce1cd608d751a9d5db2e30608687a2e58e (patch)
treedfdb8683c56709bedc5d50cb03cdb8fa557d5e8f
parent66895e61fb6f6adebd04fa3c041e89ddb37725d2 (diff)
Testing movement -- adding movement cases
-rw-r--r--main.go29
1 files changed, 23 insertions, 6 deletions
diff --git a/main.go b/main.go
index 20ffc61..fb8d913 100644
--- a/main.go
+++ b/main.go
@@ -64,12 +64,13 @@ func (f Field) String() (output string) {
func main() {
var f Field
fmt.Print("\033[2J") // Clear screen
- for i := 0; i < 200; i++ {
- if (i+i/10)%2 == 0 {
- f[i/10][i%10] = true
- }
- }
+ p := Point{}
+ var oldp Point
for {
+ fmt.Print("\033[2J") // Clear screen
+ f[oldp.Y][oldp.X] = false
+ oldp = p
+ f[p.Y][p.X] = true
fmt.Print("\033[0;0H") // Position to 0,0
fmt.Println(f.String())
t, _ := term.Open("/dev/tty")
@@ -80,10 +81,26 @@ func main() {
t.Close()
switch key[0] {
case 27: // Escape, read the arrow key pressed
- fmt.Print(string(key[2]))
+ switch key[2] {
+ case 65: // Up
+ p.Y = (p.Y + 20 - 1)%20
+ case 66: // Down
+ p.Y = (p.Y + 20 + 1)%20
+ case 67: // Right
+ p.X = (p.X + 10 + 1)%10
+ case 68: // Left
+ p.X = (p.X + 10 - 1)%10
+ default:
+ fmt.Println("...escape, escape!")
+ return
+ }
case 'q':
fmt.Println("...that was exciting!")
return
+ default:
+ if key[0] != 0 {
+ fmt.Print(string(key[0]))
+ }
}
}
}