application

package
v0.0.0-...-ed902dd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

application implements logic of the game

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDescriptionFieldEnemy

func NewDescriptionFieldEnemy(desc string) descriptionField

NewDescriptionFielEnemy take enemy description string and return it devided to up to three lines and create descriptionField in appriopriate coordinates

func NewDescriptionFieldYours

func NewDescriptionFieldYours(desc string) descriptionField

NewDescriptionFielYours take player description string and return it devided to up to three lines and create descriptionField

func RunApp

func RunApp(ctx context.Context, board boardGUI, client connection.Client)

RunApp takes context, boardGUI interface and Client interface and run a gane. In the for loop function implements running of the programm.

func StartApp

func StartApp(ctx context.Context)

StartApp function is starting a game by opening the main menu geting starting header from it. Creates board and client struct Pass context to child functions and start RunApp function

Types

type Accuracy

type Accuracy struct {
	ShotNumber uint16
	HitNumber  uint16
	// contains filtered or unexported fields
}

Accuracy show and monitor you percentage of hit shot / total number shot

func NewAccuracyField

func NewAccuracyField() Accuracy

NewAccuracyField creates Accuracy in appropriate coordinates

type GuiBoard

type GuiBoard struct {
	Description connection.Description
	// contains filtered or unexported fields
}

GuiBoard contain variables needed to run the board and implements function needed to manipulate GUI and make it interactive ui - contain user interface yourBoard is user board field userBoardState - contain state of user's board enemyBoard is enemy board field enemyBoardState - contain state of enemy's board config - contain configuration of the board Description contain information about user's and enemy's nick and description turnText is field indication whose turn is now versusText is field which tell against whome user play descText is user description field oppDescText is opponent descritpion field fireLogText is field which logs your shots

func NewGuiBoard

func NewGuiBoard(wantLogs bool) GuiBoard

NewGuiBoard create GuiBoard

func (*GuiBoard) BoardListener

func (g *GuiBoard) BoardListener(ctx context.Context, ch chan<- string, t <-chan struct{})

BoardListener listen to user click

func (*GuiBoard) CreateBoard

func (g *GuiBoard) CreateBoard(stateBoard connection.BoardRespons) error

CreateBoard create board of the game

func (*GuiBoard) FireToBoard

func (g *GuiBoard) FireToBoard(coord string, resp connection.FireResponse) error

Upate enemy board with user shots with its result

func (*GuiBoard) HighlighEmptyTiles

func (g *GuiBoard) HighlighEmptyTiles(gotRow int, gotColumn int)

HighlighEmptyTiles algorithm which set fields around the ship to miss and takes row and column coordinates of last shot. Script move clocwise.

func (*GuiBoard) LogMessage

func (g *GuiBoard) LogMessage(message string)

LogMessage log text

func (*GuiBoard) PrintDescription

func (g *GuiBoard) PrintDescription(ctx context.Context) error

PrintDescription print text fields on the board

func (*GuiBoard) SetTurnText

func (g *GuiBoard) SetTurnText(text string)

SetTurnText change text indicating which turn is now

func (*GuiBoard) StartBoard

func (g *GuiBoard) StartBoard(ctx context.Context, quit chan struct{})

StartBoard starting printing board

func (*GuiBoard) StartTimer

func (g *GuiBoard) StartTimer(ctx context.Context)

StartTimer starting timerField which listen how much time left player have to decide on shot

func (*GuiBoard) UpdateShipCountField

func (g *GuiBoard) UpdateShipCountField(shipMastCount int)

UpdateShipCountField update shipLeftCountField on the mast count number of sunken ship

func (*GuiBoard) UpdateTImer

func (g *GuiBoard) UpdateTImer(time int)

UpdateTimer take time and set counter to this number

func (*GuiBoard) UpdateYourBoard

func (g *GuiBoard) UpdateYourBoard(coords []string) error

UpdateYourBoard update user board with enemy shot with indication if enemy missed or hit a ship

type LegendField

type LegendField struct {
	// contains filtered or unexported fields
}

LegendField create legend explaining fields on the board hitLegend explain hit field missLegend explain miss field shipLegend explain ship field

func NewLegendField

func NewLegendField() LegendField

NewLegendField creates LegenField in appriopriate coordinates

type ShipLeftCountField

type ShipLeftCountField struct {
	FourMastField  *gui.Text
	FourMastCount  int
	ThreeMastField *gui.Text
	ThreeMastCount int
	TwoMastField   *gui.Text
	TwoMastCount   int
	OneMastField   *gui.Text
	OneMastCount   int
}

ShipLeftCountField creating fields teling ship left to strike FourMastField text field telling number of four mast ship left FourMastCount number telling how many four mast ship left to strike ThreeMastField text field telling number of three mast ship left ThreeMastCount number telling how many three mast ship left to strike TwoMastField text field telling number of two mast ship left TwoMastCount number telling how many two mast ship left to strike OneMastField text field telling number of one mast ship left OneMastCount number telling how many one mast ship left to strike

func NewShipLeftCountField

func NewShipLeftCountField() ShipLeftCountField

NewShipLeftCountField creates ShipLeftCountField on appropriate coordinates and starting values of ships number

func (*ShipLeftCountField) UpdateFourMastField

func (s *ShipLeftCountField) UpdateFourMastField()

UpdateFourMastField update FourMastField

func (*ShipLeftCountField) UpdateOneMastField

func (s *ShipLeftCountField) UpdateOneMastField()

UpdateOneMastField update OneMastField

func (*ShipLeftCountField) UpdateThreeMastField

func (s *ShipLeftCountField) UpdateThreeMastField()

UpdateThreeMastField update ThreeMastField

func (*ShipLeftCountField) UpdateTwoMastField

func (s *ShipLeftCountField) UpdateTwoMastField()

UpdateTwoMastField update TwoMastField

Directories

Path Synopsis
menu create main menu of the game
menu create main menu of the game
setShips handle a logic to position ships by the player
setShips handle a logic to position ships by the player
contain algoritm which find all ship nodes
contain algoritm which find all ship nodes
timer create a clock which count turn time
timer create a clock which count turn time

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL