package game import ( "fmt" "github.com/google/uuid" ) type Card interface { Cast(g *Game) *Game Upkeep(g *Game) *Game Endstep(g *Game) *Game Enters(g *Game) *Game Value() CardValue Act() Refresh() Acted() bool Empty() bool String() string CanAttack(int, int) bool Port() *PortableCard } type GenericCard struct { Val CardValue `json:"value"` Id uuid.UUID `json:"id"` Sick bool `json:"sick"` } func (g *GenericCard) Cast(game *Game) *Game { return nil } func (g *GenericCard) Enters(game *Game) *Game { return nil } func (g *GenericCard) Upkeep(game *Game) *Game { g.Sick = false return nil } func (g *GenericCard) Endstep(game *Game) *Game { return nil } func (g *GenericCard) Value() CardValue { return g.Val } func (g *GenericCard) Acted() bool { return g.Sick } func (g *GenericCard) Act() { g.Sick = true } func (g *GenericCard) Refresh() { fmt.Println("refreshed") g.Sick = false } func (g *GenericCard) Empty() bool { return false } func (g *GenericCard) String() string { return fmt.Sprintf("%v", g.Val) } func (g *GenericCard) Port() *PortableCard { return &PortableCard{ Type: int(g.Val), ID: g.Id, Sick: g.Sick, } } func (g *GenericCard) CanAttack(x, y int) bool { if x == y && !g.Sick { return true } fmt.Println("sick") return false } type CardValue int const ( Valk CardValue = iota Ace Two Three Four Five Six Seven Eight ) const ( EmptyValue CardValue = -1 ) func (c CardValue) String() string { if c == -1 { return " " } return []string{"V", "A", "2", "3", "4", "5", "6", "7", "8"}[c] } func CreateCard(v int) Card { return NewCard(v, uuid.New()) } func NewCard(v int, id uuid.UUID) Card { switch v { case -1: return &EmptyCard{ &GenericCard{ Val: EmptyValue, Id: id, Sick: true, }, } case 1: return &AceCard{ &GenericCard{ Val: Ace, Id: id, Sick: false, }, } case 4: return &FourCard{ &GenericCard{ Val: Four, Id: id, Sick: true, }, } case 8: return &EightCard{ &GenericCard{ Val: Eight, Id: id, Sick: true, }, 0, } case 0: return &Valkyrie{ &GenericCard{ Val: Valk, Id: id, Sick: false, }, } default: return &GenericCard{ Val: CardValue(v), Id: id, Sick: true, } } } type EmptyCard struct { *GenericCard } func (e *EmptyCard) Empty() bool { return true } type AceCard struct { *GenericCard } type FourCard struct { *GenericCard } func (f *FourCard) Enters(g *Game) *Game { g.CanDraw = true return g } type EightCard struct { *GenericCard Counters int `json:"counters"` } func (e *EightCard) CanAttack(x, y int) bool { return false } func (e *EightCard) Upkeep(g *Game) *Game { if e.Counters > 2 { e = nil } return g } func (e *EightCard) Endstep(g *Game) *Game { e.Counters = e.Counters + 1 return g } type Valkyrie struct { *GenericCard } func (v *Valkyrie) Cast(g *Game) *Game { g.GameBoard.Sentinal = [4]Card{CreateCard(-1), CreateCard(-1), CreateCard(-1), CreateCard(-1)} g.GameBoard.Scourge = [4]Card{CreateCard(-1), CreateCard(-1), CreateCard(-1), CreateCard(-1)} return g } func (v *Valkyrie) Enters(g *Game) *Game { v = nil return g } type PortableCard struct { Type int `json:"type"` ID uuid.UUID `json:"ID"` Sick bool `json:"sick"` }