diff options
author | Joop Kiefte <ikojba@gmail.com> | 2020-08-31 04:27:04 +0200 |
---|---|---|
committer | Joop Kiefte <ikojba@gmail.com> | 2020-08-31 04:27:04 +0200 |
commit | 66895e61fb6f6adebd04fa3c041e89ddb37725d2 (patch) | |
tree | fe4b41c711c53def6d18fefd2af394469dd4c60f /main.go | |
parent | e7099a6f597f227cf141f621e28dcc2acf64fdf3 (diff) |
... nope, still not a working game, but I got the key reading figured out
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 36 |
1 files changed, 32 insertions, 4 deletions
@@ -2,13 +2,13 @@ package main import ( "fmt" - "time" + "github.com/pkg/term" ) -type Piece int +type PieceType int const ( - IPiece Piece = iota + IPiece PieceType = iota JPiece LPiece SPiece @@ -17,6 +17,20 @@ const ( OPiece ) +type Point struct { + X, Y int +} + +type Piece struct { + Type PieceType + RelX int + RelY int + Layout []Point + Lock int +} + +type Bag []Piece + type Field [20][10]bool func (f Field) String() (output string) { @@ -54,8 +68,22 @@ func main() { if (i+i/10)%2 == 0 { f[i/10][i%10] = true } + } + for { fmt.Print("\033[0;0H") // Position to 0,0 fmt.Println(f.String()) - time.Sleep(time.Second/1000) + t, _ := term.Open("/dev/tty") + term.RawMode(t) + key := make([]byte, 3) + t.Read(key) + t.Restore() + t.Close() + switch key[0] { + case 27: // Escape, read the arrow key pressed + fmt.Print(string(key[2])) + case 'q': + fmt.Println("...that was exciting!") + return + } } } |