animal

package
v0.0.0-...-292fe0d Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeOut = errors.New("timeout")
)
View Source
var Rooms map[int64]*Room

Functions

func Response

func Response(rsp []MessageRsp)

Types

type Hall

type Hall struct {
	// contains filtered or unexported fields
}
var TheHall *Hall

func (*Hall) Join

func (h *Hall) Join(playerId int64)

func (*Hall) Notify

func (h *Hall) Notify(playerId int64) (err error)

func (*Hall) Service

func (h *Hall) Service()

处理玩家在房间外发送的消息: - CreateRoom - JoinRoom

type MessageRsp

type MessageRsp struct {
	ToPlayerId int64
	Msg        model.Message
}

type Room

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

处理在房间内的所有用户消息

func CreateRoom

func CreateRoom(room model.Room) (r *Room)

func GetRoom

func GetRoom(id int64) (r *Room, exist bool)

func (*Room) GetPlayerIds

func (r *Room) GetPlayerIds() (ids []int64)

func (*Room) Join

func (r *Room) Join(playerId int64) (err error)

当玩家加入房间 - 发送玩家动作

func (*Room) Notify

func (r *Room) Notify(playerId int64) (err error)

通知用户该进行的动作, 只有目标用户会收到消息 用于用户第一次加入房间

func (*Room) Receive

func (r *Room) Receive(ctx context.Context, pid int64, validator func(msg *model.Message) bool) (msg model.Message, err error)

接收一个消息, ctx超时控制

func (*Room) ReceiveAll

func (r *Room) ReceiveAll(validator func(msg *model.Message) bool) (msgs []model.Message, err error)

接收任何一个消息

func (*Room) Send

func (r *Room) Send(pid int64, messageType model.MessageType, raw interface{}) (err error)

func (*Room) Service

func (r *Room) Service()

接受两个人的 准备 消息

func (*Room) Start

func (r *Room) Start()

开始游戏循环

Jump to

Keyboard shortcuts

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