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 --- go.mod | 2 ++ go.sum | 2 ++ main.go | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 go.sum diff --git a/go.mod b/go.mod index 4f649a8..b1a54d4 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module git.kiefte.eu/lapingvino/clitris go 1.15 + +require github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ea41137 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03 h1:pd4YKIqCB0U7O2I4gWHgEUA2mCEOENmco0l/bM957bU= +github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03/go.mod h1:Z9+Ul5bCbBKnbCvdOWbLqTHhJiYV414CURZJba6L8qA= 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