diff options
author | Joop Kiefte <ikojba@gmail.com> | 2020-09-12 09:05:28 +0200 |
---|---|---|
committer | Joop Kiefte <ikojba@gmail.com> | 2020-09-12 09:05:28 +0200 |
commit | 3edb4c1779ae23dd976c067622f2aaee9ac98f5d (patch) | |
tree | 9289f2b2a674ab11bb6eed6dbead64810d567497 /main.go | |
parent | ac3196415d5d87a745d339f1548573b0b5745c41 (diff) |
Mostly playable now -- kicks still missing and problem with floor detection L piece
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -22,18 +22,19 @@ func GetKey() []byte { func main() { var f tris.Field - var floor, topout bool + var floor, topout, harddrop bool var x, y int var rot tris.Rotation fmt.Print("\033[2J") // Clear screen b := tris.NewBag() b, p := b.Pick() - t := time.Tick(time.Second / 60) + t := time.Tick(time.Second) for { x, y, rot = p.X, p.Y, p.Rot fmt.Print("\033[0;0H") // Position to 0,0 fmt.Println(f.Add(p).String()) key := GetKey() + if harddrop { key[0] = ' ' } switch key[0] { case 27: // Escape, read the arrow key pressed switch key[2] { @@ -54,7 +55,7 @@ func main() { case 'z': rot = (p.Rot + 3)%4 case ' ': - y = 20 + harddrop = true case 'q': fmt.Println("...that was exciting!") return @@ -66,11 +67,21 @@ func main() { case <-t: y = p.Y + 1 default: + if harddrop { + y = p.Y + 1 + } } p, floor, topout = p.Move(f, rot, x, y) if floor && p.Lock.Add(tris.LockDelay).Before(time.Now()) { - fmt.Print("\033[2J") // Clear screen + harddrop = false + var l int f = f.Add(p) + l, f = f.Lines() + if l > 0 { + fmt.Println(l, " lines removed!") + time.Sleep(time.Second) + } + fmt.Print("\033[2J") // Clear screen b, p = b.Pick() } if !floor { |