snengame/cmd/engine/main.go

80 lines
1.4 KiB
Go
Raw Permalink Normal View History

2021-07-15 19:26:57 -04:00
package main
import (
"bufio"
"fmt"
"os"
"strings"
2021-07-22 15:55:52 -04:00
. "git.saintnet.tech/stryan/snengame/internal/game"
)
2021-07-22 13:43:28 -04:00
const DEBUG = true
2021-07-15 19:26:57 -04:00
func main() {
2021-07-22 13:43:28 -04:00
if DEBUG {
local()
}
}
func local() {
reader := bufio.NewReader(os.Stdin)
2021-07-22 15:55:52 -04:00
g := NewGame()
for {
var t, cmd string
var i int
fmt.Print("> ")
_, err := fmt.Scanf("%s %d", &t, &i)
if t == "x" {
return
}
cmd_raw, _ := reader.ReadString('\n')
cmd = strings.TrimSpace(cmd_raw)
2021-07-22 15:55:52 -04:00
if t == "d" {
c := &Command{
PlayerID: i,
Type: DebugCmd,
Cmd: "d",
}
res := g.Parse(c)
if res.DebugResult != nil {
fmt.Println(res.DebugResult)
} else {
fmt.Println("invalid debug command")
}
} else if t == "s" {
c := &Command{
2021-07-22 13:09:56 -04:00
PlayerID: i,
Type: CmdType(t),
Cmd: cmd,
}
res := g.Parse(c)
if res.StateResult != nil {
fmt.Println(res.StateResult)
} else if res.DebugResult != nil {
fmt.Println(res.DebugResult)
} else if res.StateResult == nil && res.DebugResult == nil {
fmt.Println("invalid state command")
} else {
fmt.Println("uh oh")
}
} else if t == "a" {
2021-07-22 15:55:52 -04:00
c := &Command{
2021-07-22 13:09:56 -04:00
PlayerID: i,
Type: CmdType(t),
Cmd: cmd,
}
res := g.Parse(c)
if res.ActionResult != nil {
fmt.Println(res.ActionResult)
} else {
fmt.Println("invalid action command")
}
} else {
fmt.Println("error parsing")
fmt.Println(err)
}
}
2021-07-15 19:26:57 -04:00
}