Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChooseText ¶
ChooseText randomly chooses a text from the dataset
func Compose ¶ added in v0.1.2
func Compose(t MessageType, payload string) []byte
Compose creates a data string for connections
Types ¶
type Client ¶ added in v0.1.2
type Client struct { // State stores State logic State *State // Name is the username Name string // Conn holds the connection to the server Conn net.Conn }
Client is a state manager for the client
func (*Client) ConfirmUsername ¶ added in v0.1.2
ConfirmUsername sets a username and informs the server about it
type MessageType ¶ added in v0.1.2
type MessageType string
MessageType defines available commands
const ( // ChangeName is for changing usernames // payload = new username ChangeName MessageType = "change-name" // ExitPlayer is for players leaving the game // payload = nil ExitPlayer MessageType = "exit-player" // StartGame is for starting the game // payload = unix timestamp of when it starts StartGame MessageType = "start-game" )
func Parse ¶ added in v0.1.2
func Parse(payload string) (MessageType, string)
Parse returns message type and message itself from a connection
type Other ¶ added in v0.1.2
type Other struct { // Conn holds the connection to the user Conn net.Conn // Name is the username Name string // Progress indicates how far is the user Progress float64 }
Other contains all information needed about other players
type Server ¶ added in v0.1.2
type Server struct { // State stores State logic State *State // Name is the username Name string // Server is an instance of net.Listener to control server logic Server net.Listener // Others has connection to clients Others []*Other // Callback is fired when a message comes Callback func(t MessageType) }
Server is a state manager for the server
func (*Server) StartGame ¶ added in v0.1.2
func (s *Server) StartGame()
StartGame informs client the game is starting
func (*Server) Subscribe ¶ added in v0.1.2
func (s *Server) Subscribe(cb func(t MessageType))
Subscribe creates a callback
type State ¶
type State struct { // CurrWord is an index to State.Words CurrWord int // Words contains the text split by spaces Words []string // StartTime is a timestamp of the first keystroke StartTime time.Time // contains filtered or unexported fields }
State describes the state of a game
func (*State) NextWord ¶
func (s *State) NextWord()
NextWord saves stats of the current word and increments the counter
Click to show internal directories.
Click to hide internal directories.