Documentation ¶
Index ¶
- Constants
- func GetHealthBitfield(size uint8) uint8
- func ProduceHitBitmask(offset uint8) uint8
- func RandomId(input string, length int) string
- func SwitchTeam(player *Player, destTeam *Team)
- type Coordinate
- type Game
- func (game *Game) BoardCoordinates() <-chan Coordinate
- func (game *Game) GetMap(team *Team) [][]string
- func (game *Game) GetPlayerById(id string) *Player
- func (game *Game) GetRadar(team *Team, targetTeam *Team) [][]string
- func (game *Game) GetSmallestTeam() *Team
- func (game *Game) Join(username, password string) (*Player, bool, error)
- func (game *Game) NewTeam() *Team
- func (game *Game) UniqueTeamName(name string) bool
- type Orientation
- type Player
- type Ship
- type ShipCoord
- type ShotResult
- type Target
- type Team
Constants ¶
const ( // Points awarded for scoring hit HIT_POINT = 8 HIT_STREAK_POINT = 10 SINK_POINT = 18 DISCOVERY_POINT = 1 DEPLOY_COST = 50 DEPLOY_PER_SQ_COST = 10 MOVE_COST = 1 NEW_TEAM_COST = 200 )
Point values
const ( // ICON_ALIVE is the icon represent a portion of a ship that has not been hit ICON_ALIVE = '+' // ICON_DEAD is the icon represent a portion of a ship that has been hit ICON_DEAD = '@' // ICON_MISS is the icon representing a missed attempted attack on a team map ICON_MISS = "-" ICON_HIT = "x" )
Map icons
Variables ¶
This section is empty.
Functions ¶
func GetHealthBitfield ¶
GetHealthBitfield returns a bitfield representing the Ship and thats parts of it that are hit and unscathed.
func ProduceHitBitmask ¶
ProduceHitBitmask creates a bitfield of all ones, except for a single zero at the offset position. This bitmask & ship.health will zero the bit at the offset.
func SwitchTeam ¶
SwitchTeam switches a Players Team
Types ¶
type Coordinate ¶
Coordinate is the actually row/column square
func (Coordinate) ToTarget ¶
func (coordinate Coordinate) ToTarget() Target
type Game ¶
type Game struct { // As long as this is true server will keep running Live bool // Game server info Port uint16 Password string StartTime time.Time AdminPassword string MaxPlayers uint8 ShipLimit uint8 BoardSize uint8 Teams []*Team StartDeployPts int }
Game represents a running with all Game settings and teams
func (*Game) BoardCoordinates ¶
func (game *Game) BoardCoordinates() <-chan Coordinate
BoardCoordinates creates an iterator that iterates over ever Coordinate of the Board
func (*Game) GetPlayerById ¶
GetPlaerById finds and return a Player using their Player ID
func (*Game) GetSmallestTeam ¶
GetSmallestTeam when called on a Game returns the Team in the game with the least userse
func (*Game) Join ¶
Adds a new Player to a Game, returns pointer to new Player This should be used to instantiate a new Player
func (*Game) UniqueTeamName ¶
type Orientation ¶
type Orientation uint8
Orientation is integer used to represent the Orientation enum options. Represents the direction a Ship is pointing
const ( VERTICAL Orientation = iota HORIZONTAL )
Orientation is the direction a Ship is pointing towards
type Player ¶
type Player struct { Username string Password string // Pointer to Team this player is on Team *Team Id string Points int // How many hits this player has gotten in a row HitStreak int PreviousTeam *Team }
Player represents a single human user connected to game
type Ship ¶
type Ship struct { Team *Team Size uint8 Orientation Orientation Location Coordinate Health uint8 // Bit-field representing spots hit on this Ship }
Ship represents a single ship
func CheckLocation ¶
func CheckLocation(targetTeam *Team, target Coordinate) *Ship
CheckLocation will loop through each Ship on the target Team and see if any Ships occupy the target space
func (Ship) GetOccupyingSpaces ¶
func (ship Ship) GetOccupyingSpaces() []Coordinate
getOccupyingSpaces returns an array of Coordinates that are occupied by this Ship
func (*Ship) GetOffset ¶
func (ship *Ship) GetOffset(coordinate Coordinate) uint8
GetOffset returns the number of squares a coordinate is away from the "location" of this ship
func (*Ship) Hit ¶
func (ship *Ship) Hit(player *Player, coordinate Coordinate) ShotResult
Hit marks a hit on the Ship and returns either HIT if the Ship is still alive or SINK if dead. If the hit occurred in a spot on the Ship take has already taken damage, the ship health will remain the same and we return REPEAT_HIT
func (*Ship) ShipIcon ¶
func (ship *Ship) ShipIcon(coordinate Coordinate) rune
ShipIcon returns, given a Ship and a coordinate, what icon should be displayed at this coordinate?
type ShotResult ¶
type ShotResult uint8
ShotResult is integer used to represent the ShotResult enum options. Represents the result of fired shot
const ( SINK ShotResult = iota HIT MISS REPEAT_HIT )
ShotResult is the result of a shot, a Hit if it hits a Ship, a miss if it doesn't and a Sink if it was a killing Hit
type Target ¶
Target is the human-way of representing a square most similar to the board game (A1 -> Z26)
func StringToTarget ¶
func (Target) ToCoordinate ¶
func (target Target) ToCoordinate() Coordinate
ToCoordinate converts a Target (base64/number pair ex: B12) to a Coordinate (X,Y pair)
type Team ¶
type Team struct { Name string Game *Game // Array of pointers to Player Players []*Player // Number of Players currently on Team NumPlayers int // A log of shots fired by this Team and shots upon this Team Hits map[*Team][]Coordinate Misses map[*Team][]Coordinate ShotsUpon []Coordinate // This Team's Ships Ships []*Ship DeploymentPoints int }
Team is a collection of Players working together on the same team
func (*Team) NewShip ¶
func (team *Team) NewShip(size uint8, orientation Orientation, coordinate Coordinate) (*Ship, error)
NewShip generates a new Ship and adds it to a Team, then returns a pointer to the new Ship
func (*Team) ShipCoordinates ¶
ShipCoordinates creates an iterator that iterates through the Coordinates of all the ship on a Team. It uses the channel iterator pattern, meaning it creates a Goroutine that loops through all the values and pushes them into a channel to be consumed in the main thread