snengame/card.go

191 lines
2.6 KiB
Go
Raw Normal View History

2021-07-15 19:26:57 -04:00
package main
2021-07-16 14:53:45 -04:00
import "fmt"
2021-07-15 20:58:21 -04:00
type Card interface {
Cast(g *Game) *Game
Upkeep(g *Game) *Game
Endstep(g *Game) *Game
Enters(g *Game) *Game
Value() CardValue
Act()
Acted() bool
2021-07-16 14:53:45 -04:00
Empty() bool
String() string
2021-07-15 20:58:21 -04:00
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() {
2021-07-15 20:58:21 -04:00
g.Sick = true
}
2021-07-16 14:53:45 -04:00
func (g *GenericCard) Empty() bool {
return false
}
func (g *GenericCard) String() string {
return fmt.Sprintf("%v", g.Val)
}
2021-07-15 20:58:21 -04:00
func (g *GenericCard) CanAttack(x, y int) bool {
if x == y && !g.Sick {
return true
}
return false
}
type CardValue int
2021-07-15 19:26:57 -04:00
const (
2021-07-15 20:58:21 -04:00
Valk CardValue = iota
2021-07-15 19:26:57 -04:00
Ace
Two
Three
Four
Five
Six
Seven
Eight
)
2021-07-16 14:53:45 -04:00
const (
EmptyValue CardValue = -1
)
2021-07-15 19:26:57 -04:00
2021-07-15 20:58:21 -04:00
func (c CardValue) String() string {
2021-07-16 14:53:45 -04:00
if c == -1 {
return " "
}
2021-07-15 20:58:21 -04:00
return []string{"V", "A", "2", "3", "4", "5", "6", "7", "8"}[c]
2021-07-15 19:26:57 -04:00
}
2021-07-15 20:58:21 -04:00
func NewCard(v int) Card {
switch v {
2021-07-16 14:53:45 -04:00
case -1:
return &EmptyCard{
&GenericCard{
Val: EmptyValue,
Sick: true,
2021-07-16 14:53:45 -04:00
},
}
2021-07-15 20:58:21 -04:00
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,
}
2021-07-15 19:26:57 -04:00
}
2021-07-15 20:58:21 -04:00
}
2021-07-16 14:53:45 -04:00
type EmptyCard struct {
*GenericCard
}
func (e *EmptyCard) Empty() bool {
return true
}
2021-07-15 20:58:21 -04:00
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 {
2021-07-16 14:53:45 -04:00
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)}
2021-07-15 20:58:21 -04:00
return g
}
func (v *Valkyrie) Enters(g *Game) *Game {
v = nil
return g
2021-07-15 19:26:57 -04:00
}