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 }