card change cleanup

This commit is contained in:
stryan 2021-07-15 21:44:45 -04:00
parent 279af42056
commit b37cc0e73c
2 changed files with 42 additions and 3 deletions

View File

@ -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 {

28
game.go
View File

@ -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 {