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.

Adding in creating a test card and an instance of that card in the hand of the first player

authored by

Cass Unterholzner and committed by
Tangled
8f2b3642 e63381d7

+30 -1
+12
game/card.go
··· 76 76 return nil 77 77 } 78 78 79 + func (c *Card) CreateInstance() CardInstance { 80 + attack := *c.Attack 81 + defense := *c.Defense 82 + 83 + return CardInstance{ 84 + id: CardId(uuid.New()), 85 + source: c.Id, 86 + current_attack: &attack, 87 + current_defense: &defense, 88 + } 89 + } 90 + 79 91 type CardInstance struct { 80 92 id CardId 81 93 source CardDefId
+11
game/game.go
··· 2 2 3 3 import ( 4 4 "bytes" 5 + "fmt" 5 6 "image" 6 7 "image/color" 7 8 ··· 58 59 59 60 game.cards[CardDefId(id)] = card 60 61 62 + new_instance := card.CreateInstance() 63 + 64 + game.state.cards[new_instance.id] = new_instance 65 + hand_zone_id := game.state.players[firstPlayerId].hand 66 + hand_zone := game.state.zones[hand_zone_id] 67 + hand_zone.cards = append(hand_zone.cards, new_instance.id) 68 + game.state.zones[hand_zone_id] = hand_zone 69 + 61 70 return game, nil 62 71 } 63 72 64 73 func (g *Game) Update() error { 74 + fmt.Println(g.state.cards) 75 + 65 76 return nil 66 77 } 67 78
+7 -1
game/state.go
··· 6 6 cards map[CardId]CardInstance 7 7 } 8 8 9 + var firstPlayerId PlayerId 10 + 9 11 func NewGameState(player_names []string) GameState { 10 12 players := make(map[PlayerId]Player) 11 13 zones := make(map[ZoneId]Zone) 12 14 cards := make(map[CardId]CardInstance) 13 15 14 - for _, player_name := range player_names { 16 + for i, player_name := range player_names { 15 17 player_id := NewPlayerId() 16 18 players[player_id] = NewPlayer(player_id, player_name, &zones) 19 + 20 + if i == 0 { 21 + firstPlayerId = player_id 22 + } 17 23 } 18 24 19 25 return GameState{