you can win the game now
This commit is contained in:
parent
d05b670e23
commit
89c69d6037
18
board.go
18
board.go
@ -26,6 +26,24 @@ func (b *Board) GetRow(id int) []Card {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Board) Empty(id int) bool {
|
||||
res := true
|
||||
if id == SentinalID {
|
||||
for _, v := range b.Sentinal {
|
||||
if !v.Empty() {
|
||||
res = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, v := range b.Scourge {
|
||||
if !v.Empty() {
|
||||
res = false
|
||||
}
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (b *Board) Move(id, src, dest int) bool {
|
||||
var brd [4]Card
|
||||
if id == 1 {
|
||||
|
40
game.go
40
game.go
@ -15,6 +15,7 @@ const (
|
||||
StatusStop
|
||||
StatusSentinalWin
|
||||
StatusScourgeWin
|
||||
StatusDraw
|
||||
)
|
||||
|
||||
const (
|
||||
@ -63,6 +64,17 @@ func (g *Game) String() string {
|
||||
}
|
||||
|
||||
func (g *Game) Parse(cmd *Command) *CommandResult {
|
||||
|
||||
if g.Status != StatusLobby || g.Status != StatusReady || g.Status != StatusPlaying {
|
||||
return &CommandResult{
|
||||
PlayerID: cmd.PlayerID,
|
||||
ResultType: cmd.Type,
|
||||
StateResult: NewView(cmd.PlayerID, g),
|
||||
ActionResult: nil,
|
||||
DebugResult: g,
|
||||
}
|
||||
}
|
||||
|
||||
var state_res *GameView
|
||||
var action_res []Card
|
||||
var debug_res *Game
|
||||
@ -78,6 +90,7 @@ func (g *Game) Parse(cmd *Command) *CommandResult {
|
||||
debug_res = g
|
||||
res_type = DebugCmd
|
||||
}
|
||||
g.StateChanges()
|
||||
return &CommandResult{
|
||||
PlayerID: cmd.PlayerID,
|
||||
ResultType: res_type,
|
||||
@ -87,6 +100,33 @@ func (g *Game) Parse(cmd *Command) *CommandResult {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) StateChanges() {
|
||||
//check for no actions first
|
||||
if len(g.SentinalPlayer.Hand) == 0 && g.SentinalDeck.Size() == 0 {
|
||||
if g.GameBoard.Empty(SentinalID) {
|
||||
g.Status = StatusScourgeWin
|
||||
}
|
||||
}
|
||||
|
||||
if len(g.ScourgePlayer.Hand) == 0 && g.ScourgeDeck.Size() == 0 {
|
||||
if g.GameBoard.Empty(ScourgeID) {
|
||||
g.Status = StatusSentinalWin
|
||||
}
|
||||
}
|
||||
//check life
|
||||
//this is second on purpose so that it shadows deck out win conditions
|
||||
//if you use your last action to win the game, you should actually win
|
||||
if g.SentinalPlayer.Life < 0 {
|
||||
g.Status = StatusScourgeWin
|
||||
}
|
||||
if g.ScourgePlayer.Life < 0 {
|
||||
g.Status = StatusSentinalWin
|
||||
}
|
||||
if g.ScourgePlayer.Life < 0 && g.SentinalPlayer.Life < 0 {
|
||||
g.Status = StatusDraw
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) PlayerStateAct(id int, cmd string) *GameView {
|
||||
switch cmd {
|
||||
case "g":
|
||||
|
Loading…
Reference in New Issue
Block a user