empty cards have owners, clogs and duds should work

This commit is contained in:
stryan 2021-11-16 18:07:24 -05:00
parent c62eff76bb
commit 354167535a
2 changed files with 23 additions and 5 deletions

View File

@ -23,6 +23,7 @@ func (b *Board) GetRow(id int) []*Card {
return b.Scourge[:] return b.Scourge[:]
} else { } else {
log.Println("asked for invalid row") log.Println("asked for invalid row")
panic("bad row")
return nil return nil
} }
} }
@ -38,16 +39,27 @@ func (b *Board) GetCard(id int, pos int) *Card {
func (b *Board) Remove(c *Card) { func (b *Board) Remove(c *Card) {
for k, v := range b.Sentinal { for k, v := range b.Sentinal {
if v.Id == c.Id { if v.Id == c.Id {
b.Sentinal[k] = NewEmpty(k) b.Sentinal[k] = NewEmpty(c.Owner, k)
} }
} }
for k, v := range b.Scourge { for k, v := range b.Scourge {
if v.Id == c.Id { if v.Id == c.Id {
b.Scourge[k] = NewEmpty(k) b.Scourge[k] = NewEmpty(c.Owner, k)
} }
} }
} }
func (b *Board) Replace(old *Card, neo *Card) {
if old.Owner == SentinalID {
b.Sentinal[old.Position] = neo
} else if old.Owner == ScourgeID {
b.Scourge[old.Position] = neo
} else {
log.Printf("can't replace a card with bad owner:%v", old.Owner)
return
}
}
func (b *Board) Empty(id int) bool { func (b *Board) Empty(id int) bool {
res := true res := true
row := b.GetRow(id) row := b.GetRow(id)
@ -81,7 +93,7 @@ func (b *Board) Move(id, src, dest int) bool {
brd := b.GetRow(id) brd := b.GetRow(id)
brd[dest] = brd[src] brd[dest] = brd[src]
brd[dest].Position = dest brd[dest].Position = dest
brd[src] = NewEmpty(src) brd[src] = NewEmpty(brd[dest].Owner, src)
return true return true
} }

10
card.go
View File

@ -2,6 +2,7 @@ package tome_lib
import ( import (
"fmt" "fmt"
"log"
"github.com/google/uuid" "github.com/google/uuid"
) )
@ -21,7 +22,12 @@ type Card struct {
Effects []*Effect `json:"effects"` Effects []*Effect `json:"effects"`
} }
func NewEmpty(p int) *Card { func NewEmpty(o, p int) *Card {
if o != ScourgeID && o != SentinalID {
log.Printf("Need valid owner for empty card:%v", o)
panic("err")
return nil
}
return &Card{ return &Card{
Type: EmptyValue, Type: EmptyValue,
BasePower: -1, BasePower: -1,
@ -29,7 +35,7 @@ func NewEmpty(p int) *Card {
Id: uuid.New(), Id: uuid.New(),
Sick: false, Sick: false,
Counters: 0, Counters: 0,
Owner: -1, Owner: o,
Position: p, Position: p,
Spell: false, Spell: false,
Token: false, Token: false,