aboutsummaryrefslogtreecommitdiff
path: root/go/game/tile.go
blob: f66b4fb0ee5be35296d03ddb47bb6a7561dd1fbe (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
72
73
74
75
76
77
78
79
80
81
82
83
package game

import (
	"log"
	"strings"
)

type TileType int

const (
	neutral TileType = iota + 1
	tower
	house
	farm
	street
	spawn
)

func (t TileType) String() string {
	switch t {
	case neutral:
		return "neutral"
	case tower:
		return "tower"
	case house:
		return "house"
	case farm:
		return "farm"
	case street:
		return "street"
	case spawn:
		return "spawn"
	}
	log.Panicf("Switch not exhausting %d", t)
	return ""
}

var TileTypes = struct {
	Neutral TileType
	Tower   TileType
	House   TileType
	Farm    TileType
	Street  TileType
	Spawn   TileType
}{
	Neutral: neutral,
	Tower:   tower,
	House:   house,
	Farm:    farm,
	Street:  street,
	Spawn:   spawn,
}

var TileNames = map[string]TileType{
	"neutral": neutral,
	"tower":   tower,
	"house":   house,
	"farm":    farm,
	"street":  street,
	"spawn":   spawn,
}

type Tile struct {
	Position  Position
	Permanent Permanent
	Type      TileType
	Raw       string
}

func INVALID_TILE() Tile {
	return Tile{INVALID_POSITION(), nil, 0, ""}
}

func NewTileFromString(tile string, pos Position) (Tile, error) {
	tokens := strings.Split(tile, " ")
	tileType := TileNames[strings.ToLower(tokens[0])]
	t := Tile{pos, nil, tileType, tile}
	return t, nil
}

func (t *Tile) IsFree() bool {
	return t.Permanent == nil
}