Documentation ¶
Index ¶
- Constants
- Variables
- type Player
- func (pl *Player) AssignChosen()
- func (pl *Player) CastVote(votedPlayerName string)
- func (pl *Player) CreateRoom(roomName string) *Room
- func (pl *Player) Die()
- func (pl *Player) End()
- func (pl *Player) IncrementVote()
- func (pl *Player) IsEligibleToChat() bool
- func (pl *Player) ResetRound()
- func (pl *Player) Save()
- func (pl *Player) SetVotes(score uint)
- func (pl *Player) StartGame() bool
- type Role
- type Room
- func (r *Room) AddPlayer(player *Player)
- func (r *Room) CanGoToNextStage() bool
- func (r *Room) CheckIfAllVoted() bool
- func (r *Room) CheckIfDoctorSaved() bool
- func (r *Room) CheckIfMafiaVoted() bool
- func (r *Room) End()
- func (r *Room) FindChosenPlayerToDie() *Player
- func (r *Room) FindPlayer(name string) *Player
- func (r *Room) GameOver() (bool, Role)
- func (r *Room) GetMostVotedPlayer() *Player
- func (r *Room) GetName() string
- func (r *Room) GetOwner() *Player
- func (r *Room) GetPlayers() []*Player
- func (r *Room) GetStage() int
- func (r *Room) HasDoctor() bool
- func (r *Room) IsPlaying() bool
- func (r *Room) KickPlayer(pl *Player)
- func (r *Room) NextStage()
- func (r *Room) Reset()
- func (r *Room) SetName(name string)
- func (r *Room) StartGame()
- func (r Room) String() string
Constants ¶
const ( MAFIASTAGE int = iota DOCTORSTAGE ALLSTAGE )
const MINIMUMPLAYERCOUNT = 4
const ROLECOUNT = 3
Variables ¶
var ClientCount uint = 0
Functions ¶
This section is empty.
Types ¶
type Player ¶
type Player struct { RoomOwner bool Room *Room Number uint Name string Job Role Votes uint Dead bool Voted bool Chosen bool }
func (*Player) AssignChosen ¶
func (pl *Player) AssignChosen()
AssignChosen is used by MAFIA members, when they vote to kill a player. This method is necessary, because following the MAFIA vote, the room DOCTOR has a chance to Save a Chosen Player. Keep in mind that the current player must not be DEAD.
func (*Player) CastVote ¶
CastVote is a method used to blame or save the player specified with the votedPlayerName string. Keep in mind that the current player must not be DEAD.
func (*Player) CreateRoom ¶
CreateRoom is used to initialize a room using the name argument.
func (*Player) Die ¶
func (pl *Player) Die()
Die is used on the current player if they have been chosen to die by the others. Keep in mind that the current player must not be DEAD.
func (*Player) End ¶
func (pl *Player) End()
End is a method used to reset all of the stats of the current player, after finishing the game. This is used so that the players return to the Lobby, where they can continue play the game by chatting or creating a new room and so on.
func (*Player) IncrementVote ¶
func (pl *Player) IncrementVote()
IncrementVote is used to ++ the votes of the current player.
func (*Player) IsEligibleToChat ¶
IsEligibleToChat is used to determine if the current player can chat. This depends on the current stage of the game or the alive status of the current player.
func (*Player) ResetRound ¶
func (pl *Player) ResetRound()
ResetRound is used to reset the stats of the current player, after a the room proceeds into the next stage.
func (*Player) Save ¶
func (pl *Player) Save()
Save is called when a player of Role DOCTOR decides to Save the current player from dying. Keep in mind that the current player must not be DEAD.
func (*Player) StartGame ¶
StartGame is a boolean method that starts the game after the owner of the room uses the #START_GAME command. The method returns false, if any of the 2 conditions are not met. 1 : The player calling the method, must be the owner of the room. 2 : The count of the players in the room must be higher than MINIMUMPLAYERCOUNT.
type Room ¶
type Room struct {
// contains filtered or unexported fields
}
func CreateRoom ¶
CreateRoom creates a new room, by using the 2 parameters given as arguments. Name becomes the name of the room and the player becomes owner of the room.
func (*Room) AddPlayer ¶
AddPlayer is used to add new players to the current room. The player given as parameter becomes the leader of the room if the room is empty.
func (*Room) CanGoToNextStage ¶
CanGoToNextStage performs a couple of check-ups that are based on the current stage of the room. For example, if the room is at the MAFIASTAGE, in order to advance to the DOCTORSTAGE, all of the Mafia members that are alive should have casted their votes.
func (*Room) CheckIfAllVoted ¶
CheckIfAllVoted performs a check-up on the players to determine if they have all voted. Keep in mind, this method is used during the ALLSTAGE.
func (*Room) CheckIfDoctorSaved ¶
CheckIfDoctorSaved performs a check-up to determine if they has voted. Keep in mind, this method is used during the DOCTORSTAGE.
func (*Room) CheckIfMafiaVoted ¶
CheckIfMafiaVoted performs a check-up on the MAFIA members to determine if they have all voted. Keep in mind, this method is used during the MAFIASTAGE.
func (*Room) End ¶
func (r *Room) End()
End is used the finish the Game, after either side wins. Every player call its End method, and the current room is discarded.
func (*Room) FindChosenPlayerToDie ¶
FindChosenPlayerToDie loops through the alive players in the current room to find out who has been selected to Die or Be Imprisoned. Returns nil, if there is no such player.
func (*Room) FindPlayer ¶
Searches for a player using their name in the current room
func (*Room) GameOver ¶
GameOver determines who has won the game. The main logic here is that, if MAFIA members become 0, CITIZENS win. Otherwise, if CITIZENS(incl the DOCTOR) become 1 or less than 1, MAFIA win. You might find it interesting that when CITIZENS(incl Doctor) and MAFIA both become 1, MAFIA win, this is because MAFIA will just shoot the alive CITIZEN.
func (*Room) GetMostVotedPlayer ¶
GetMostVotedPlayer loops through the players of the room and finds the one, who has the most votes.
func (*Room) GetOwner ¶
GetOwner finds the owner/leader of the room. If there is no leader, returns nil.
func (*Room) GetPlayers ¶
GetPlayers is a getter for the players of the room.
func (*Room) KickPlayer ¶
KickPlayer is used to remove the given player from the current room.
func (*Room) NextStage ¶
func (r *Room) NextStage()
NextStage changes the current stage of the room.