aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2020-08-31 04:27:04 +0200
committerJoop Kiefte <ikojba@gmail.com>2020-08-31 04:27:04 +0200
commit66895e61fb6f6adebd04fa3c041e89ddb37725d2 (patch)
treefe4b41c711c53def6d18fefd2af394469dd4c60f
parente7099a6f597f227cf141f621e28dcc2acf64fdf3 (diff)
... nope, still not a working game, but I got the key reading figured out
-rw-r--r--go.mod2
-rw-r--r--go.sum2
-rw-r--r--main.go36
3 files changed, 36 insertions, 4 deletions
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
+ }
}
}