debug commands
This commit is contained in:
parent
b09d0b37f1
commit
d05b670e23
1
cmd.go
1
cmd.go
@ -5,6 +5,7 @@ type CmdType string
|
|||||||
const (
|
const (
|
||||||
ActCmd = "a"
|
ActCmd = "a"
|
||||||
StateCmd = "s"
|
StateCmd = "s"
|
||||||
|
DebugCmd = "d"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Command struct {
|
type Command struct {
|
||||||
|
18
game.go
18
game.go
@ -72,8 +72,11 @@ func (g *Game) Parse(cmd *Command) *CommandResult {
|
|||||||
action_res = g.PlayerAct(cmd.PlayerID, cmd.Cmd)
|
action_res = g.PlayerAct(cmd.PlayerID, cmd.Cmd)
|
||||||
res_type = ActCmd
|
res_type = ActCmd
|
||||||
} else if cmd.Type == StateCmd {
|
} 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
|
res_type = StateCmd
|
||||||
|
} else {
|
||||||
|
debug_res = g
|
||||||
|
res_type = DebugCmd
|
||||||
}
|
}
|
||||||
return &CommandResult{
|
return &CommandResult{
|
||||||
PlayerID: cmd.PlayerID,
|
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 {
|
switch cmd {
|
||||||
case "d":
|
|
||||||
//debug game state
|
|
||||||
return nil, g
|
|
||||||
case "g":
|
case "g":
|
||||||
//game state
|
//game state
|
||||||
return NewView(id, g), nil
|
return NewView(id, g)
|
||||||
case "b":
|
case "b":
|
||||||
//begin game
|
//begin game
|
||||||
g.Status = StatusReady
|
g.Status = StatusReady
|
||||||
@ -112,7 +112,7 @@ func (g *Game) PlayerStateAct(id int, cmd string) (*GameView, *Game) {
|
|||||||
g.HasDrawn = false
|
g.HasDrawn = false
|
||||||
}
|
}
|
||||||
if id != g.CurrentTurn {
|
if id != g.CurrentTurn {
|
||||||
return nil, nil
|
return nil
|
||||||
}
|
}
|
||||||
if id == SentinalID {
|
if id == SentinalID {
|
||||||
for _, v := range g.GameBoard.Sentinal {
|
for _, v := range g.GameBoard.Sentinal {
|
||||||
@ -126,7 +126,7 @@ func (g *Game) PlayerStateAct(id int, cmd string) (*GameView, *Game) {
|
|||||||
case "e":
|
case "e":
|
||||||
//end turn and clean up
|
//end turn and clean up
|
||||||
if id != g.CurrentTurn {
|
if id != g.CurrentTurn {
|
||||||
return nil, nil
|
return nil
|
||||||
}
|
}
|
||||||
g.CardBuffer = []Card{}
|
g.CardBuffer = []Card{}
|
||||||
if id == SentinalID {
|
if id == SentinalID {
|
||||||
@ -144,7 +144,7 @@ func (g *Game) PlayerStateAct(id int, cmd string) (*GameView, *Game) {
|
|||||||
g.CurrentTurn = SentinalID
|
g.CurrentTurn = SentinalID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NewView(id, g), nil
|
return NewView(id, g)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) PlayerAct(id int, cmd string) []Card {
|
func (g *Game) PlayerAct(id int, cmd string) []Card {
|
||||||
|
2
main.go
2
main.go
@ -21,7 +21,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
cmd_raw, _ := reader.ReadString('\n')
|
cmd_raw, _ := reader.ReadString('\n')
|
||||||
cmd = strings.TrimSpace(cmd_raw)
|
cmd = strings.TrimSpace(cmd_raw)
|
||||||
if t == "s" {
|
if t == "s" || t == "d" {
|
||||||
c := &Command{
|
c := &Command{
|
||||||
PlayerID: i,
|
PlayerID: i,
|
||||||
Type: CmdType(t),
|
Type: CmdType(t),
|
||||||
|
Loading…
Reference in New Issue
Block a user