clients

package
v0.0.0-...-192a9cc Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clients

type Clients map[*websocket.Conn]Player

Clients maps websocket connections to players

func (Clients) GetPlayers

func (c Clients) GetPlayers() (list Players)

GetPlayers returns a slice of all the players' names

func (Clients) GetWinners

func (c Clients) GetWinners(comp int) (list Players)

GetWinners returns a slice of the winner(s) of the game, if any

func (Clients) ScoreAnswers

func (c Clients) ScoreAnswers(answers map[string][]*websocket.Conn)

ScoreAnswers calculates the players' scores each round

type Gamewinners

type Gamewinners struct {
	Winners string `json:"winners"`
}

Gamewinners JSON encodes the list of winners

type Player

type Player struct {
	Answer string `json:"answer"`
	Name   string `json:"name"`
	Color  string `json:"color"`
	Score  int    `json:"score"`
}

Player holds info on each player: last answer, name, color, and score

func InitPlayer

func InitPlayer(name, color string) (p Player)

InitPlayer initializes a player struct

func (Player) UpdatePlayerAnswer

func (p Player) UpdatePlayerAnswer(s string) (newplayer Player)

UpdatePlayerAnswer takes a player and their sanitized but otherwise unprocessed answer (as they entered it) and returns a new updated player

type PlayerJSON

type PlayerJSON struct {
	Player Player `json:"player"`
}

PlayerJSON adds a player key to the resulting JSON to ease parsing on the front end

type Players

type Players struct {
	Players []Player `json:"players"`
}

Players lists all players to populate the scoreboard

func (Players) FormatWinners

func (ps Players) FormatWinners() (gw Gamewinners)

FormatWinners builds a string of winners' names and returns it in a struct

Jump to

Keyboard shortcuts

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