game

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// maximum preparation time.
	// If no one connects after this time, just shut down the game
	MaxReadyTime int64 = 20

	// maximum number of frames per game
	MaxGameFrame uint32 = 30*60*3 + 100

	// the interval of broadcast frame data
	BroadcastOffsetFrames = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Game

type Game struct {
	State GameState
	// contains filtered or unexported fields
}

Game represents a game

func NewGame

func NewGame(id uint64, players []uint64, randomSeed int32, listener gameListener) *Game

NewGame builds a game meta

func (*Game) Cleanup

func (g *Game) Cleanup()

Cleanup clears the game's info

func (*Game) Close

func (g *Game) Close()

Close closes the game

func (*Game) JoinGame

func (g *Game) JoinGame(pid uint64, conn *network.Conn) bool

JoinGame user joins game

func (*Game) LeaveGame

func (g *Game) LeaveGame(pid uint64) bool

LeaveGame user leaves game

func (*Game) ProcessMsg

func (g *Game) ProcessMsg(pid uint64, msg *pb_packet.Packet)

ProcessMsg handles the message

func (*Game) Result

func (g *Game) Result() map[uint64]uint64

Result returns the game result

func (*Game) Tick

func (g *Game) Tick(now int64) bool

Tick is the main logic

type GameState

type GameState int

GameState the state of the game

type Player

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

Player defines a player state

func NewPlayer

func NewPlayer(id uint64, idx int32) *Player

NewPlayer creates a new player state

func (*Player) Cleanup

func (p *Player) Cleanup()

func (*Player) Connect

func (p *Player) Connect(conn *network.Conn)

func (*Player) GetLastHeartbeatTime

func (p *Player) GetLastHeartbeatTime() int64

func (*Player) GetSendFrameCount

func (p *Player) GetSendFrameCount() uint32

func (*Player) IsOnline

func (p *Player) IsOnline() bool

func (*Player) RefreshHeartbeat

func (p *Player) RefreshHeartbeat()

func (*Player) SendMessage

func (p *Player) SendMessage(msg network.Packet)

func (*Player) SetSendFrameCount

func (p *Player) SetSendFrameCount(c uint32)

Jump to

Keyboard shortcuts

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