diff options
author | Joop Kiefte <ikojba@gmail.com> | 2020-09-06 23:52:28 +0200 |
---|---|---|
committer | Joop Kiefte <ikojba@gmail.com> | 2020-09-06 23:52:28 +0200 |
commit | 749ecb0e4ed365be186ad3ee65c8a04634ac247b (patch) | |
tree | b5488340a8d814b9e51d1dc79bf0118e2eb42003 | |
parent | e2bf8762f96dfdfef05ac22d9b2bdfa1ab926c59 (diff) |
Dropping piece demov0.0.2
-rw-r--r-- | main.go | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -2,8 +2,9 @@ package main import ( "fmt" - "github.com/pkg/term" "git.kiefte.eu/lapingvino/clitris/tris" + "github.com/pkg/term" + "time" ) // GetKey() returns the key currently pressed. It always returns a 3 byte slice. Check first element for Escape for handling arrow keys @@ -12,6 +13,7 @@ func GetKey() []byte { t, _ := term.Open("/dev/tty") term.RawMode(t) key := make([]byte, 3) + t.SetReadTimeout(time.Second / 60) t.Read(key) t.Restore() t.Close() @@ -21,26 +23,28 @@ func GetKey() []byte { func main() { var f tris.Field fmt.Print("\033[2J") // Clear screen - var p, oldp tris.Point + b := tris.NewBag() + p := b.Pick() for { - fmt.Print("\033[2J") // Clear screen - f[oldp.Y][oldp.X] = false - oldp = p - f[p.Y][p.X] = true +// fmt.Print("\033[2J") // Clear screen + if p.Lock <= 0 { + f = f.Add(p) + p = b.Pick() + } fmt.Print("\033[0;0H") // Position to 0,0 - fmt.Println(f.String()) + fmt.Println(f.Add(p).String()) + if !p.Drop(f) { + fmt.Println("Should drop one") + p.Lock-- + } key := GetKey() switch key[0] { case 27: // Escape, read the arrow key pressed 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 |