aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--new_game.go24
-rw-r--r--utils/helper/incremental_print.go19
-rw-r--r--utils/ncfmt/effects.go (renamed from utils/helper/effects.go)2
-rw-r--r--utils/ncfmt/incremental_print.go30
4 files changed, 38 insertions, 37 deletions
diff --git a/new_game.go b/new_game.go
index 1a24cbc..eb9710e 100644
--- a/new_game.go
+++ b/new_game.go
@@ -5,7 +5,7 @@ import (
"time"
. "github.com/gbin/goncurses"
- "gitlab.com/stvnliu/ai_game/utils/helper"
+ "gitlab.com/stvnliu/ai_game/utils/ncfmt"
. "gitlab.com/stvnliu/ai_game/utils/types"
"gitlab.com/stvnliu/ai_game/utils/windows"
)
@@ -14,17 +14,7 @@ const (
STD_BLINK_INTERVAL = 450 * time.Millisecond
)
-func IncrementalPrintMany(
- w *Window,
- y int,
- x int,
- texts []string,
- duration time.Duration,
-) {
- for i := 0; i < len(texts); i++ {
- helper.IncrementalPrint(w, texts[i], y+i, x, int(1*time.Second))
- }
-}
+
func NewGame(scr *Window) {
//_, _ := scr.MaxYX()
game_name := windows.InputPrompt(scr, " New game information ", "Game name: ", 20)
@@ -67,11 +57,11 @@ func NewGame(scr *Window) {
"============ Copyright 2024 @ Zhongheng Liu & Zhiyong He =============",
"Please wait while we boot some AI models for the first part of the game...",
}
- IncrementalPrintMany(w, 1, 1, texts, time.Duration(1*time.Second))
+ ncfmt.IncrementalPrintMany(w, 1, 1, texts, time.Duration(1*time.Second))
init_done := make(chan bool, 1)
- go helper.BlinkCursorUntilDone(
+ go ncfmt.BlinkCursorUntilDone(
w,
len(texts)+1,
1,
@@ -86,8 +76,8 @@ func NewGame(scr *Window) {
"Ok we are done with everything!",
"Now try putting something in the input box below!",
}
- IncrementalPrintMany(w, len(texts)+1, 1, texts2, time.Duration(1*time.Second))
- key := helper.BlinkCursorUntilInput(input_window, 1, 3, STD_BLINK_INTERVAL)
+ ncfmt.IncrementalPrintMany(w, len(texts)+1, 1, texts2, time.Duration(1*time.Second))
+ key := ncfmt.BlinkCursorUntilInput(input_window, 1, 3, STD_BLINK_INTERVAL)
Cursor(0)
my_input := "You said: "
for {
@@ -111,7 +101,7 @@ func NewGame(scr *Window) {
key = input_window.GetChar()
}
- helper.IncrementalPrint(w, my_input, 8, 1, int(time.Duration(1*time.Second)))
+ ncfmt.IncrementalPrint(w, my_input, 8, 1, int(time.Duration(1*time.Second)))
// User input processing
for {
ch := w.GetChar()
diff --git a/utils/helper/incremental_print.go b/utils/helper/incremental_print.go
deleted file mode 100644
index c94f904..0000000
--- a/utils/helper/incremental_print.go
+++ /dev/null
@@ -1,19 +0,0 @@
-package helper
-
-import (
- "time"
-
- . "github.com/gbin/goncurses"
-)
-
-func IncrementalPrint(scr *Window, text string, from_y int, from_x int, interval_millis int) {
- for i:=0; i < len(text); i++ {
- ch := string([]rune(text)[i])
- _, mx := scr.MaxYX()
- cy := i / mx + from_y
- cx := i % mx + 1
- scr.MovePrint(cy, cx, ch)
- time.Sleep( time.Duration(1000 / len(text)) * time.Millisecond)
- scr.Refresh()
- }
-}
diff --git a/utils/helper/effects.go b/utils/ncfmt/effects.go
index ff9a93a..170ed11 100644
--- a/utils/helper/effects.go
+++ b/utils/ncfmt/effects.go
@@ -1,4 +1,4 @@
-package helper
+package ncfmt
import (
"fmt"
diff --git a/utils/ncfmt/incremental_print.go b/utils/ncfmt/incremental_print.go
new file mode 100644
index 0000000..8ab0f05
--- /dev/null
+++ b/utils/ncfmt/incremental_print.go
@@ -0,0 +1,30 @@
+package ncfmt
+
+import (
+ "time"
+
+ . "github.com/gbin/goncurses"
+)
+
+func IncrementalPrintMany(
+ w *Window,
+ y int,
+ x int,
+ texts []string,
+ duration time.Duration,
+) {
+ for i := 0; i < len(texts); i++ {
+ IncrementalPrint(w, texts[i], y+i, x, int(1*time.Second))
+ }
+}
+func IncrementalPrint(scr *Window, text string, from_y int, from_x int, interval_millis int) {
+ for i := 0; i < len(text); i++ {
+ ch := string([]rune(text)[i])
+ _, mx := scr.MaxYX()
+ cy := i/mx + from_y
+ cx := i%mx + 1
+ scr.MovePrint(cy, cx, ch)
+ time.Sleep(time.Duration(1000/len(text)) * time.Millisecond)
+ scr.Refresh()
+ }
+}