diff --git a/board.go b/board.go index 17f817c..6756368 100644 --- a/board.go +++ b/board.go @@ -43,7 +43,7 @@ func (b *Board) Move(id, src, dest int) bool { return true } -func (b *Board) Play(id int, c Card, dest int) bool { +func (b *Board) CanPlay(id int, c *Card, dest int) bool { var brd [4]Card if id == 1 { brd = b.Sentinal @@ -53,7 +53,20 @@ func (b *Board) Play(id int, c Card, dest int) bool { if brd[dest] != nil { return false } - brd[dest] = c + return true +} + +func (b *Board) Play(id int, c *Card, dest int) bool { + var brd [4]Card + if id == 1 { + brd = b.Sentinal + } else { + brd = b.Scourge + } + if brd[dest] != nil { + return false + } + brd[dest] = *c if id == 1 { b.Sentinal = brd } else { diff --git a/game.go b/game.go index ba28dd9..e5a80bf 100644 --- a/game.go +++ b/game.go @@ -44,10 +44,31 @@ func (g *Game) PlayerStateAct(id int, cmd string) *Game { return nil } g.CanDraw = true + if id == 1 { + for _, v := range g.GameBoard.Sentinal { + v.Upkeep(g) + } + } else { + for _, v := range g.GameBoard.Scourge { + v.Upkeep(g) + } + } return g case "e": //end turn and clean up + if id != g.CurrentTurn { + return nil + } g.cardBuffer = []Card{} + if id == 1 { + for _, v := range g.GameBoard.Sentinal { + v.Endstep(g) + } + } else { + for _, v := range g.GameBoard.Scourge { + v.Endstep(g) + } + } if g.CurrentTurn == 1 { g.CurrentTurn = 2 } else { @@ -141,8 +162,13 @@ func (g *Game) PlayerAct(id int, cmd string) []Card { } x_i, _ := strconv.Atoi(cmd_s[1]) y_i, _ := strconv.Atoi(cmd_s[2]) - res := g.GameBoard.Play(g.CurrentTurn, curr.Hand[x_i], y_i) + card := curr.Hand[x_i] + if g.GameBoard.CanPlay(g.CurrentTurn, &card, y_i) { + curr.Hand[x_i].Cast(g) + } + res := g.GameBoard.Play(g.CurrentTurn, &card, y_i) if res { + curr.Hand[x_i].Enters(g) curr.Hand = append(curr.Hand[:x_i], curr.Hand[x_i+1:]...) return g.GameBoard.GetRow(g.CurrentTurn) } else {