Documentation
¶
Index ¶
- Constants
- type ActionMsgRaw
- type EndRaw
- type ErrorMsgRaw
- type GameStatusMsgRaw
- type GetRoomRaw
- type JoinRoomMsgRaw
- type LeaveRoomMsgRaw
- type LoginMsgRaw
- type Message
- type MessageType
- type MoveMsgRaw
- type Piece
- type Pieces
- type Player
- type PlayerStatus
- func (ps *PlayerStatus) Get(playerId int64) (*PlayerStatusOne, bool)
- func (ps *PlayerStatus) GetByCamp(camp string) (*PlayerStatusOne, bool)
- func (ps *PlayerStatus) GetP1() (*PlayerStatusOne, bool)
- func (ps *PlayerStatus) GetP2() (*PlayerStatusOne, bool)
- func (ps PlayerStatus) IsAllReady() bool
- func (p PlayerStatus) IsFull() bool
- func (ps *PlayerStatus) Join(playerId int64) (s *PlayerStatusOne, err error)
- func (ps *PlayerStatus) Leave(playerId int64) (err error)
- func (ps *PlayerStatus) Next(playerId int64) (po *PlayerStatusOne, err error)
- func (ps *PlayerStatus) Ready(playerId int64) (err error)
- type PlayerStatusOne
- type Point
- type Room
- type RoomStatus
- type SetPieceMsgRaw
- type TablePieces
- type TablePiecesOne
- type TimeToRaw
Constants ¶
View Source
const ( ActionReady = "ready" ActionMove = "move" )
View Source
const ( FitResultAllDie = "bothdie" FitResultP1Win = "p1win" FitResultP2Win = "p2win" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionMsgRaw ¶
type ErrorMsgRaw ¶
type ErrorMsgRaw struct {
Msg string `json:"msg"`
}
type GameStatusMsgRaw ¶
type GameStatusMsgRaw struct { Status RoomStatus `json:"status"` RoomId int64 `json:"room_id"` }
type GetRoomRaw ¶
type GetRoomRaw struct { Status RoomStatus `json:"status"` PlayerStatus PlayerStatus `json:"player_status"` TablePieces TablePieces `json:"table_pieces"` }
type JoinRoomMsgRaw ¶
type JoinRoomMsgRaw struct { RoomId int64 `json:"room_id"` PlayerId int64 `json:"player_id,omitempty"` Camp string `json:"camp"` Status RoomStatus `json:"status"` }
type LeaveRoomMsgRaw ¶
type LeaveRoomMsgRaw struct {
PlayerId int64 `json:"player_id"`
}
type LoginMsgRaw ¶
type LoginMsgRaw struct {
PlayerId int64 `json:"player_id"`
}
type Message ¶
type Message struct { PlayerId int64 `json:"player_id,omitempty"` Type MessageType `json:"type"` Raw json.RawMessage `json:"raw"` }
func NewErrorMsg ¶
func (*Message) MarshalRaw ¶
func (m *Message) MarshalRaw(i interface{})
func (*Message) UnmarshalRaw ¶
type MessageType ¶
type MessageType string
const ( Err MessageType = "err" // 错误 // 游戏状态 GameStatus MessageType = "game_status" // 当用户登录上来之后需要下发游戏状态 // 玩家动作 CreateRoom MessageType = "create_room" // 创建房间 JoinRoom MessageType = "join_room" // 加入房间 LeaveRoom MessageType = "leave_room" // 离开房间 GetRoom MessageType = "get_room" // 获取房间所有信息(重连恢复) SetPiece MessageType = "set_piece" // 摆放棋子 并准备 Move MessageType = "move" // 移动棋子, 如果两个棋子打架则还会包括打架结果 // 系统发送游戏的消息 Start MessageType = "start" // 开始游戏 TimeTo MessageType = "time_to" // 改xx走棋了 //Fit MessageType = "fit" // 两个棋子打架了, 消息体中包含结果 End MessageType = "end" // 结束, 消息体包含结果(谁胜利了) // 命令动作, 将取代timeTo Action MessageType = "action" )
type MoveMsgRaw ¶
type Pieces ¶
func (Pieces) ValidateSet ¶
检查是否摆放完整 camp: p1/p2
type Player ¶
type Player struct { Id int64 `json:"id" xorm:"int(11) pk autoincr index"` InRoomId int64 `json:"in_room_id" xorm:"int(11) index"` Uid string `json:"uid" xorm:"varchar(32) unique"` }
玩家保存则正在进行的游戏房间
type PlayerStatus ¶
type PlayerStatus []*PlayerStatusOne
第一个人就是蓝色方, 第二个是红色方
func (*PlayerStatus) Get ¶
func (ps *PlayerStatus) Get(playerId int64) (*PlayerStatusOne, bool)
func (*PlayerStatus) GetByCamp ¶
func (ps *PlayerStatus) GetByCamp(camp string) (*PlayerStatusOne, bool)
func (*PlayerStatus) GetP1 ¶
func (ps *PlayerStatus) GetP1() (*PlayerStatusOne, bool)
func (*PlayerStatus) GetP2 ¶
func (ps *PlayerStatus) GetP2() (*PlayerStatusOne, bool)
func (PlayerStatus) IsAllReady ¶
func (ps PlayerStatus) IsAllReady() bool
func (PlayerStatus) IsFull ¶
func (p PlayerStatus) IsFull() bool
func (*PlayerStatus) Join ¶
func (ps *PlayerStatus) Join(playerId int64) (s *PlayerStatusOne, err error)
加入房间, 不是准备状态
func (*PlayerStatus) Next ¶
func (ps *PlayerStatus) Next(playerId int64) (po *PlayerStatusOne, err error)
下一个人
type PlayerStatusOne ¶
type PlayerStatusOne struct { PlayerId int64 `json:"player_id"` Ready bool `json:"ready"` Camp string `json:"camp"` // p1, p2 第一个进入房间的是p1 }
func (PlayerStatusOne) IsP1 ¶
func (po PlayerStatusOne) IsP1() bool
type Room ¶
type Room struct { Id int64 `json:"id" xorm:"pk autoincr int(11)"` PlayerId int64 `json:"player_id" xorm:"int(11)"` // 房主 PlayerStatus PlayerStatus `json:"player_status" xorm:"json"` TimeToPlayerId int64 `json:"timeto_player_id" xorm:"int(11)"` // 该谁走棋 WinPlayerId int64 `json:"win_player_id" xorm:"int(11)"` // 胜利方 Status RoomStatus `json:"status" xorm:"tinyint(1)"` // 游戏状态 TablePieces TablePieces `json:"table_pieces" xorm:"json"` // 当前桌面上的棋子, 包括两方 }
房间管理着一局棋局和玩家
type RoomStatus ¶
type RoomStatus int64
const ( WaitPeopleStatus RoomStatus = 1 // 等待玩家加入 WaitReadStatus RoomStatus = 2 // 等待准备 PlayingStatus RoomStatus = 3 // 正在游戏中 EndStatus RoomStatus = 4 // 游戏结束 )
type SetPieceMsgRaw ¶
type TablePieces ¶
type TablePieces struct { P1 *TablePiecesOne `json:"p1"` // 蓝方的棋子 P2 *TablePiecesOne `json:"p2"` // 红方的棋子 }
type TablePiecesOne ¶
Click to show internal directories.
Click to hide internal directories.