Compare commits
No commits in common. "b2928ec07302edd6f7e4319a1be4d532521e0aa3" and "78d73a792064e269dbeb9bb2f27e20c1b7234931" have entirely different histories.
b2928ec073
...
78d73a7920
23
render.go
23
render.go
@ -1,23 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "github.com/gdamore/tcell/v2"
|
|
||||||
|
|
||||||
/*
|
|
||||||
func renderScreen(&screen tcell.Screen, event tcell.Event, score int) {
|
|
||||||
if checkSize(*screen) == false {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func checkSize(screen tcell.Screen) bool {
|
|
||||||
var retval bool = true
|
|
||||||
x, y := screen.Size()
|
|
||||||
if x < 80 {
|
|
||||||
retval = false
|
|
||||||
}
|
|
||||||
if y < 24 {
|
|
||||||
retval = false
|
|
||||||
}
|
|
||||||
return retval
|
|
||||||
}
|
|
@ -1,24 +1,27 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func updateScore(screen tcell.Screen, style tcell.Style, score int) {
|
func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string) {
|
||||||
var x, y int
|
row := y1
|
||||||
_, y = screen.Size()
|
col := x1
|
||||||
x = 5
|
for _, r := range []rune(text) {
|
||||||
for _, r := range []rune("[ Score: " + strconv.FormatInt(int64(score), 10) + " ]") {
|
s.SetContent(col, row, r, nil, style)
|
||||||
screen.SetContent(x, y-1, r, nil, style)
|
col++
|
||||||
x++
|
if col >= x2 {
|
||||||
|
row++
|
||||||
|
col = x1
|
||||||
|
}
|
||||||
|
if row > y2 {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawBox(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style) {
|
func drawBox(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string) {
|
||||||
if y2 < y1 {
|
if y2 < y1 {
|
||||||
y1, y2 = y2, y1
|
y1, y2 = y2, y1
|
||||||
}
|
}
|
||||||
@ -51,13 +54,13 @@ func drawBox(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style) {
|
|||||||
s.SetContent(x2, y2, '╝', nil, style)
|
s.SetContent(x2, y2, '╝', nil, style)
|
||||||
}
|
}
|
||||||
|
|
||||||
//drawText(s, x1+1, y1+1, x2-1, y2-1, style, text)
|
drawText(s, x1+1, y1+1, x2-1, y2-1, style, text)
|
||||||
updateScore(s, style, 10)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// info, err := tcell.LookupTerminfo(os.Getenv("TERM"))
|
||||||
defaultStyle := tcell.StyleDefault.Background(tcell.ColorReset).Foreground(tcell.ColorReset)
|
defStyle := tcell.StyleDefault.Background(tcell.ColorReset).Foreground(tcell.ColorReset)
|
||||||
|
//boxStyle := tcell.StyleDefault.Foreground(tcell.ColorWhite).Background(tcell.ColorPurple)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@ -74,7 +77,7 @@ func main() {
|
|||||||
|
|
||||||
screen.Clear()
|
screen.Clear()
|
||||||
|
|
||||||
drawBox(screen, 0, 0, x-1, y-1, defaultStyle)
|
drawBox(screen, 0, 0, x-1, y-1, defStyle, "There should be worms here!")
|
||||||
|
|
||||||
quit := func() {
|
quit := func() {
|
||||||
// You have to catch panics in a defer, clean up, and
|
// You have to catch panics in a defer, clean up, and
|
||||||
@ -94,14 +97,13 @@ func main() {
|
|||||||
switch ev := ev.(type) {
|
switch ev := ev.(type) {
|
||||||
case *tcell.EventResize:
|
case *tcell.EventResize:
|
||||||
x, y := screen.Size()
|
x, y := screen.Size()
|
||||||
drawBox(screen, 0, 0, x-1, y-1, defaultStyle)
|
drawBox(screen, 0, 0, x-1, y-1, defStyle, "There should be worms here!")
|
||||||
fmt.Println("size=ok:", checkSize(screen))
|
|
||||||
screen.Sync()
|
screen.Sync()
|
||||||
case *tcell.EventKey:
|
case *tcell.EventKey:
|
||||||
//fmt.Println("Key: ",ev.Rune())
|
//fmt.Println("Key: ",ev.Rune())
|
||||||
if ev.Key() == tcell.KeyEscape || ev.Key() == tcell.KeyCtrlC {
|
if ev.Key() == tcell.KeyEscape || ev.Key() == tcell.KeyCtrlC {
|
||||||
return
|
return
|
||||||
} else if ev.Rune() == 'q' || ev.Rune() == 'Q' {
|
} else if ev.Rune() == 'q' {
|
||||||
return
|
return
|
||||||
} else if ev.Key() == tcell.KeyCtrlL {
|
} else if ev.Key() == tcell.KeyCtrlL {
|
||||||
screen.Sync()
|
screen.Sync()
|
Loading…
x
Reference in New Issue
Block a user