player

package
v0.0.0-...-e6555c8 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const TeamTypeAttacker = "attacker"

Describes attacker team type

View Source
const TeamTypeDefender = "defender"

Describes defender team type

Variables

This section is empty.

Functions

This section is empty.

Types

type IRepository

type IRepository interface {
	// Fetches the available players in the system
	GetPlayers() []Model
	// Adds a new player to the system
	AddPlayer(Model) error
	// Update by ID
	UpdateByID(ID string, update Model) (Model, error)
	// Finds a user by ID
	FindByID(ID string) (Model, error)
	// Add given amounts of points to a player
	AddPoint(ID string, points int) (Model, error)
}

Describes a repository for the engine

type IService

type IService interface {
	// Adds a new player
	AddPlayer(Model) error
	// Sets a player's online status
	SetPlayerOnlineStatus(ID string, online bool) (Model, error)
	// Finds a player by ID
	FindByID(ID string) (Model, error)
	// Checks if a given player is already registered or not
	IsPlayerExist(*Model) bool
	// Add given amounts of points to a player
	AddPoint(ID string, points int) (Model, error)
	// Fetch a given team completely
	// use Team enums for the string
	GetTeam(team string) []Model
}

Describes a player service interface

func NewService

func NewService(repository IRepository) IService

type Model

type Model struct {
	// ID of the player
	ID string
	// Name of the player
	Name string
	// Team of the player. Either "attacker" or "defender"
	Team string
	// Current score of the individual player
	Score int
	// Online indicator
	Online bool
}

Describes a player in the system who is a user already registered to a given team and (possibly) actively participating in the game

type Repository

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

Engine repository implementation

func NewRepository

func NewRepository() *Repository

Constructor to create a new engine repository

func (*Repository) AddPlayer

func (r *Repository) AddPlayer(user Model) error

func (*Repository) AddPoint

func (r *Repository) AddPoint(ID string, points int) (Model, error)

func (*Repository) FindByID

func (r *Repository) FindByID(ID string) (Model, error)

func (*Repository) GetPlayers

func (r *Repository) GetPlayers() []Model

func (*Repository) UpdateByID

func (r *Repository) UpdateByID(ID string, update Model) (Model, error)

type Service

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

func (Service) AddPlayer

func (s Service) AddPlayer(p Model) error

func (Service) AddPoint

func (s Service) AddPoint(ID string, points int) (Model, error)

func (Service) FindByID

func (s Service) FindByID(ID string) (Model, error)

func (Service) GetTeam

func (s Service) GetTeam(team string) []Model

func (Service) IsPlayerExist

func (s Service) IsPlayerExist(p *Model) bool

func (Service) SetPlayerOnlineStatus

func (s Service) SetPlayerOnlineStatus(ID string, online bool) (Model, error)

Jump to

Keyboard shortcuts

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