tile.go 940 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package board
  2. import "fmt"
  3. type TileType byte
  4. type jsonTile struct {
  5. X int `json:"x"`
  6. Y int `json:"y"`
  7. Type string `json:"type"`
  8. Player string `json:"player,omitempty"`
  9. }
  10. const (
  11. Water TileType = 0
  12. Rock TileType = 1
  13. Ice TileType = 2
  14. Iglo TileType = 3
  15. )
  16. func FromName(name string) TileType {
  17. switch name {
  18. case "W":
  19. return Water
  20. case "R":
  21. return Rock
  22. case "I":
  23. return Ice
  24. case "H":
  25. return Iglo
  26. }
  27. panic(fmt.Sprintf("Unknown tile type %v", name))
  28. }
  29. func (t TileType) String() string {
  30. switch t {
  31. case Water:
  32. return "~"
  33. case Rock:
  34. return "▲"
  35. case Ice:
  36. return "*"
  37. case Iglo:
  38. return "⌂"
  39. }
  40. panic(fmt.Sprintf("Unknown tile type %#v", t))
  41. }
  42. func (t TileType) Name() string {
  43. switch t {
  44. case Water:
  45. return "W" // API says WATER... zucht.
  46. case Rock:
  47. return "R"
  48. case Ice:
  49. return "I"
  50. case Iglo:
  51. return "H"
  52. }
  53. panic(fmt.Sprintf("Unknown tile type %#v", t))
  54. }