minesweepersvc

package
v0.0.0-...-14c0c35 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

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

func CheckLost

func CheckLost(status string) bool

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 CellGrid

type CellGrid []Cell

type ClickAction

type ClickAction struct {
	Row       int    `json:"row"`
	Col       int    `json:"col"`
	ClickType string `json:"click_type"`
}

type DB

type DB interface {
	Save(key string, value interface{}) error
	Get(key string) (*User, error)
	GetGame(key string) (*Game, error)
	Exists(key string) bool
	FlushAll() error
}

func NewDB

func NewDB() 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) GetGame

func (s *GameEngineStorage) GetGame(name string) (*Game, 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

func (*MSGameService) GetUser

func (s *MSGameService) GetUser(username string) (*User, error)

func (*MSGameService) Start

func (s *MSGameService) Start(name string) (*Game, 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

type MineSweeperGameStorage interface {
	CreateGame(game *Game) error
	UpdateGame(game *Game) error
	GetGame(name string) (*Game, error)
	CreateUser(u *User) error
	GetUser(username string) (*User, error)
	FlushAll() error // for development purpose
}

type RedisDB

type RedisDB struct {
	redis.Conn
}

func (*RedisDB) Exists

func (r *RedisDB) Exists(key string) bool

func (*RedisDB) FlushAll

func (r *RedisDB) FlushAll() error

func (*RedisDB) Get

func (r *RedisDB) Get(key string) (*User, error)

func (*RedisDB) GetGame

func (r *RedisDB) GetGame(key string) (*Game, error)

func (*RedisDB) Save

func (r *RedisDB) Save(key string, value interface{}) error

type User

type User struct {
	Username  string    `json:"username"`
	CreatedAt time.Time `json:"-"`
}

Directories

Path Synopsis
Package mock_minesweepersvc is a generated GoMock package.
Package mock_minesweepersvc is a generated GoMock package.

Jump to

Keyboard shortcuts

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