snengame/internal/game/card.go

226 lines
3.3 KiB
Go
Raw Normal View History

2021-07-22 15:37:25 -04:00
package game
2021-07-15 19:26:57 -04:00
import (
"fmt"
"github.com/google/uuid"
)
2021-07-16 14:53:45 -04:00
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()
2021-07-23 17:42:12 -04:00
Refresh()
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
Port() *PortableCard
2021-07-15 20:58:21 -04:00
}
type GenericCard struct {
Val CardValue `json:"value"`
Id uuid.UUID `json:"id"`
Sick bool `json:"sick"`
2021-07-15 20:58:21 -04:00
}
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-23 17:42:12 -04:00
func (g *GenericCard) Refresh() {
fmt.Println("refreshed")
g.Sick = false
}
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)
}
func (g *GenericCard) Port() *PortableCard {
return &PortableCard{
Type: int(g.Val),
ID: g.Id,
2021-07-23 17:42:12 -04:00
Sick: g.Sick,
}
}
2021-07-15 20:58:21 -04:00
func (g *GenericCard) CanAttack(x, y int) bool {
if x == y && !g.Sick {
return true
}
2021-07-23 17:42:12 -04:00
fmt.Println("sick")
2021-07-15 20:58:21 -04:00
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
}
func CreateCard(v int) Card {
return NewCard(v, uuid.New())
}
func NewCard(v int, id uuid.UUID) Card {
2021-07-15 20:58:21 -04:00
switch v {
2021-07-16 14:53:45 -04:00
case -1:
return &EmptyCard{
&GenericCard{
Val: EmptyValue,
Id: id,
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,
Id: id,
2021-07-15 20:58:21 -04:00
Sick: false,
},
}
case 4:
return &FourCard{
&GenericCard{
Val: Four,
Id: id,
2021-07-15 20:58:21 -04:00
Sick: true,
},
}
case 8:
return &EightCard{
&GenericCard{
Val: Eight,
Id: id,
2021-07-15 20:58:21 -04:00
Sick: true,
},
0,
}
case 0:
return &Valkyrie{
&GenericCard{
Val: Valk,
Id: id,
2021-07-15 20:58:21 -04:00
Sick: false,
},
}
default:
return &GenericCard{
Val: CardValue(v),
Id: id,
2021-07-15 20:58:21 -04:00
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 `json:"counters"`
2021-07-15 20:58:21 -04:00
}
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)}
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
}
type PortableCard struct {
Type int `json:"type"`
ID uuid.UUID `json:"ID"`
2021-07-23 17:42:12 -04:00
Sick bool `json:"sick"`
}