snengame/internal/game/card.go

90 lines
1.5 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-23 18:33:17 -04:00
type Card struct {
Type CardType `json:"type"`
BasePower int `json:"base_power"`
Power int `json:"power"`
Id uuid.UUID `json:"id"`
Sick bool `json:"sick"`
Counters int `json:"counters"`
Owner int `json:"owner"`
Position int `json:"position"`
Spell bool `json:"spell"`
2021-07-26 11:17:45 -04:00
Effects []*Effect `json:"effects"`
2021-07-15 20:58:21 -04:00
}
2021-07-23 18:33:17 -04:00
type CardType int
2021-07-15 19:26:57 -04:00
const (
2021-07-23 18:33:17 -04:00
Valk CardType = 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 (
2021-07-23 18:33:17 -04:00
EmptyValue CardType = -1
2021-07-16 14:53:45 -04:00
)
2021-07-15 19:26:57 -04:00
2021-07-23 18:33:17 -04:00
func (c CardType) 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 NewCard(v, o, p int, id uuid.UUID) *Card {
2021-07-23 18:33:17 -04:00
if id == uuid.Nil {
id = uuid.New()
2021-07-15 19:26:57 -04:00
}
2021-07-23 18:33:17 -04:00
return &Card{
Type: CardType(v),
BasePower: OraclePower(CardType(v), nil),
Power: OraclePower(CardType(v), nil),
Id: id,
Sick: false,
Counters: 0,
Owner: o,
Position: p,
Spell: OracleSpell(CardType(v), nil),
2021-07-26 11:17:45 -04:00
Effects: []*Effect{},
}
}
func NewEmpty(p int) *Card {
return &Card{
Type: EmptyValue,
BasePower: -1,
Power: -1,
Id: uuid.New(),
Sick: false,
Counters: 0,
Owner: -1,
Position: p,
2021-07-25 15:33:47 -04:00
Spell: false,
2021-07-26 11:17:45 -04:00
Effects: []*Effect{},
2021-07-15 20:58:21 -04:00
}
}
2021-07-23 18:33:17 -04:00
func (c *Card) Empty() bool {
return c.Type == EmptyValue
2021-07-15 19:26:57 -04:00
}
2021-07-23 18:33:17 -04:00
func (c *Card) String() string {
2021-07-25 15:33:47 -04:00
ready := " "
if c.Sick {
ready = "*"
}
return fmt.Sprintf("%v%v%v", c.Type, c.Power, ready)
}