aboutsummaryrefslogtreecommitdiff
path: root/go/game/permanent.go
blob: ce1d3105d31a706aa331fc3027c520f82bd8ef95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package game

import (
	"fmt"
	"log"
)

type Permanent interface {
	GetCard() *Card
	GetTile() *Tile
	GetDamage() int
	GetPile() []Permanent
	GetController() *Player
	GetOwner() *Player

	String() string
	Fight(p Permanent)
	AddDamage(damage int)
	IsDestroyed() bool
	Attackable() bool
	GetAvailActionPrototypes() []ActionPrototype
}

type PermanentBase struct {
	Card       *Card
	Tile       *Tile
	Damage     int
	Pile       []Permanent
	Controller *Player
	Owner      *Player
}

func NewPermanentBase(card *Card, tile *Tile, owner *Player) PermanentBase {
	if tile.Permanent != nil {
		log.Fatalf("Tile at %v already occupied by %v", tile.Position, tile.Permanent)
	}
	return PermanentBase{card, tile, 0, []Permanent{}, owner, owner}
}

func (p *PermanentBase) GetCard() *Card {
	return p.Card
}

func (p *PermanentBase) GetTile() *Tile {
	return p.Tile
}

func (p *PermanentBase) GetDamage() int {
	return p.Damage
}

func (p *PermanentBase) GetPile() []Permanent {
	return p.Pile
}

func (p *PermanentBase) GetController() *Player {
	return p.Controller
}

func (p *PermanentBase) GetOwner() *Player {
	return p.Owner
}

func (p *PermanentBase) String() string {
	return fmt.Sprintf("%s's %s@%s",
		p.GetController().Name, p.GetCard().Name, p.GetTile().Position.String())
}

func (p *PermanentBase) AddDamage(damage int) {
	p.Damage += damage
}