Documentation ¶
Overview ¶
Warships-LightGUI provides an easy to use graphical user interface for the `Warships Online` game.
Index ¶
Examples ¶
Constants ¶
const ( Left pos = iota // indicates player's board (on the left side) Right // indicates enemy's board (on the right side) )
const ( Empty state = iota Hit Miss Ship Border // border around a sunken ship Ruler )
Variables ¶
This section is empty.
Functions ¶
func ConfigParams
deprecated
func ConfigParams() customizer
ConfigParams returns a new config with default values.
Deprecated: use NewConfig instead.
Types ¶
type Board ¶
type Board struct {
// contains filtered or unexported fields
}
Board represents a game board, including both player's (Left) and enemy's (Right) sides.
func New ¶
func New(c *config) *Board
New returns a new Board.
Example (Advanced) ¶
New( NewConfig(). HitChar('#'). HitColor(color.FgRed). BorderColor(color.BgRed). RulerTextColor(color.BgYellow). NewConfig())
Output:
Example (Simple) ¶
cfg := NewConfig() New(cfg)
Output:
func (*Board) CreateBorder ¶
CreateBorder creates a border around a (sunken) ship, to indicate which coordinates cannot contain a ship segment and can be safely ignored.
func (*Board) Export ¶
Export exports ships from either Left (player's) or Right (enemy's) board. The return value is a slice of ship coordinates (using format expected by the game server).
Example ¶
board := New(NewConfig()) coords := []string{"A1", "A2", "A3"} board.Import(coords) exported := board.Export(Left) fmt.Println(exported)
Output: [A3 A2 A1]
func (*Board) HitOrMiss ¶
HitOrMiss updates and returns the state of a coordinate on the board, depending on the previous state:
- Empty -> Miss
- Ship, Hit -> Hit
It returns Miss if the coordinate is invalid.
Parameters:
- p (pos): Left or Right board
- coord (string): a string representing the coordinate (e.g. "A1", "B2")
Returns:
- s (state): updated state value (Empty, Miss, or Hit)
Example ¶
board := New(NewConfig()) board.Set(Left, "A1", Ship) board.HitOrMiss(Left, "A1")
Output:
func (*Board) Import ¶
Import imports player's ships from a slice of coordinates (as returned by the game server) and places them on the Left board.
Example ¶
board := New(NewConfig()) coords := []string{"A1", "A2", "A3"} board.Import(coords)
Output:
func (*Board) Set ¶
Set updates the state of a coordinate on the board.
For the Left board, the function validates the state of the coordinate based on the following logic:
- If the state is Miss and the previous state is not Empty, it does not update the state.
- If the state is Hit and the previous state is not Ship, it does not update the state.
- If the state is Ship and the previous state is not Empty, it does not update the state.
For the Right board, the function does not update the state if the previous state is not Empty.
If the coordinate is invalid, the function does not update the state.
Parameters:
- p (pos): Left or Right board
- coord (string): a string representing the coordinate (e.g. "A1", "B2")
- s (state): the state to update the coordinate to (Empty, Miss, or Ship)
Example (Enemy) ¶
board := New(NewConfig()) board.Set(Right, "C3", Hit)
Output:
Example (Player) ¶
board := New(NewConfig()) board.Set(Left, "A1", Ship)
Output: