A card game engine for TCGs, primarily Magic: The Gathering but with support for others
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Removing test print; Changing how the card data is stored because this will only be for MTG~

authored by

Cass Unterholzner and committed by
Tangled
3ac4630b 8f2b3642

+30 -77
+24 -65
game/card.go
··· 9 9 type CardId uuid.UUID 10 10 type CardDefId uuid.UUID 11 11 12 - type Cost interface { 13 - CanPay(state GameState, player PlayerId, source CardId) bool 14 - Pay(state *GameState, player PlayerId, source CardId) error 15 - FromMap(data map[string]interface{}) 16 - } 17 - 18 - type MagicResource struct { 19 - Black int `json:"black"` 20 - White int `json:"white"` 21 - Blue int `json:"blue"` 22 - Green int `json:"green"` 23 - Red int `json:"red"` 24 - Colorless int `json:"colorless"` 25 - } 26 - 27 - type Card struct { 28 - Id CardDefId 29 - Name string 30 - Cost Cost 31 - Attack *int 32 - Defense *int 33 - Text string 34 - } 35 - 36 - func (c *Card) UnmarshalJSON(b []byte) error { 37 - type TmpCost struct { 38 - Game string `json:"game"` 39 - Data map[string]interface{} `json:"data"` 40 - } 41 - 42 - type TmpCard struct { 43 - Id string `json:"id"` 44 - Name string `json:"name"` 45 - Cost TmpCost `json:"cost"` 46 - Attack *int `json:"attack"` 47 - Defense *int `json:"defense"` 48 - Text string `json:"text"` 49 - } 50 - 51 - var data TmpCard 12 + func (c *CardDefId) UnmarshalJSON(b []byte) error { 13 + var data string 52 14 53 15 if err := json.Unmarshal(b, &data); err != nil { 54 16 return err 55 17 } 56 18 57 - id, err := uuid.Parse(data.Id) 19 + id, err := uuid.Parse(data) 58 20 59 21 if err != nil { 60 22 return err 61 23 } 62 24 63 - c.Id = CardDefId(id) 64 - c.Name = data.Name 65 - c.Attack = data.Attack 66 - c.Defense = data.Defense 67 - c.Text = data.Text 25 + *c = CardDefId(id) 26 + return nil 27 + } 68 28 69 - if data.Cost.Game == "mtg" { 70 - c.Cost = &MagicCost{} 71 - c.Cost.FromMap(data.Cost.Data) 72 - } else { 73 - return &ManaGroveError{} 74 - } 29 + type Resource struct { 30 + Black int `json:"black"` 31 + White int `json:"white"` 32 + Blue int `json:"blue"` 33 + Green int `json:"green"` 34 + Red int `json:"red"` 35 + Colorless int `json:"colorless"` 36 + } 75 37 76 - return nil 38 + type Card struct { 39 + Id CardDefId `json:"id"` 40 + Name string `json:"name"` 41 + Cost Cost `json:"cost"` 42 + Attack *int `json:"attack"` 43 + Defense *int `json:"defense"` 44 + Text string `json:"text"` 77 45 } 78 46 79 47 func (c *Card) CreateInstance() CardInstance { ··· 95 63 current_defense *int 96 64 } 97 65 98 - type MagicCost MagicResource 66 + type Cost Resource 99 67 100 - func (m MagicCost) CanPay(state GameState, player PlayerId, source CardId) bool { 68 + func (m Cost) CanPay(state GameState, player PlayerId, source CardId) bool { 101 69 return false 102 70 } 103 71 104 - func (m MagicCost) Pay(state *GameState, player PlayerId, source CardId) error { 72 + func (m Cost) Pay(state *GameState, player PlayerId, source CardId) error { 105 73 return nil 106 74 } 107 - 108 - func (m *MagicCost) FromMap(data map[string]interface{}) { 109 - m.Black = int(data["black"].(float64)) 110 - m.Blue = int(data["blue"].(float64)) 111 - m.Colorless = int(data["colorless"].(float64)) 112 - m.Green = int(data["green"].(float64)) 113 - m.Red = int(data["red"].(float64)) 114 - m.White = int(data["white"].(float64)) 115 - }
+6 -9
game/cards/test.json
··· 2 2 "84ae9ffe-878f-4769-b18f-214658b92379": { 3 3 "name": "River Bear", 4 4 "cost": { 5 - "game": "mtg", 6 - "data": { 7 - "black": 0, 8 - "green": 2, 9 - "blue": 0, 10 - "white": 0, 11 - "red": 0, 12 - "colorless": 0 13 - } 5 + "black": 0, 6 + "green": 2, 7 + "blue": 0, 8 + "white": 0, 9 + "red": 0, 10 + "colorless": 0 14 11 }, 15 12 "id": "84ae9ffe-878f-4769-b18f-214658b92379", 16 13 "attack": 2,
-3
game/game.go
··· 2 2 3 3 import ( 4 4 "bytes" 5 - "fmt" 6 5 "image" 7 6 "image/color" 8 7 ··· 71 70 } 72 71 73 72 func (g *Game) Update() error { 74 - fmt.Println(g.state.cards) 75 - 76 73 return nil 77 74 } 78 75