Documentation ¶
Index ¶
- Constants
- func CheckLost(status string) bool
- type Cell
- type CellGrid
- type ClickAction
- type DB
- type Game
- type GameEngineStorage
- func (s *GameEngineStorage) CreateGame(game *Game) error
- func (s *GameEngineStorage) CreateUser(user *User) error
- func (s *GameEngineStorage) FlushAll() error
- func (s *GameEngineStorage) GetGame(name string) (*Game, error)
- func (s *GameEngineStorage) GetUser(username string) (*User, error)
- func (s *GameEngineStorage) UpdateGame(game *Game) error
- type MSGameService
- func (s *MSGameService) Click(name, clickType string, i, j int) (*Game, error)
- func (s *MSGameService) CreateGame(game *Game) error
- func (s *MSGameService) CreateUser(user *User) error
- func (s *MSGameService) FlushAll() error
- func (s *MSGameService) GetUser(username string) (*User, error)
- func (s *MSGameService) Start(name string) (*Game, error)
- type MineSweeperGameService
- type MineSweeperGameStorage
- type RedisDB
- type User
Constants ¶
View Source
const ( Click = "click" InProgress = "in_progress" Lost = "lost" New = "new" Won = "won" )
some default game parameters if the user does not provide those.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cell ¶
type Cell struct { Mine bool `json:"mine"` Clicked bool `json:"clicked"` Flagged bool `json:"flagged"` // add a red flag in the cell Marked bool `json:"marked"` // add a question mark int the cell Coordinates string `json:"coordinates"` }
Cell express the status of every cell in the board.
type ClickAction ¶
type DB ¶
type Game ¶
type Game struct { Name string `json:"name"` Rows int `json:"rows"` Cols int `json:"cols"` Mines int `json:"mines"` Status statuses `json:"-"` //new, in_progress, won, lost S string `json:"status"` Grid []CellGrid `json:"grid,omitempty"` ClickCounter int `json:"-"` Username string `json:"username"` CreatedAt time.Time `json:"created_at,omitempty"` StartedAt time.Time `json:"-"` TimeSpent time.Duration `json:"time_spent"` Points float64 `json:"points,omitempty"` }
Game contains all the structure of the game, user, results, parameters, etc.
type GameEngineStorage ¶
type GameEngineStorage struct {
// contains filtered or unexported fields
}
func NewGameEngineStorage ¶
func NewGameEngineStorage(db DB) *GameEngineStorage
func (*GameEngineStorage) CreateGame ¶
func (s *GameEngineStorage) CreateGame(game *Game) error
func (*GameEngineStorage) CreateUser ¶
func (s *GameEngineStorage) CreateUser(user *User) error
func (*GameEngineStorage) FlushAll ¶
func (s *GameEngineStorage) FlushAll() error
func (*GameEngineStorage) GetUser ¶
func (s *GameEngineStorage) GetUser(username string) (*User, error)
func (*GameEngineStorage) UpdateGame ¶
func (s *GameEngineStorage) UpdateGame(game *Game) error
type MSGameService ¶
type MSGameService struct {
GameStorage MineSweeperGameStorage
}
func (*MSGameService) Click ¶
func (s *MSGameService) Click(name, clickType string, i, j int) (*Game, error)
func (*MSGameService) CreateGame ¶
func (s *MSGameService) CreateGame(game *Game) error
func (*MSGameService) CreateUser ¶
func (s *MSGameService) CreateUser(user *User) error
func (*MSGameService) FlushAll ¶
func (s *MSGameService) FlushAll() error
type MineSweeperGameService ¶
type MineSweeperGameService interface { CreateGame(game *Game) error Start(name string) (*Game, error) Click(name, clickType string, i, j int) (*Game, error) //click type [click, flag, mark] FlushAll() error CreateUser(user *User) error GetUser(username string) (*User, error) }
func NewGameService ¶
func NewGameService(db DB) MineSweeperGameService
type MineSweeperGameStorage ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.