debug commands

This commit is contained in:
stryan 2021-07-22 13:21:49 -04:00
parent b09d0b37f1
commit d05b670e23
3 changed files with 11 additions and 10 deletions

1
cmd.go
View File

@ -5,6 +5,7 @@ type CmdType string
const (
ActCmd = "a"
StateCmd = "s"
DebugCmd = "d"
)
type Command struct {

18
game.go
View File

@ -72,8 +72,11 @@ func (g *Game) Parse(cmd *Command) *CommandResult {
action_res = g.PlayerAct(cmd.PlayerID, cmd.Cmd)
res_type = ActCmd
} else if cmd.Type == StateCmd {
state_res, debug_res = g.PlayerStateAct(cmd.PlayerID, cmd.Cmd)
state_res = g.PlayerStateAct(cmd.PlayerID, cmd.Cmd)
res_type = StateCmd
} else {
debug_res = g
res_type = DebugCmd
}
return &CommandResult{
PlayerID: cmd.PlayerID,
@ -84,14 +87,11 @@ func (g *Game) Parse(cmd *Command) *CommandResult {
}
}
func (g *Game) PlayerStateAct(id int, cmd string) (*GameView, *Game) {
func (g *Game) PlayerStateAct(id int, cmd string) *GameView {
switch cmd {
case "d":
//debug game state
return nil, g
case "g":
//game state
return NewView(id, g), nil
return NewView(id, g)
case "b":
//begin game
g.Status = StatusReady
@ -112,7 +112,7 @@ func (g *Game) PlayerStateAct(id int, cmd string) (*GameView, *Game) {
g.HasDrawn = false
}
if id != g.CurrentTurn {
return nil, nil
return nil
}
if id == SentinalID {
for _, v := range g.GameBoard.Sentinal {
@ -126,7 +126,7 @@ func (g *Game) PlayerStateAct(id int, cmd string) (*GameView, *Game) {
case "e":
//end turn and clean up
if id != g.CurrentTurn {
return nil, nil
return nil
}
g.CardBuffer = []Card{}
if id == SentinalID {
@ -144,7 +144,7 @@ func (g *Game) PlayerStateAct(id int, cmd string) (*GameView, *Game) {
g.CurrentTurn = SentinalID
}
}
return NewView(id, g), nil
return NewView(id, g)
}
func (g *Game) PlayerAct(id int, cmd string) []Card {

View File

@ -21,7 +21,7 @@ func main() {
}
cmd_raw, _ := reader.ReadString('\n')
cmd = strings.TrimSpace(cmd_raw)
if t == "s" {
if t == "s" || t == "d" {
c := &Command{
PlayerID: i,
Type: CmdType(t),