package main import ( "bufio" "fmt" "os" "strings" ) func main() { 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 == "s" || t == "d" { 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) } } }