src

package
v0.0.0-...-07c18fb Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2019 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MAFIASTAGE int = iota
	DOCTORSTAGE
	ALLSTAGE
)
View Source
const MINIMUMPLAYERCOUNT = 4
View Source
const ROLECOUNT = 3

Variables

View Source
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

func (pl *Player) CastVote(votedPlayerName string)

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

func (pl *Player) CreateRoom(roomName string) *Room

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

func (pl *Player) IsEligibleToChat() bool

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) SetVotes

func (pl *Player) SetVotes(score uint)

SetVotes is a simple setter for the Votes of the current player.

func (*Player) StartGame

func (pl *Player) StartGame() bool

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 Role

type Role int
const (
	MAFIA Role = iota
	DOCTOR
	CITIZEN
)

type Room

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

func CreateRoom

func CreateRoom(name string, player *Player) *Room

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 FindRoom

func FindRoom(rooms *[]Room, name string) *Room

Finds the sought room, when JOIN room is called

func (*Room) AddPlayer

func (r *Room) AddPlayer(player *Player)

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

func (r *Room) CanGoToNextStage() bool

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

func (r *Room) CheckIfAllVoted() bool

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

func (r *Room) CheckIfDoctorSaved() bool

CheckIfDoctorSaved performs a check-up to determine if they has voted. Keep in mind, this method is used during the DOCTORSTAGE.

func (*Room) CheckIfMafiaVoted

func (r *Room) CheckIfMafiaVoted() bool

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

func (r *Room) FindChosenPlayerToDie() *Player

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

func (r *Room) FindPlayer(name string) *Player

Searches for a player using their name in the current room

func (*Room) GameOver

func (r *Room) GameOver() (bool, Role)

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

func (r *Room) GetMostVotedPlayer() *Player

GetMostVotedPlayer loops through the players of the room and finds the one, who has the most votes.

func (*Room) GetName

func (r *Room) GetName() string

GetName returns the name of the room.

func (*Room) GetOwner

func (r *Room) GetOwner() *Player

GetOwner finds the owner/leader of the room. If there is no leader, returns nil.

func (*Room) GetPlayers

func (r *Room) GetPlayers() []*Player

GetPlayers is a getter for the players of the room.

func (*Room) GetStage

func (r *Room) GetStage() int

GetStage returns the current stage of the room.

func (*Room) HasDoctor

func (r *Room) HasDoctor() bool

HasDoctor is used to check if the DOCTOR of the room is still alive

func (*Room) IsPlaying

func (r *Room) IsPlaying() bool

IsPlaying checks if the current room is playing.

func (*Room) KickPlayer

func (r *Room) KickPlayer(pl *Player)

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.

func (*Room) Reset

func (r *Room) Reset()

Reset changes after round completion

func (*Room) SetName

func (r *Room) SetName(name string)

SetName is used to change the name of the current room.

func (*Room) StartGame

func (r *Room) StartGame()

StartGame is used by owner/leader of the room to initiate the game. The players inside the room are given roles as DOCTOR/CITIZEN/MAFIA on a random basis. The room starts playing and the stage becomes 0 == MAFIASTAGE.

func (Room) String

func (r Room) String() string

Jump to

Keyboard shortcuts

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