snengame/cmd/engine/main.go
2021-07-22 15:37:25 -04:00

66 lines
1.1 KiB
Go

package main
import (
"bufio"
"fmt"
"os"
"strings"
)
const DEBUG = true
func main() {
if DEBUG {
local()
}
}
func local() {
reader := bufio.NewReader(os.Stdin)
g := snengame.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 == "s" || t == "d" {
c := &snengame.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 := &snengame.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)
}
}
}