game

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2019 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogStandard = iota
	LogDebug
	LogVerbose
)
View Source
const (
	DefaultPort   = 1984
	DefaultServer = "netris.rocketnine.space"
)
View Source
const (
	CommandQueueSize = 10
	LogQueueSize     = 10
	PlayerHost       = -1
	PlayerUnknown    = 0
)
View Source
const ConnTimeout = 30 * time.Second
View Source
const UpdateDuration = 850 * time.Millisecond

Variables

This section is empty.

Functions

func NetworkAndAddress

func NetworkAndAddress(address string) (string, string)

func Nickname

func Nickname(nick string) string

Types

type ClientInterface

type ClientInterface interface {
	Attach(in chan<- GameCommandInterface, out <-chan GameCommandInterface)
	Detach(reason string)
}

type Command

type Command int
const (
	CommandUnknown Command = iota
	CommandDisconnect
	CommandPing
	CommandPong
	CommandNickname
	CommandMessage
	CommandNewGame
	CommandJoinGame
	CommandQuitGame
	CommandUpdateGame
	CommandStartGame
	CommandGameOver
	CommandUpdateMatrix
	CommandSendGarbage
	CommandReceiveGarbage
)

The order of these constants must be preserved

func (Command) String

func (c Command) String() string

type ConnectingPlayer

type ConnectingPlayer struct {
	Client ClientInterface

	Name string
}

type Game

type Game struct {
	Rank     int
	Minos    []mino.Mino
	Seed     int64
	Players  map[int]*Player
	FallTime time.Duration

	Event chan interface{}

	Started            bool
	Starting           bool
	GameOver           bool
	SentGameOverMatrix bool
	Terminated         bool

	LocalPlayer int
	NextPlayer  int

	LogLevel int

	Local bool

	*sync.Mutex
	// contains filtered or unexported fields
}

func NewGame

func NewGame(rank int, out func(GameCommandInterface), logger chan string, draw chan event.DrawObject) (*Game, error)

func (*Game) AddPlayer

func (g *Game) AddPlayer(p *Player)

func (*Game) AddPlayerL

func (g *Game) AddPlayerL(p *Player)

func (*Game) HandleReadCommands

func (g *Game) HandleReadCommands(in chan GameCommandInterface)

func (*Game) Log

func (g *Game) Log(level int, a ...interface{})

func (*Game) Logf

func (g *Game) Logf(level int, format string, a ...interface{})

func (*Game) ProcessAction

func (g *Game) ProcessAction(a event.GameAction)

func (*Game) RemovePlayer

func (g *Game) RemovePlayer(playerID int)

func (*Game) RemovePlayerL

func (g *Game) RemovePlayerL(playerID int)

func (*Game) Reset

func (g *Game) Reset()

func (*Game) ResetL

func (g *Game) ResetL()

func (*Game) Start

func (g *Game) Start(seed int64) int64

func (*Game) StartL

func (g *Game) StartL(seed int64) int64

func (*Game) StopL

func (g *Game) StopL()

func (*Game) WriteAll

func (g *Game) WriteAll(gc GameCommandInterface)

func (*Game) WriteAllAndLogL

func (g *Game) WriteAllAndLogL(gc GameCommandInterface)

func (*Game) WriteAllL

func (g *Game) WriteAllL(gc GameCommandInterface)

func (*Game) WriteMessage

func (g *Game) WriteMessage(message string)

type GameCommand

type GameCommand struct {
	SourcePlayer int
}

func (*GameCommand) SetSource

func (gc *GameCommand) SetSource(source int)

func (*GameCommand) Source

func (gc *GameCommand) Source() int

type GameCommandGameOver

type GameCommandGameOver struct {
	GameCommand
	Player int
	Winner string
}

func (GameCommandGameOver) Command

func (gc GameCommandGameOver) Command() Command

type GameCommandInterface

type GameCommandInterface interface {
	Command() Command
	Source() int
	SetSource(int)
}

type GameCommandJoinGame

type GameCommandJoinGame struct {
	GameCommand
	Name     string
	GameID   int
	PlayerID int
}

func (GameCommandJoinGame) Command

func (gc GameCommandJoinGame) Command() Command

type GameCommandMessage

type GameCommandMessage struct {
	GameCommand
	Player  int
	Message string
}

func (GameCommandMessage) Command

func (gc GameCommandMessage) Command() Command

type GameCommandNickname

type GameCommandNickname struct {
	GameCommand

	Player   int
	Nickname string
}

func (GameCommandNickname) Command

func (gc GameCommandNickname) Command() Command

type GameCommandPing

type GameCommandPing struct {
	GameCommand
	Message string
}

func (GameCommandPing) Command

func (gc GameCommandPing) Command() Command

type GameCommandPong

type GameCommandPong struct {
	GameCommand
	Message string
}

func (GameCommandPong) Command

func (gc GameCommandPong) Command() Command

type GameCommandQuitGame

type GameCommandQuitGame struct {
	GameCommand
	Player int
}

func (GameCommandQuitGame) Command

func (gc GameCommandQuitGame) Command() Command

type GameCommandReceiveGarbage

type GameCommandReceiveGarbage struct {
	GameCommand
	Lines int
}

func (GameCommandReceiveGarbage) Command

func (gc GameCommandReceiveGarbage) Command() Command

type GameCommandSendGarbage

type GameCommandSendGarbage struct {
	GameCommand
	Lines int
}

func (GameCommandSendGarbage) Command

func (gc GameCommandSendGarbage) Command() Command

type GameCommandStartGame

type GameCommandStartGame struct {
	GameCommand
	Seed    int64
	Started bool
}

func (GameCommandStartGame) Command

func (gc GameCommandStartGame) Command() Command

type GameCommandTransport

type GameCommandTransport struct {
	Command Command `json:"cmd"`
	Data    json.RawMessage
}

type GameCommandUpdateGame

type GameCommandUpdateGame struct {
	GameCommand
	Players map[int]string
}

func (GameCommandUpdateGame) Command

func (gc GameCommandUpdateGame) Command() Command

type GameCommandUpdateMatrix

type GameCommandUpdateMatrix struct {
	GameCommand
	Matrixes map[int]*mino.Matrix
}

func (GameCommandUpdateMatrix) Command

func (gc GameCommandUpdateMatrix) Command() Command

type IncomingPlayer

type IncomingPlayer struct {
	Name string
	Conn *ServerConn
}

type Player

type Player struct {
	Name string

	*ServerConn

	Score   int
	Preview *mino.Matrix
	Matrix  *mino.Matrix
	// contains filtered or unexported fields
}

func NewPlayer

func NewPlayer(name string, conn *ServerConn) *Player

type Server

type Server struct {
	I []ServerInterface

	In  chan GameCommandInterface
	Out chan GameCommandInterface

	NewPlayers chan *IncomingPlayer

	Games map[int]*Game

	Logger chan string

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewServer

func NewServer(si []ServerInterface) *Server

func (*Server) FindGame

func (s *Server) FindGame(p *Player, gameID int) *Game

func (*Server) Listen

func (s *Server) Listen(address string)

func (*Server) Log

func (s *Server) Log(a ...interface{})

func (*Server) Logf

func (s *Server) Logf(format string, a ...interface{})

func (*Server) NewGame

func (s *Server) NewGame() (*Game, error)

func (*Server) StopListening

func (s *Server) StopListening()

type ServerConn

type ServerConn struct {
	Conn   net.Conn
	Player int

	In chan GameCommandInterface

	ForwardOut chan GameCommandInterface

	LastTransfer time.Time

	Terminated bool

	*sync.WaitGroup
	// contains filtered or unexported fields
}

func Connect

func Connect(address string) *ServerConn

func NewServerConn

func NewServerConn(conn net.Conn, forwardOut chan GameCommandInterface) *ServerConn

func (*ServerConn) Close

func (s *ServerConn) Close()

func (*ServerConn) JoinGame

func (s *ServerConn) JoinGame(name string, gameID int, logger chan string, draw chan event.DrawObject) (*Game, error)

func (*ServerConn) Write

func (s *ServerConn) Write(gc GameCommandInterface)

type ServerInterface

type ServerInterface interface {
	// Load config
	Host(newPlayers chan<- *IncomingPlayer)
	Shutdown(reason string)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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