gameservice

package
v0.0.0-...-8fa2ce1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmitEvent

func EmitEvent(event Event)

func StartEventDispatcher

func StartEventDispatcher(handleEvent func(Event))

Types

type CardDrawnData

type CardDrawnData struct {
	CardID       int64  `json:"card_id"`
	CardName     string `json:"name"`
	PlayerGameID int64  `json:"player_game_id"`
	PlayerHandID int64  `json:"player_hand_id"`
	GameID       int64  `json:"game_id"`
}

CardDrawnData carries data for a card drawn event

type DessertPlayedData

type DessertPlayedData struct {
	GameID       int64  `json:"game_id"`
	PlayerGameID int64  `json:"player_game_id"`
	PlayerNumber int32  `json:"player_number"`
	DessertName  string `json:"dessert_name"`
	DessertScore int32  `json:"dessert_score"`
	Score        int32  `json:"score"`
	GameOver     bool   `json:"game_over"`
	Success      bool   `json:"success"`
}

DessertPlayedData carries data for a dessert played event

type DrawCardHandlerParams

type DrawCardHandlerParams struct {
	GameID       int64 `json:"game_id"`
	PlayerGameID int64 `json:"player_game_id"`
	PlayerNumber int32 `json:"player_number"`
}

type EndGameData

type EndGameData struct {
	GameID              int64  `json:"game_id"`
	Status              string `json:"status"`
	WinningPlayerGameID int64  `json:"winner_player_game_id"`
	WinningPlayerNumber int32  `json:"winner_player_number"`
	WinningScore        int32  `json:"winning_score"`
}

EndGameData carries data for an end game event

type EndTurnData

type EndTurnData struct {
	GameID              int64  `json:"game_id"`
	Status              string `json:"status"`
	CreatedBy           int64  `json:"created_by"`
	NumberOfPlayers     int32  `json:"number_of_players"`
	CurrentTurn         int32  `json:"current_turn"`
	CurrentPlayerNumber int32  `json:"current_player_number"`
}

EndTurnData carries data for an end turn event

type Event

type Event struct {
	Type EventType
	Data interface{}
}

Event represents a game event

type EventType

type EventType string
const (
	EventTypeCardDrawn         EventType = "CardDrawn"
	EventTypeDessertPlayed     EventType = "DessertPlayed"
	EventTypeSpecialCardPlayed EventType = "SpecialCardPlayed"
	EventTypeScoreUpdate       EventType = "ScoreUpdate"
	EventTypeEndTurn           EventType = "EndTurn"
	EventTypeEndGame           EventType = "EndGame"
)

type GameService

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

func NewGameService

func NewGameService(store db.Store) *GameService

NewGameService creates a new instance of GameService with the provided store

func (*GameService) DrawCardHandler

func (s *GameService) DrawCardHandler(ctx context.Context, arg DrawCardHandlerParams) error

Handles the coordination of services when a player draws a card

func (*GameService) EndGameHandler

func (s *GameService) EndGameHandler(ctx context.Context, gameID int64, playerGameID int64) error

Handles the coordination of services the game is over

func (*GameService) EndTurnHandler

func (s *GameService) EndTurnHandler(ctx context.Context, gameID int64, playerGameID int64) error

Handles the coordination of services when a player's turn is over

func (*GameService) PlayDessertHandler

func (s *GameService) PlayDessertHandler(ctx context.Context, arg PlayDessertHandlerParams) error

Handles the coordination of services when a player play's a dessert

func (*GameService) UpdateScoresForAllPlayers

func (s *GameService) UpdateScoresForAllPlayers(ctx context.Context, gameID int64) error

type PlayDessertHandlerParams

type PlayDessertHandlerParams struct {
	GameID       int64   `json:"game_id"`
	PlayerGameID int64   `json:"player_game_id"`
	DessertName  string  `json:"dessert_name"`
	CardIDs      []int64 `json:"card_ids"`
}

type ScoreUpdateData

type ScoreUpdateData struct {
	PlayerGameID int64  `json:"player_game_id"`
	PlayerID     int64  `json:"player_id"`
	GameID       int64  `json:"game_id"`
	PlayerNumber int32  `json:"player_number"`
	PlayerScore  int32  `json:"player_score"`
	PlayerStatus string `json:"player_status"`
}

ScoreUpdateData carries data for a score update event

type SpecialCardPlayedData

type SpecialCardPlayedData struct {
}

SpecialCardPlayedData carries data for a special card played event

Jump to

Keyboard shortcuts

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