snengame/cmd/engine/main.go
2021-07-22 15:55:52 -04:00

80 lines
1.4 KiB
Go

package main
import (
"bufio"
"fmt"
"os"
"strings"
. "git.saintnet.tech/stryan/snengame/internal/game"
)
const DEBUG = true
func main() {
if DEBUG {
local()
}
}
func local() {
reader := bufio.NewReader(os.Stdin)
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)
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{
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" {
c := &Command{
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)
}
}
}