diff options
author | Joop Kiefte <ikojba@gmail.com> | 2020-09-07 01:34:57 +0200 |
---|---|---|
committer | Joop Kiefte <ikojba@gmail.com> | 2020-09-07 01:34:57 +0200 |
commit | 295f19e88a7a7ebd1de019b091a362324a369809 (patch) | |
tree | 6833e4832e44b6ede9c780c429fa36f28effef02 /main.go | |
parent | 749ecb0e4ed365be186ad3ee65c8a04634ac247b (diff) |
Working demov0.0.3
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 34 |
1 files changed, 20 insertions, 14 deletions
@@ -13,7 +13,7 @@ func GetKey() []byte { t, _ := term.Open("/dev/tty") term.RawMode(t) key := make([]byte, 3) - t.SetReadTimeout(time.Second / 60) + t.SetReadTimeout(time.Second / 1000) t.Read(key) t.Restore() t.Close() @@ -24,27 +24,37 @@ func main() { var f tris.Field fmt.Print("\033[2J") // Clear screen b := tris.NewBag() - p := b.Pick() + b, p := b.Pick() + t := time.Tick(time.Second / 60) + ds := time.NewTicker(time.Second / 10) for { -// fmt.Print("\033[2J") // Clear screen - if p.Lock <= 0 { - f = f.Add(p) - p = b.Pick() - } + fmt.Print("\033[2J") // Clear screen fmt.Print("\033[0;0H") // Position to 0,0 fmt.Println(f.Add(p).String()) - if !p.Drop(f) { - fmt.Println("Should drop one") - p.Lock-- + select { + case <-ds.C: + np, ok := p.Drop(f) + if ok { + p = np + p.Lock = time.Now() + } + if time.Now().Sub(p.Lock) > tris.LockDelay { + f = f.Add(p) + b, p = b.Pick() + } + case <-t: } key := GetKey() switch key[0] { case 27: // Escape, read the arrow key pressed switch key[2] { case 65: // Up + p.Rot = (p.Rot + 1)%4 case 66: // Down case 67: // Right + p.X++ case 68: // Left + p.X-- default: fmt.Println("...escape, escape!") return @@ -55,10 +65,6 @@ func main() { case 'Q': fmt.Println("...never let an engineer pick the name of your software?") return - default: - if key[0] != 0 { - fmt.Print(string(key[0])) - } } } } |