Documentation
¶
Index ¶
- Constants
- Variables
- func AddPlayer(name string) (string, bool)
- func Auth(room string, uuid string) bool
- func CalTai(hand uint64, door uint64) int
- func CreateRoom()
- func Exec()
- func FindPlayerByName(name string) int
- func FindPlayerBySocket(socket socketio.Socket) int
- func FindPlayerByUUID(uuid string) int
- func GetNameList(list []*IPlayer) []string
- func GetServer() *socketio.Server
- func GetUUIDList(list []IPlayer) []string
- func IF(condition bool, trueVal, falseVal interface{}) interface{}
- func InitHuTable() bool
- func IsValidTile(tile string) bool
- func Login(name string, socket *socketio.Socket) (string, bool)
- func Logout(socket socketio.Socket)
- func Match() []string
- func NewGameManager() bool
- func RemovePlayer(id int)
- func RemoveRoom(name string)
- func SocketConnect(so socketio.Socket)
- func SocketError(so socketio.Socket, err error)
- func WaitingNum() int
- type Action
- type ActionSet
- type GameManager
- type GameResult
- type IPlayer
- type Player
- func (player *Player) ChangeTiles() []Tile
- func (player *Player) CheckGon(tile Tile) bool
- func (player *Player) CheckHu(tile Tile, tai *int) bool
- func (player *Player) CheckPon(tile Tile) bool
- func (player *Player) CheckTing(max *int) bool
- func (player *Player) ChooseLack() int
- func (player *Player) Command(actionSet ActionSet, command int) Action
- func (player *Player) Draw(drawTile Tile) Action
- func (player *Player) Fail(command int)
- func (player *Player) Gon(tile Tile, Type int, fromID int) int
- func (player *Player) Hu(tile Tile, tai int, Type int, addOneTai, addToRoom bool, fromID int) int
- func (player *Player) Init()
- func (player Player) Name() string
- func (player *Player) Pon(tile Tile)
- func (player Player) Room() string
- func (player Player) Socket() socketio.Socket
- func (player *Player) Success(from int, command int, tile Tile, score int)
- func (player *Player) Tai(tile Tile) int
- func (player *Player) Throw(drawTile Tile) Tile
- type PlayerManager
- type Room
- func (room *Room) Accept(uuid string, callback func(int))
- func (room *Room) AddPlayer(playerList []string)
- func (room Room) BroadcastChange(id int)
- func (room Room) BroadcastCommand(from int, to int, command int, tile Tile, score int)
- func (room Room) BroadcastDraw(id int, num uint)
- func (room Room) BroadcastEnd(data []GameResult)
- func (room Room) BroadcastGameStart()
- func (room Room) BroadcastLack()
- func (room Room) BroadcastReady(name string)
- func (room Room) BroadcastRemainTile(num uint)
- func (room Room) BroadcastRobGon(id int, tile Tile)
- func (room Room) BroadcastStopWaiting()
- func (room Room) BroadcastThrow(id int, tile Tile)
- func (room Room) GetCurrentIdx() int
- func (room Room) GetDoor(id int) ([][]string, []int, bool)
- func (room Room) GetHandCount() []int
- func (room Room) GetHu() ([][]string, bool)
- func (room Room) GetLack() []int
- func (room Room) GetPlayerList() []string
- func (room Room) GetReadyPlayers() []string
- func (room Room) GetRemainCount() int
- func (room Room) GetScore() []int
- func (room Room) GetSea() ([][]string, bool)
- func (room Room) NumPlayer() int
- func (room *Room) RemovePlayer(id int)
- func (room *Room) Run()
- func (room *Room) StopWaiting()
- func (room *Room) WaitToStart()
- type ScoreRecord
- type Suit
- type SuitSet
- func (suitSet *SuitSet) Add(input interface{})
- func (suitSet SuitSet) At(idx int) Tile
- func (suitSet SuitSet) Count() uint
- func (suitSet *SuitSet) Draw() Tile
- func (suitSet SuitSet) Have(tile Tile) bool
- func (suitSet SuitSet) IsContainColor(color int) bool
- func (suitSet SuitSet) IsEmpty() bool
- func (suitSet *SuitSet) Sub(input interface{})
- func (suitSet SuitSet) ToStringArray() []string
- func (suitSet SuitSet) Translate(lack int) uint64
- type Tile
Constants ¶
const ( BeforeStart = iota DealTile ChangeTile ChooseLack IdxTurn )
Game State
const ( WAITING = 0 MATCHED = 1 READY = 2 PLAYING = 4 LEAVE = 8 )
Player's state
Variables ¶
var COMMAND = map[string]int{
"NONE": 0,
"PON": 1,
"GON": 2,
"ONGON": 4,
"PONGON": 8,
"HU": 16,
"ZIMO": 32,
}
COMMAND is a map of command type
Functions ¶
func FindPlayerByName ¶
FindPlayerByName gets player's index by player's name
func FindPlayerBySocket ¶
func FindPlayerBySocket(socket socketio.Socket) int
FindPlayerBySocket gets player's index by player's socket
func FindPlayerByUUID ¶
FindPlayerByUUID gets player's index by player's uuid
func GetNameList ¶
GetNameList returns the list of player's name
func GetUUIDList ¶
GetUUIDList returns the list of player's uuid
func IF ¶
func IF(condition bool, trueVal, falseVal interface{}) interface{}
IF implements ternary conditional operator
func SocketConnect ¶
func SocketConnect(so socketio.Socket)
SocketConnect is callback of socket connect event
func SocketError ¶
func SocketError(so socketio.Socket, err error)
SocketError is callback of socket error event
func WaitingNum ¶
func WaitingNum() int
WaitingNum returns the number of player which state are waiting
Types ¶
type Action ¶
Action represent a command made by player
func JSONToAction ¶
JSONToAction converts json string to action
type GameManager ¶
GameManager represents a gameManager
type GameResult ¶
type GameResult struct { Hand []string Door []string Score int ScoreLog []ScoreRecord }
GameResult represents the result of mahjong
type IPlayer ¶
type IPlayer struct { Name string UUID string Room string Socket *socketio.Socket State int Index int }
IPlayer represents the player's info
func FindPlayerListInRoom ¶
FindPlayerListInRoom gets list of player which in the same room
func FindPlayerListIsSameState ¶
FindPlayerListIsSameState gets list of player which are same state
type Player ¶
type Player struct { Hand SuitSet Door SuitSet VisiableDoor SuitSet DiscardTiles SuitSet HuTiles SuitSet GonRecord [4]int ScoreLog []ScoreRecord Lack int Credit int MaxTai int IsHu bool IsTing bool JustGon bool IsPenalize bool ID int UUID string // contains filtered or unexported fields }
Player represents a player in mahjong
func (*Player) ChangeTiles ¶
ChangeTiles emits to client to get the change tiles
func (*Player) ChooseLack ¶
ChooseLack emits to client to get the choose lack
func (Player) Socket ¶
func (player Player) Socket() socketio.Socket
Socket returns the player's socket
type PlayerManager ¶
type PlayerManager []*IPlayer
PlayerManager represents the array of pointer of IPlayer
var PlayerList PlayerManager
PlayerList is a PlayerManager
type Room ¶
type Room struct { Players []*Player ChangedTiles [4][]Tile ChoosedLack [4]int Deck SuitSet HuTiles SuitSet Waiting bool IO *socketio.Server Name string State int }
Room represents a round of mahjong
func (Room) BroadcastChange ¶
BroadcastChange broadcasts the player's id who already change tiles
func (Room) BroadcastCommand ¶
BroadcastCommand broadcasts the player's id and the command he made
func (Room) BroadcastDraw ¶
BroadcastDraw broadcasts the player's id who draw a tile
func (Room) BroadcastEnd ¶
func (room Room) BroadcastEnd(data []GameResult)
BroadcastEnd broadcasts the game result
func (Room) BroadcastGameStart ¶
func (room Room) BroadcastGameStart()
BroadcastGameStart broadcasts player list
func (Room) BroadcastLack ¶
func (room Room) BroadcastLack()
BroadcastLack broadcasts the player's id who already choose lack
func (Room) BroadcastReady ¶
BroadcastReady broadcasts the player's name who is ready
func (Room) BroadcastRemainTile ¶
BroadcastRemainTile broadcasts remain tile
func (Room) BroadcastRobGon ¶
BroadcastRobGon broadcasts rob gon
func (Room) BroadcastStopWaiting ¶
func (room Room) BroadcastStopWaiting()
BroadcastStopWaiting broadcasts stop waiting signal
func (Room) BroadcastThrow ¶
BroadcastThrow broadcasts the player's id and the tile he threw
func (Room) GetCurrentIdx ¶
GetCurrentIdx returns current index
func (Room) GetHandCount ¶
GetHandCount returns each player's amount of hand
func (Room) GetPlayerList ¶
GetPlayerList returns the list of player's name
func (Room) GetReadyPlayers ¶
GetReadyPlayers returns the name list of ready player
func (Room) GetRemainCount ¶
GetRemainCount returns amount of deck
func (*Room) RemovePlayer ¶
RemovePlayer reomves id th player from this room
func (*Room) WaitToStart ¶
func (room *Room) WaitToStart()
WaitToStart checks if all player in this room are ready and run the mahjong logic
type ScoreRecord ¶
ScoreRecord represents the record of score
func NewScoreRecord ¶
func NewScoreRecord(message string, direct string, player string, tile string, score int) ScoreRecord
NewScoreRecord creates a new scoreRecord
type SuitSet ¶
type SuitSet [3]Suit
SuitSet represents a set of suit
func ArrayToSuitSet ¶
ArrayToSuitSet converts tile array to suit set
func (*SuitSet) Add ¶
func (suitSet *SuitSet) Add(input interface{})
Add adds a tile or a suit set to a suit set
func (SuitSet) IsContainColor ¶
IsContainColor return if suit set contain color
func (*SuitSet) Sub ¶
func (suitSet *SuitSet) Sub(input interface{})
Sub subs a tile or a suit set from a suit set
func (SuitSet) ToStringArray ¶
ToStringArray converts suit set to string array
type Tile ¶
Tile represents a mahjong tile
func StringArrayToTileArray ¶
StringArrayToTileArray converts string array to tile array