From 66895e61fb6f6adebd04fa3c041e89ddb37725d2 Mon Sep 17 00:00:00 2001 From: Joop Kiefte Date: Mon, 31 Aug 2020 04:27:04 +0200 Subject: ... nope, still not a working game, but I got the key reading figured out --- main.go | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index a436135..20ffc61 100644 --- a/main.go +++ b/main.go @@ -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 + } } } -- cgit v1.2.3-70-g09d2