snengame/internal/game/card.go
2021-07-22 15:37:25 -04:00

191 lines
2.6 KiB
Go

package game
import "fmt"
type Card interface {
Cast(g *Game) *Game
Upkeep(g *Game) *Game
Endstep(g *Game) *Game
Enters(g *Game) *Game
Value() CardValue
Act()
Acted() bool
Empty() bool
String() string
CanAttack(int, int) bool
}
type GenericCard struct {
Val CardValue
Sick bool
}
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) Empty() bool {
return false
}
func (g *GenericCard) String() string {
return fmt.Sprintf("%v", g.Val)
}
func (g *GenericCard) CanAttack(x, y int) bool {
if x == y && !g.Sick {
return true
}
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 NewCard(v int) Card {
switch v {
case -1:
return &EmptyCard{
&GenericCard{
Val: EmptyValue,
Sick: true,
},
}
case 1:
return &AceCard{
&GenericCard{
Val: Ace,
Sick: false,
},
}
case 4:
return &FourCard{
&GenericCard{
Val: Four,
Sick: true,
},
}
case 8:
return &EightCard{
&GenericCard{
Val: Eight,
Sick: true,
},
0,
}
case 0:
return &Valkyrie{
&GenericCard{
Val: Valk,
Sick: false,
},
}
default:
return &GenericCard{
Val: CardValue(v),
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
}
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{NewCard(-1), NewCard(-1), NewCard(-1), NewCard(-1)}
g.GameBoard.Scourge = [4]Card{NewCard(-1), NewCard(-1), NewCard(-1), NewCard(-1)}
return g
}
func (v *Valkyrie) Enters(g *Game) *Game {
v = nil
return g
}