Documentation ¶
Index ¶
- func ValidRoles(roles []Role) error
- type ActEndedEvent
- type AlreadyVotedEvent
- type EventOutput
- type FirstDayEvent
- type Game
- type NightActEvent
- type NightEndedEvent
- type NightStartedEvent
- type NotifyStopGameEvent
- type Player
- type Role
- type Side
- type UnableToVoteEvent
- type UnexpectedActTrialEvent
- type UnsupportedActEvent
- type VotingEndedEvent
- type VotingStartedEvent
- type WinEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidRoles ¶
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 ¶
NewGame returns instance with fields specified in parameters, nil GActive and empty NickToUser and UserToNick maps
func (*Game) AddMember ¶
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) RandomPlayerQueue ¶
RandomPlayerQueue returns a slice of players formed from current list of joined users and roles set in Game g.
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 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