models

package
v0.0.0-...-cb97648 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Game

type Game struct {
	gorm.Model
	sttt.Game
	JoinID    string `gorm:"unique"` // The joining key that players use to pair manually
	Player1ID int
	Player1   User // "X"
	Player2ID int
	Player2   User // "O"
	WinnerID  int
	Winner    User
	State     State
	StartTime time.Time
	Duration  time.Duration
	Password  string
}

Game wraps the sttt Game class, providing some extra information for our use, like what userids are participating. It does _not_ save the full game state; that's just saved in memory. We only hit the database when saving a completed game.

func NewGame

func NewGame() *Game

NewGame creates and initializes a new game.

func (g Game) GetLink() string

GetLink returns the URL to view or participate in a game.

type State

type State int

State describes what state the game is in

const (
	// InProgress describes a game that has been created, but not won or tied.
	InProgress State = iota

	// Won represents a game that either one player won, or the other player
	// resigned.
	Won

	// Abandoned references a game that is not won, but is more than a month
	// old.
	Abandoned

	// Tied references a game that has been played into such a state that
	// neither player can win. For example, if the top level grid is
	//   X | O |
	//  ---+---+---
	//   O |   | X
	//  ---+---+---
	//     | X | O
	// then no matter who takes the last three squares, nobody can attain three
	// top-level squares in a row.
	Tied
)

type User

type User struct {
	gorm.Model
	Name     string
	Email    string
	Password string // TODO: hash with an auth lib; set `gorm:"size:255"`
}

A User is a user. You probably don't need this explained.

Jump to

Keyboard shortcuts

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