Documentation ¶
Index ¶
- Constants
- func ConvertToJSON(input interface{}) (string, error)
- type AddPlayerToGameMessage
- type AddQuizMessage
- type AnswersUpdate
- type BindGameToSessionMessage
- type CancelGameMessage
- type ClientErrorMessage
- type ClientMessage
- type DeleteGameByPin
- type DeleteGameMessage
- type DeleteQuizMessage
- type DeleteSessionMessage
- type DeregisterClientMessage
- type DeregisterGameFromSessionsMessage
- type ErrorToSessionMessage
- type ExtendSessionExpiryMessage
- type Game
- func (g *Game) AddPlayer(sessionid, name string) bool
- func (g *Game) Copy() Game
- func (g *Game) DeletePlayer(sessionid string)
- func (g *Game) GetCurrentQuestion() (bool, GameCurrentQuestion, error)
- func (g *Game) GetGameState() int
- func (g *Game) GetPlayerNames() []string
- func (g *Game) GetPlayers() []string
- func (g *Game) GetQuestionResults() (QuestionResults, error)
- func (g *Game) GetWinners() []PlayerScore
- func (g *Game) Marshal() ([]byte, error)
- func (g *Game) NameExistsInGame(name string) bool
- func (g *Game) NextState() (int, error)
- func (g *Game) RegisterAnswer(sessionid string, answerIndex int) (bool, AnswersUpdate, error)
- func (g *Game) SetQuiz(quiz Quiz)
- func (g *Game) ShowResults() error
- type GameCurrentQuestion
- type GetGameMessage
- type GetGameResult
- type GetGamesMessage
- type GetQuizMessage
- type GetQuizResult
- type GetQuizzesMessage
- type GetSessionMessage
- type GetSessionsMessage
- type HostGameLobbyMessage
- type HostShowGameResultsMessage
- type HostShowQuestionMessage
- type LookupQuizForGameMessage
- type NameExistsInGameError
- type NextQuestionMessage
- type NoSuchGameError
- type PlayerScore
- type PlayerScoreList
- type QueryDisplayChoicesMessage
- type QueryHostResultsMessage
- type QueryPlayerResultsMessage
- type QuestionResults
- type Quiz
- type QuizQuestion
- type RegisterAnswerMessage
- type SendGameMetadataMessage
- type SendQuizzesToClientMessage
- type Session
- type SessionMessage
- type SessionToScreenMessage
- type SetQuizForGameMessage
- type SetSessionGamePinMessage
- type SetSessionScreenMessage
- type ShowResultsMessage
- type StartGameMessage
- type UnexpectedStateError
- type UpdateGameMessage
- type UpdateQuizMessage
Constants ¶
View Source
const ( // Game states: // * The game starts off as GameNotStarted // * When the host starts the game, the state shifts to QuestionInProgress // * When the time is up or if all players have answered, the state shifts // to Show Results // * When the host advances to the next question, the state shifts back to // QuestionInProgress // * When the time is up or if all players have answered, the state shifts // to Show Results // * After all the questions have been answered and the last result is // shown, the state shifts to GameEnded - the UI can then show the // the results of the game (the winners list) // * After that, the game can be deleted // GameNotStarted = iota QuestionInProgress = iota ShowResults = iota GameEnded = iota )
Variables ¶
This section is empty.
Functions ¶
func ConvertToJSON ¶
Types ¶
type AddPlayerToGameMessage ¶
type AddQuizMessage ¶
type AnswersUpdate ¶
type AnswersUpdate struct { AllAnswered bool `json:"allanswered"` Answered int `json:"answered"` TotalPlayers int `json:"totalplayers"` Votes []int `json:"votes"` TotalVotes int `json:"totalvotes"` }
To be sent to the host when a player answers a question
type CancelGameMessage ¶
type ClientErrorMessage ¶
type ClientMessage ¶
type DeleteGameMessage ¶
used by frontend
type DeleteQuizMessage ¶
type DeleteQuizMessage struct {
Quizid int
}
type DeleteSessionMessage ¶
type DeleteSessionMessage struct {
Sessionid string
}
type DeregisterClientMessage ¶
type DeregisterClientMessage struct {
Clientid uint64
}
type DeregisterGameFromSessionsMessage ¶
type DeregisterGameFromSessionsMessage struct {
Sessions []string
}
type ErrorToSessionMessage ¶
type ExtendSessionExpiryMessage ¶
type ExtendSessionExpiryMessage struct {
Sessionid string
}
type Game ¶
type Game struct { Pin int `json:"pin"` Host string `json:"host"` // session ID of game host Players map[string]int `json:"players"` // scores of players PlayerNames map[string]string `json:"playernames"` Quiz Quiz `json:"quiz"` QuestionIndex int `json:"questionindex"` // current question QuestionDeadline time.Time `json:"questiondeadline"` // answers must come in at this time or before PlayersAnswered map[string]struct{} `json:"playersanswered"` CorrectPlayers map[string]struct{} `json:"correctplayers"` // players that answered current question correctly Votes []int `json:"votes"` // number of players that answered each choice GameState int `json:"gamestate"` }
func UnmarshalGame ¶
func (*Game) AddPlayer ¶
Returns true if the player was added - false if the player is already in the game
func (*Game) DeletePlayer ¶
func (*Game) GetCurrentQuestion ¶
func (g *Game) GetCurrentQuestion() (bool, GameCurrentQuestion, error)
Returns true if state was changed
func (*Game) GetGameState ¶
func (*Game) GetPlayerNames ¶
func (*Game) GetPlayers ¶
func (*Game) GetQuestionResults ¶
func (g *Game) GetQuestionResults() (QuestionResults, error)
func (*Game) GetWinners ¶
func (g *Game) GetWinners() []PlayerScore
func (*Game) NameExistsInGame ¶
name should be trimmed of leading and trailing spaces
func (*Game) RegisterAnswer ¶
Returns true if changed
func (*Game) ShowResults ¶
type GameCurrentQuestion ¶
type GameCurrentQuestion struct { QuestionIndex int `json:"questionindex"` TimeLeft int `json:"timeleft"` Answered int `json:"answered"` // number of players that have answered TotalPlayers int `json:"totalplayers"` // number of players in this game Question string `json:"question"` Answers []string `json:"answers"` Votes []int `json:"votes"` TotalVotes int `json:"totalvotes"` TotalQuestions int `json:"totalquestions"` }
Queried by the host - either when the host first displays the question or when the host reconnects
type GetGameMessage ¶
type GetGameMessage struct { Pin int Result chan GetGameResult }
type GetGameResult ¶
type GetGamesMessage ¶
type GetGamesMessage struct {
Result chan []Game
}
type GetQuizMessage ¶
type GetQuizMessage struct { Quizid int Result chan GetQuizResult }
type GetQuizResult ¶
type GetQuizzesMessage ¶
type GetQuizzesMessage struct {
Result chan []Quiz
}
type GetSessionMessage ¶
type GetSessionsMessage ¶
type GetSessionsMessage struct {
Result chan []Session
}
type HostGameLobbyMessage ¶
type HostShowQuestionMessage ¶
type NameExistsInGameError ¶
func NewNameExistsInGameError ¶
func NewNameExistsInGameError(name string, pin int) *NameExistsInGameError
func (*NameExistsInGameError) Error ¶
func (e *NameExistsInGameError) Error() string
type NextQuestionMessage ¶
type NoSuchGameError ¶
type NoSuchGameError struct {
Pin int
}
func NewNoSuchGameError ¶
func NewNoSuchGameError(pin int) *NoSuchGameError
func (*NoSuchGameError) Error ¶
func (e *NoSuchGameError) Error() string
type PlayerScore ¶
type PlayerScoreList ¶
type PlayerScoreList []PlayerScore
func (PlayerScoreList) Len ¶
func (p PlayerScoreList) Len() int
func (PlayerScoreList) Less ¶
func (p PlayerScoreList) Less(i, j int) bool
func (PlayerScoreList) Swap ¶
func (p PlayerScoreList) Swap(i, j int)
type QueryHostResultsMessage ¶
type QuestionResults ¶
type QuestionResults struct { QuestionIndex int `json:"questionindex"` Question string `json:"question"` Answers []string `json:"answers"` Correct int `json:"correct"` Votes []int `json:"votes"` TotalVotes int `json:"totalvotes"` TotalQuestions int `json:"totalquestions"` TotalPlayers int `json:"totalplayers"` TopScorers []PlayerScore `json:"topscorers"` }
type Quiz ¶
type Quiz struct { Id int `json:"id"` Name string `json:"name"` QuestionDuration int `json:"questionDuration"` ShuffleQuestions bool `json:"shuffleQuestions"` ShuffleAnswers bool `json:"shuffleAnswers"` Questions []QuizQuestion `json:"questions"` }
func UnmarshalQuiz ¶
Ingests a single Quiz object in JSON
func UnmarshalQuizzes ¶
Ingests an array of Quiz objects in JSON
func (Quiz) GetQuestion ¶
func (q Quiz) GetQuestion(i int) (QuizQuestion, error)
func (Quiz) NumQuestions ¶
type QuizQuestion ¶
type QuizQuestion struct { Question string `json:"question"` Answers []string `json:"answers"` Correct int `json:"correct"` }
func (QuizQuestion) NumAnswers ¶
func (q QuizQuestion) NumAnswers() int
func (QuizQuestion) ShuffleAnswers ¶
func (q QuizQuestion) ShuffleAnswers() QuizQuestion
func (QuizQuestion) String ¶
func (q QuizQuestion) String() string
type RegisterAnswerMessage ¶
type SendGameMetadataMessage ¶
type Session ¶
type Session struct { Id string `json:"id"` ClientId uint64 `json:"clientid"` Screen string `json:"screen"` Gamepin int `json:"gamepin"` Name string `json:"name"` Admin bool `json:"admin"` Expiry time.Time `json:"expiry"` }
func UnmarshalSession ¶
type SessionMessage ¶
type SessionToScreenMessage ¶
type SetQuizForGameMessage ¶
type SetSessionScreenMessage ¶
type ShowResultsMessage ¶
type StartGameMessage ¶
type UnexpectedStateError ¶
func NewUnexpectedStateError ¶
func NewUnexpectedStateError(state int, message string) *UnexpectedStateError
func (*UnexpectedStateError) Error ¶
func (e *UnexpectedStateError) Error() string
type UpdateGameMessage ¶
type UpdateGameMessage struct {
Game
}
type UpdateQuizMessage ¶
Click to show internal directories.
Click to hide internal directories.