snengame/main.go

59 lines
1.0 KiB
Go
Raw Normal View History

2021-07-15 19:26:57 -04:00
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
2021-07-15 19:26:57 -04:00
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" {
2021-07-22 13:09:56 -04:00
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" {
2021-07-22 13:09:56 -04:00
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)
}
}
2021-07-15 19:26:57 -04:00
}