server

package
v0.0.0-...-ec8cf66 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotExistsOnlineUser = errors.New("没有找到该用户")
	ErrUserInRoom          = errors.New("该用户已经在房间内")
	ErrApiParam            = errors.New("接口参数错误")
	ErrUserNotExtsisRoom   = errors.New("用户不在房间中")
	ErrRoomNotExists       = errors.New("房间不存在")
)
View Source
var (
	ErrNotExam = errors.New("已经完成了所有题目")
)

Functions

func GetServer

func GetServer() *hub

func InitServer

func InitServer()

func NewPlayer

func NewPlayer(userId int, isRebot bool) (*player, error)

创建一个玩家 userId 玩家ID isRebot 是否机器人

func NewRoom

func NewRoom(userId int) (*room, error)

创建房间

func SetReload

func SetReload(level int8)

Types

type Connection

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

连接管理

func NewConn

func NewConn(userId int, ws *websocket.Conn) (*Connection, error)

初始化一个新连接

func (*Connection) ReadPump

func (c *Connection) ReadPump()

监听websocket请求信息

func (*Connection) WritePump

func (c *Connection) WritePump()

监听websocket的发送信息

type Game

type Game struct {
	Users  []*player //房间用户列表
	Status int8      //房间状态(0等待1游戏中2满人)
	Count  int8      //当前游戏总局数

	ExamList  []int     //已完成的题库列表
	Answer    chan int8 //开始游戏chan
	GameStart chan bool //chan
	Over      chan bool //离开游戏chan
	// contains filtered or unexported fields
}

func NewGame

func NewGame(r *room) *Game

new game

func (*Game) Close

func (game *Game) Close()

关闭游戏, 清除数据

func (*Game) GameOver

func (game *Game) GameOver(userId int)

中途退出房间

Jump to

Keyboard shortcuts

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