game

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidRoles

func ValidRoles(roles []Role) error

ValidRoles returns nil error iff list of role-cards roles is valid for mafia game

Types

type ActEndedEvent

type ActEndedEvent struct {
	Player  Player // player acted
	Success bool   // if the action was successful, semantics varies for different roles
	Next    string // nick of a player who should wake up next
}

ActEndedEvent represents result of player's night act

type AlreadyVotedEvent

type AlreadyVotedEvent struct {
	User int64 // id of the player
}

AlreadyVotedEvent represents a situation where player tries to vote more than once

type EventOutput

type EventOutput interface {
	HandleFirstDay(FirstDayEvent) // outputs FirstDayEvent

	HandleVotingStarted(VotingStartedEvent) // outputs VotingStartedEvent
	HandleUnableToVote(UnableToVoteEvent)   // outputs UnableToVoteEvent
	HandleAlreadyVoted(AlreadyVotedEvent)   // outputs AlreadyVotedEvent
	HandleVotingEnded(VotingEndedEvent)     // outputs VotingEndedEvent

	HandleNightStarted(NightStartedEvent)             // outputs NightStartedEvent
	HandleNightAct(NightActEvent)                     // outputs NightActEvent
	HandleUnexpectedActTrial(UnexpectedActTrialEvent) // outputs UnexpectedActTrialEvent
	HandleUnsupportedAct(UnsupportedActEvent)         // outputs UnsupportedActEvent
	HandleActEnded(ActEndedEvent)                     // outputs ActEndedEvent
	HandleNightEnded(NightEndedEvent)                 // outputs NightEndedEvent

	HandleWin(WinEvent)                       // outputs WinEvent
	HandleNotifyStopGame(NotifyStopGameEvent) // outputs NotifyStopGameEvent
}

EventOutput is used as view model for mafia game. Outputs events happening during mafia game

type FirstDayEvent

type FirstDayEvent struct {
	UserToNick map[int64]string // mapping from player's id to nick in the game
	Players    []Player         // slice of players in the game
}

FirstDayEvent represents starting of the first day in the game

type Game

type Game struct {
	NickToUser map[string]int64 // mapping from nick in the game to user
	UserToNick map[int64]string // mapping from user to nick in the game
	Roles      []Role           // list of all role-cards in the game, its len should be equal to number of players
	GActive    *gameActive      // nil iff is game is not started, represents active game otherwise
	// contains filtered or unexported fields
}

Game represents a mafia game either started or not

func NewGame

func NewGame(eOutput EventOutput, code int, creator int64, roles []Role, close func(*Game)) *Game

NewGame returns instance with fields specified in parameters, nil GActive and empty NickToUser and UserToNick maps

func (*Game) AddMember

func (g *Game) AddMember(user int64, nick string) error

AddMember adds a player in Game g with user id as user and nick as game nickname if nick isn't already presented in the game. Returns non-nil error otherwise

func (*Game) GetUsers

func (g *Game) GetUsers() (users []int64)

GetUsers returns list of joined users

func (*Game) RandomPlayerQueue

func (g *Game) RandomPlayerQueue() []Player

RandomPlayerQueue returns a slice of players formed from current list of joined users and roles set in Game g.

func (*Game) Start

func (g *Game) Start(pQueue []Player) error

Start starts Game g if number of players joined is as expected, returns non-nil error otherwise

func (*Game) Started

func (g *Game) Started() bool

Started iff Game g has started

func (*Game) StopGame

func (g *Game) StopGame(notify bool)

StopGame callbacks field close in Game g and notifies in the output of game if notify is true

type NightActEvent

type NightActEvent struct {
	Player     Player   // player acted
	Victims    []string // list of victim selected by player
	MafiaAlive bool     // true iff mafia is alive
}

NightActEvent represents the result of action of a player during the night

type NightEndedEvent

type NightEndedEvent struct {
	Users []int64  // slice of all players' (including dead) ids
	Died  []string // nick of player who died this night
}

NightEndedEvent represents results of night ended

type NightStartedEvent

type NightStartedEvent struct {
	Users       []int64 // slice of all players' (including dead) ids
	FirstToWake string  // nick of the player who should wake up first
}

NightStartedEvent represents start of the night

type NotifyStopGameEvent

type NotifyStopGameEvent struct {
	Users []int64 // slice of all players' (including dead) ids
}

NotifyStopGameEvent represents request for notifying all players about stopping the game

type Player

type Player struct {
	User int64 // user ID
	Role Role  // player's role in the game
}

Player represents player in an active game

type Role

type Role int

Role represents a role in mafia game

const (
	Mafia Role
	Peaceful
	Doctor
	Witness
	Sheriff
	Maniac
	Guesser
)

type Side

type Side int

Side represents a side in mafia game. Only one can win in a game

const (
	MafiaSide Side
	PeacefulSide
	ManiacSide
	GuesserSide
)

type UnableToVoteEvent

type UnableToVoteEvent struct {
	User int64 // id of the player
}

UnableToVoteEvent represents a situation where player tries to vote for not availible for him candidate

type UnexpectedActTrialEvent

type UnexpectedActTrialEvent struct {
	User int64 // id of the player
}

UnexpectedActTrialEvent represents a situation where one of the players tries to act when he is not supposed to

type UnsupportedActEvent

type UnsupportedActEvent struct {
	User int64 // id of the player
}

UnsupportedActEvent represents a situation where player tries to select victims which is not supposed to select

type VotingEndedEvent

type VotingEndedEvent struct {
	Users       []int64          // slice of all players' (including dead) ids
	UserToNick  map[int64]string // mapping from player's id to his nick in the game
	UserToVoted map[int64]int64  // mapping from player's id to id of player he voted for or -1 if skipped
	Candidate   int64            // id of a player who was selected in the voting or 0 in case of draw
	Witness     bool             // true if selected player had been witnessed
}

VotingEndedEvent represents result of the voting

type VotingStartedEvent

type VotingStartedEvent struct {
	UserToCandidates map[int64][]string // mapping from player's id to list of nicks of his candidates for voting
}

VotingStartedEvent represents starting of the voting and holds the information which candidates are availible for players for voting

type WinEvent

type WinEvent struct {
	Users   []int64  // slice of all players' (including dead) ids
	Side    Side     // side winned
	Winners []string // slice of nicks of players winned
}

WinEvent represents win of one of the sides

Jump to

Keyboard shortcuts

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