server

package
v0.0.0-...-508256f Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckTimers

func CheckTimers(ctx context.Context, state *State, game *Game) error

func ClueAnswered

func ClueAnswered(state *State, game *Game, board *BoardLayout, clueNumber int, clueDirection string) bool

func FillInGridAnswerAcross

func FillInGridAnswerAcross(startRow, startCol, numRows, numCols int, answer string, grid []string) []string

func FillInGridAnswerDown

func FillInGridAnswerDown(startRow, startCol, numRows, numCols int, answer string, grid []string) []string

func GameID

func GameID() string

func GetGame

func GetGame(state *State) http.HandlerFunc

GetGame gets current game state

func GetLayouts

func GetLayouts(state *State) http.HandlerFunc

GetLayouts uploads a board

func IncrementClue

func IncrementClue(ctx context.Context, state *State, game *Game) error

func InitializeGrid

func InitializeGrid(numRows, numCols int, grid []string, gridNums []int) []string

func NewRouter

func NewRouter() http.Handler

func PlayerClueIDRound

func PlayerClueIDRound(name string, number int, direction string, round int) string

func PostGame

func PostGame(state *State) http.HandlerFunc

PostGame creates a new game state

func PostGuess

func PostGuess(state *State) http.HandlerFunc

PostGuess creates new guess

func PostLayout

func PostLayout(state *State) http.HandlerFunc

PostLayout uploads a board

func PostPlayer

func PostPlayer(state *State) http.HandlerFunc

PostPlayer creates new player in game

func WaitingOnPlayers

func WaitingOnPlayers(currentPlayers []Player, guesses []Guess, currentRound int) []string

Types

type BoardLayout

type BoardLayout struct {
	Admin   bool `json:"admin"`
	Answers *struct {
		Across []string `json:"across"`
		Down   []string `json:"down"`
	} `json:"answers"`
	Author   string      `json:"author"`
	Autowrap interface{} `json:"autowrap"`
	Bbars    interface{} `json:"bbars"`
	Circles  interface{} `json:"circles"`
	Clues    struct {
		Across []string `json:"across"`
		Down   []string `json:"down"`
	} `json:"clues"`
	Code            interface{} `json:"code"`
	Copyright       string      `json:"copyright"`
	Date            string      `json:"date"`
	Dow             string      `json:"dow"`
	Downmap         interface{} `json:"downmap"`
	Editor          string      `json:"editor"`
	Grid            []string    `json:"grid"`
	Gridnums        []int       `json:"gridnums"`
	Hastitle        bool        `json:"hastitle"`
	Hold            interface{} `json:"hold"`
	ID              string      `json:"id" dynamo:"ID,hash"`
	ID2             interface{} `json:"id2"`
	Interpretcolors interface{} `json:"interpretcolors"`
	Jnotes          interface{} `json:"jnotes"`
	Key             interface{} `json:"key"`
	Mini            interface{} `json:"mini"`
	Notepad         interface{} `json:"notepad"`
	Publisher       string      `json:"publisher"`
	Rbars           interface{} `json:"rbars"`
	Shadecircles    interface{} `json:"shadecircles"`
	Size            struct {
		Cols int `json:"cols"`
		Rows int `json:"rows"`
	} `json:"size"`
	Title   string      `json:"title"`
	Track   interface{} `json:"track"`
	Type    interface{} `json:"type"`
	Uniclue bool        `json:"uniclue"`
	Valid   bool        `json:"valid"`
}

func (*BoardLayout) CalculateScore

func (b *BoardLayout) CalculateScore(guess string, number int, direction string) (int, bool)

func (BoardLayout) ClueLabel

func (b BoardLayout) ClueLabel(number int, direction string) int

func (BoardLayout) ClueLabelPosition

func (b BoardLayout) ClueLabelPosition(clueLabel int) (int, int)

func (*BoardLayout) CorrectAnswer

func (b *BoardLayout) CorrectAnswer(clueNumber int, clueDirection string) string

func (BoardLayout) GetClue

func (b BoardLayout) GetClue(number int, direction string, expiresAt *time.Time) Clue

func (BoardLayout) GetLastClue

func (b BoardLayout) GetLastClue(number int, direction string) Clue

func (*BoardLayout) MaskAnswer

func (b *BoardLayout) MaskAnswer(answer string, currentClueNumber int, currentClueDirection string, grid []string) string

func (BoardLayout) Next

func (b BoardLayout) Next(number int, direction string) (int, string)

func (BoardLayout) Prev

func (b BoardLayout) Prev(number int, direction string) (int, string)

type Clue

type Clue struct {
	Number           int        `json:"number"`
	Direction        string     `json:"direction"`
	Description      string     `json:"description"`
	Answer           string     `json:"answer,omitempty"` // ?A?
	Guesses          []Guess    `json:"guesses,omitempty"`
	WaitingOnPlayers []string   `json:"waiting_on_players,omitempty"`
	ExpiresAt        *time.Time `json:"expires_at,omitempty"`
}

type Game

type Game struct {
	ID             string       `json:"id"`
	BoardLayout    *BoardLayout `json:"layout"`
	LastClue       Clue         `json:"last_clue"`
	CurrentClue    Clue         `json:"current_clue"`
	CurrentPlayers []Player     `json:"current_players"`
	CurrentRound   int          `json:"-"`
}

func FetchGame

func FetchGame(ctx context.Context, state *State, gameID string) (*Game, error)

type GameState

type GameState struct {
	ID                   string `dynamo:"ID,hash"`
	BoardID              string
	CreatedAt            time.Time
	UpdatedAt            time.Time
	CurrentClueNumber    int
	CurrentClueDirection string
	CurrentClueExpiresAt time.Time
	CurrentRound         int
	LastClueNumber       int
	LastClueDirection    string
}

type Guess

type Guess struct {
	Player      Player    `json:"player" dynamo:"-"`
	Clue        Clue      `json:"-" dynamo:"-"`
	Guess       string    `json:"guess"`
	Score       int       `json:"score"`
	SubmittedAt time.Time `json:"submitted_at"`
	IsCorrect   bool      `json:"-"`
	LatestRound int       `json:"-"`
}

func AddOrSetGuess

func AddOrSetGuess(board *BoardLayout, g Guess, guesses []Guess) []Guess

type GuessState

type GuessState struct {
	GameID       string `dynamo:"GameID,hash"`
	PlayerClueID string `dynamo:",range"`
	CreatedAt    time.Time
	UpdatedAt    time.Time
	Guess        string
}

func (GuessState) ClueDirection

func (g GuessState) ClueDirection() string

func (GuessState) ClueNumber

func (g GuessState) ClueNumber() int

func (GuessState) PlayerName

func (g GuessState) PlayerName() string

func (GuessState) Round

func (g GuessState) Round() int

type Player

type Player struct {
	Name         string  `json:"name"`
	CurrentScore int     `json:"current_score"`
	Guesses      []Guess `json:"-"`
	Active       bool    `json:"active"`
}

type PlayerState

type PlayerState struct {
	GameID     string `dynamo:"GameID,hash"`
	PlayerName string `dynamo:",range"`
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

type State

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

func NewState

func NewState() *State

func (*State) CreateBoardLayout

func (state *State) CreateBoardLayout(w BoardLayout) error

func (*State) CreateGame

func (state *State) CreateGame(ctx context.Context, boardID string) (string, error)

func (*State) CreateGuess

func (state *State) CreateGuess(ctx context.Context, gameID, name string, clueNumber int, clueDirection, guess string, round int) error

func (*State) CreatePlayer

func (state *State) CreatePlayer(ctx context.Context, gameID, name string) error

func (*State) GetBoardLayout

func (state *State) GetBoardLayout(ctx context.Context, id string) (*BoardLayout, error)

func (*State) GetBoardLayouts

func (state *State) GetBoardLayouts(ctx context.Context) ([]BoardLayout, error)

func (*State) GetGame

func (state *State) GetGame(ctx context.Context, gameID string) (*GameState, error)

func (*State) GetGuesses

func (state *State) GetGuesses(ctx context.Context, gameID string) ([]GuessState, error)

func (*State) GetPlayers

func (state *State) GetPlayers(ctx context.Context, gameID string) ([]PlayerState, error)

func (*State) UpdateGameClue

func (state *State) UpdateGameClue(ctx context.Context, id string, number int, direction string, lastNumber int, lastDirection string, round int) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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