Advertisement
Xlonix

types.go

Dec 2nd, 2017
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.63 KB | None | 0 0
  1. //This file stores struct types for other use in the program
  2.  
  3. package main
  4.  
  5. import(
  6.     "github.com/gorilla/websocket"
  7. )
  8.  
  9. // --MESSAGES--
  10.  
  11. type DataJSON struct{
  12.     T string `json:"t"`
  13.     Data string `json:"data"`
  14. }
  15.  
  16. type Message struct {
  17.     T int8 `json:"t"`
  18.     Data string `json:"data"`
  19. }
  20.  
  21. // --MATCHING--
  22.  
  23. //Stores connections until they are put into a board
  24. type Match struct {
  25.     ac []*websocket.Conn
  26.     dc []*websocket.Conn
  27. }
  28.  
  29. // --BOARD--
  30.  
  31. /*
  32.     Represents one hexagon on a board.
  33.     pos specifies the position of the tile
  34.     sides specifies the other tiles it can connect to
  35.     meta is the metadata for the tile
  36.     root specifies the game board that the tile is a part of
  37.    
  38.     NOTE: The side values go as follows:
  39.     0 is the next tile, counting up goes clockwise
  40. */
  41. type HexTile struct{
  42.     pos []uint8
  43.     sides []bool
  44.     meta string
  45.     root *GameBoard
  46. }
  47.  
  48. type Attacker struct{
  49.     pos []uint8
  50.     socket *websocket.Conn
  51.     closed bool
  52. }
  53.  
  54. type Defender struct{
  55.     slice uint8
  56.     socket *websocket.Conn
  57.     closed bool
  58. }
  59.  
  60. /*
  61.     Represents a ring of hexagons on the board
  62.     tiles specifies the hexagons
  63.    
  64.     NOTE: When refering to the board, remember that
  65.     up is relative. UP in this case means up one ring.
  66.     DOWN in this case means down one ring.
  67. */
  68. type BoardRing struct{
  69.     tiles []*HexTile
  70.     edge bool
  71. }
  72.  
  73. /*
  74.     Represents the entire game board
  75.     rings specifies the rings
  76.     numa, numd the number of attackers and defenders on the board
  77.     pla, pld the attackers and defenders on the board
  78.     open defines if the board is still in use
  79. */
  80. type GameBoard struct{
  81.     rings []*BoardRing
  82.     numa int8
  83.     pla []Attacker
  84.     numd int8
  85.     pld []Defender
  86.     open bool
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement