Dodalem biblioteke ktora pomoze mi w keyaction
This commit is contained in:
parent
5a3ca97d0a
commit
273bed1e15
33
Pong.go
33
Pong.go
@ -1,10 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"bytes"
|
||||
"github.com/pkg/term"
|
||||
)
|
||||
|
||||
var gameBoard [10][30]string
|
||||
@ -20,7 +21,8 @@ var GameOver bool = false
|
||||
var LastPressedKey rune
|
||||
|
||||
func main() {
|
||||
SpawnEverything()
|
||||
// SpawnEverything()
|
||||
loop2()
|
||||
}
|
||||
|
||||
func SpawnEverything() {
|
||||
@ -31,6 +33,19 @@ func SpawnEverything() {
|
||||
Loop()
|
||||
}
|
||||
|
||||
func getch() []byte {
|
||||
t, _ := term.Open("/dev/tty")
|
||||
term.RawMode(t)
|
||||
bytes := make([]byte, 3)
|
||||
numRead, err := t.Read(bytes)
|
||||
t.Restore()
|
||||
t.Close()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return bytes[0:numRead]
|
||||
}
|
||||
|
||||
func CreateBoard() {
|
||||
for i = 0; i < 10; i++ {
|
||||
for j = 0; j < 30; j++ {
|
||||
@ -97,3 +112,17 @@ func Loop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func loop2() {
|
||||
for !GameOver {
|
||||
c:=getch()
|
||||
switch {
|
||||
case bytes.Equal(c, []byte{3}):
|
||||
return
|
||||
case bytes.Equal(c, []byte{27, 91, 68}):
|
||||
fmt.Println("Left pressed")
|
||||
default:
|
||||
PrintBoard()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user