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 | |
parent | e7099a6f597f227cf141f621e28dcc2acf64fdf3 (diff) |
... nope, still not a working game, but I got the key reading figured out
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | go.sum | 2 | ||||
-rw-r--r-- | main.go | 36 |
3 files changed, 36 insertions, 4 deletions
@@ -1,3 +1,5 @@ module git.kiefte.eu/lapingvino/clitris go 1.15 + +require github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03 // indirect @@ -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= @@ -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 + } } } |