arena

package module
v0.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2019 License: GPL-3.0 Imports: 6 Imported by: 0

README

MakeItPlay - Arena

GoDoc Go Report Card

MakeItPlay - Arena is a Go module that provides some shareable features between the game server and the clients of the MakeItPlay football game. This module is meant to be used by the Client Player implemented in Go. However, you may implement another client and use this module as well.

If you wish to use part of this lib for any other project, please let me know if you find bugs, I will fix as soon as I can.

Notes:

  1. Most part of this library code is not tested at the current version (1.0.0-alpha). And there is no plans to improve its tests. I would appreciate if you could help with it, and I would be happy to include your name in the contributors list.
  2. This module uses MakeItPlay Football version 1.0.*-alpha constant values (distance, time, speed). Please, read the game documentation at the Official website for further information about all units.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AwayTeamGoal = Goal{
	Place:      HomeTeam,
	Center:     physics.Point{PosX: units.CourtWidth, PosY: units.CourtHeight / 2},
	TopPole:    physics.Point{PosX: units.CourtWidth, PosY: units.GoalMaxY},
	BottomPole: physics.Point{PosX: units.CourtWidth, PosY: units.GoalMinY},
}

AwayTeamGoal works as a constant value to help to retrieve a Goal struct with the values of the Away team goal

View Source
var CourtCenter = physics.Point{units.CourtWidth / 2, units.CourtHeight / 2}

CourtCenter works as a constant value to help to retrieve a Point struct with the values of the center of the court

View Source
var HomeTeamGoal = Goal{
	Place:      HomeTeam,
	Center:     physics.Point{PosX: 0, PosY: units.CourtHeight / 2},
	TopPole:    physics.Point{PosX: 0, PosY: units.GoalMaxY},
	BottomPole: physics.Point{PosX: 0, PosY: units.GoalMinY},
}

HomeTeamGoal works as a constant value to help to retrieve a Goal struct with the values of the Home team goal

Functions

func Cleanup

func Cleanup(interrupted bool)

Cleanup executes all cleaner functions in the stack passing the arg that tells if the process was interrupted or not

func RegisterCleaner

func RegisterCleaner(name string, callback func(bool))

RegisterCleaner creates a stack of call back functions to be executed when the main process ends

Types

type Cleaner

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

Cleaner binds a callback function and a label to help us to identify the tasks that are executed during the cleaning stack

type GameState

type GameState string

GameState is a game state

const (
	//WaitingTeams game state when the game server is waiting for both team's players connections
	WaitingTeams GameState = "waiting"
	//Listening game state when the game server is listening the player for orders
	Listening GameState = "listening"
	//Playing game state when the game server is executing the orders sent during the last `listening` state
	Playing GameState = "playing"
	//Pause game state when the game server is paused by a debug command and waiting for the `next step` signal
	Pause GameState = "pause"
	//Results game state when the game server is announcing the score change
	Results GameState = "results"
	//Over game state when the game server is is announcing the end of the game
	Over GameState = "game-over"
)

type Goal

type Goal struct {
	// Center the is coordinate of the center of the goal
	Center physics.Point
	// Place identifies the team of this goal (the team that should defend this goal)
	Place TeamPlace
	// TopPole is the coordinates of the pole with a higher Y coordinate
	TopPole physics.Point
	// BottomPole is the coordinates of the pole  with a lower Y coordinate
	BottomPole physics.Point
}

Goal is a set of value about a goal from a team

type JumpOrderData

type JumpOrderData struct {
	Velocity physics.Velocity `json:"velocity"`
}

JumpOrderData is the expected format of the data field of an order when it's type is Jump

type KickOrderData

type KickOrderData struct {
	Velocity physics.Velocity `json:"velocity"`
}

KickOrderData is the expected format of the data field of an order when it's type is KICK

type MoveOrderData

type MoveOrderData struct {
	Velocity physics.Velocity `json:"velocity"`
}

MoveOrderData is the expected format of the data field of an order when it's type is MOVE

type MsgType

type MsgType string

MsgType define strings acceptable as types of game msg

const (
	// ORDER is the msg sent from the player to the game server
	ORDER MsgType = "order"
	// ANNOUNCEMENT is sent from the game server to the players and to the web clients to update them with a new game state
	ANNOUNCEMENT MsgType = "announcement"
	// DEBUG is a message sent by http POST request from the web client to the game server (debug mode must be on)
	DEBUG MsgType = "debug"
	// SCORE is a message sent by the game server when the score was changed
	SCORE MsgType = "score"
	// RIP is a message sent by the game server when the game server crashes
	RIP MsgType = "rip"
	// WELCOME is a message sent by the game server to each player when the new websocket connection is accepted.
	WELCOME MsgType = "welcome"
)

type Order

type Order struct {
	Type OrderType   `json:"order"`
	Data interface{} `json:"data"`
}

Order is a orders sent by the player to the game server during the LISTENING state

func NewCatchOrder

func NewCatchOrder() Order

func NewJumpOrder

func NewJumpOrder(veloticy physics.Velocity) Order

func NewKickOrder

func NewKickOrder(veloticy physics.Velocity) Order

func NewMoveOrder

func NewMoveOrder(veloticy physics.Velocity) Order

func (*Order) GetJumpOrderData

func (o *Order) GetJumpOrderData() JumpOrderData

GetJumpOrderData returns the Data order field in JumpOrderData format

func (*Order) GetKickOrderData

func (o *Order) GetKickOrderData() KickOrderData

GetKickOrderData returns the Data order field in KickOrderData format

func (*Order) GetMoveOrderData

func (o *Order) GetMoveOrderData() MoveOrderData

GetMoveOrderData returns the Data order field in MoveOrderData format

func (*Order) UnmarshalJSON

func (o *Order) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the UnmarshalJSON interface for orders

type OrderType

type OrderType string

OrderType identifies types of orders that are acceptable by the game server

const (

	// MOVE is order to change the direction and speed of the player
	MOVE OrderType = "MOVE"
	// KICK is the order sent by the ball holder to release the ball and changes its direction and speed
	// the current ball direction will be summed with the new direction set by the order
	KICK OrderType = "KICK"
	// CATCH is an order to try to catch the ball, that has to being touched by the player
	CATCH OrderType = "CATCH"
	// JUMP is an action executed only by goal keepers! It allow the goal keeper to use extra speed during a short interval
	JUMP OrderType = "JUMP"
)

type PlayerNumber

type PlayerNumber string

PlayerNumber identifies values for players number

const (
	// GoalkeeperNumber defines the goalkeeper number
	GoalkeeperNumber PlayerNumber = "1"
)

type PlayerSpecifications

type PlayerSpecifications struct {
	// Number identifies the number of the player in its team
	Number PlayerNumber `json:"number"`
	// InitialCoords identifies where default initial player's position is
	InitialCoords physics.Point `json:"initial_coords"`
	// Token should be passed as an argument to the player to ensure that the connection is being openned by the expected process
	Token string `json:"token"`
	// ProtocolVersion identifies the game server communication version the player is compatible with (e.g. 1.0)
	ProtocolVersion string `json:"protocol_version"`
}

PlayerSpecifications is the object that should be present in the HTTP websocket headers connection open by the player with the game server

type Task

type Task struct {
	OnStop func(*Task)
	// contains filtered or unexported fields
}

Task allow us to create a task in background

func NewTask

func NewTask(task func(*Task)) *Task

NewTask creates a new task

func (*Task) IsRunning

func (t *Task) IsRunning() bool

IsRunning returns true if the task it still running

func (*Task) RequestStop

func (t *Task) RequestStop()

RequestStop send a stop request to the task

func (*Task) Start

func (t *Task) Start()

Start starts the task

func (*Task) StopRequested

func (t *Task) StopRequested() bool

StopRequested returns true when the task was requested to stop

type TeamPlace

type TeamPlace string

TeamPlace defines a side of the team during the game (left for home team, and right for the away team)

const AwayTeam TeamPlace = "away"

AwayTeam identify the home team

const HomeTeam TeamPlace = "home"

HomeTeam identify the home team

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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