common

package
v0.0.0-...-2924a1e Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HOST_IP       = "127.0.0.1"
	PORT_NUM      = "1947"
	NAME          = "Player"
	DIFFICULTY    = 30
	WORLD_WIDTH   = 20
	WORLD_HEIGHT  = 20
	NUM_MONSTERS  = 5
	NUM_HEALTHS   = 10
	NUM_STRENGTHS = 10
	NUM_TREASURES = 10
	NUM_BOMBS     = 10
	NUM_PORTALS   = 10
	CAPACITY      = 2
	VOLUME        = 10
	DYNAMIC       = true
)
View Source
const (
	MENU_WIDTH       = 30
	MENU_HEIGHT      = 5
	MAX_MSGS_DISPLAY = 9
	STATUS_LEN       = 29
	STRENGTH_LOST    = -1
)
View Source
const (
	AttrBold tb.Attribute = 1 << (iota + 9)
	AttrUnderline
	AttrReverse
)
View Source
const (
	AttrColorDefault tb.Attribute = iota
	AttrColorBlack
	AttrColorRed
	AttrColorGreen
	AttrColorYellow
	AttrColorBlue
	AttrColorMagenta
	AttrColorCyan
	AttrColorWhite
)
View Source
const (
	ColorBlack   = AttrColorBlack & ^AttrBold
	ColorRed     = AttrColorRed & ^AttrBold
	ColorGreen   = AttrColorGreen & ^AttrBold
	ColorYellow  = AttrColorYellow & ^AttrBold
	ColorBlue    = AttrColorBlue & ^AttrBold
	ColorMagenta = AttrColorMagenta & ^AttrBold
	ColorCyan    = AttrColorCyan & ^AttrBold
	ColorWhite   = AttrColorWhite & ^AttrBold
)
View Source
const (
	BoldColorBlack   = AttrColorBlack | AttrBold
	BoldColorRed     = AttrColorRed | AttrBold
	BoldColorGreen   = AttrColorGreen | AttrBold
	BoldColorYellow  = AttrColorYellow | AttrBold
	BoldColorBlue    = AttrColorBlue | AttrBold
	BoldColorMagenta = AttrColorMagenta | AttrBold
	BoldColorCyan    = AttrColorCyan | AttrBold
	BoldColorWhite   = AttrColorWhite | AttrBold
)

Variables

This section is empty.

Functions

func Biased

func Biased(bias int) bool

func LogError

func LogError(e error)

func LogPanic

func LogPanic(e error)

func MouseToRelative

func MouseToRelative(p ICreature, x, y int) (int, int)

func MoveRandomly

func MoveRandomly() (int, int)

func MoveToGameObject

func MoveToGameObject(m IGameObject, p IGameObject) (int, int)

func RandomNumber

func RandomNumber(min int, max int) int

func UUID

func UUID() string

Types

type Config

type Config struct {
	Multiplayer bool
	Server      bool
	Host        string
	Port        string
	Name        string

	Difficulty   int
	WorldWidth   int
	WorldHeight  int
	Capacity     int
	NumMonsters  int
	NumHealths   int
	NumStrengths int
	NumTreasures int
	NumBombs     int
	NumPortals   int

	Volume         int
	Dynamic        bool
	MenuWidth      int
	MenuHeight     int
	NumMsgsDisplay int
}

func NewConfig

func NewConfig() *Config

func (*Config) Init

func (c *Config) Init()

type EventManager

type EventManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewEventManager

func NewEventManager() *EventManager

func (*EventManager) Clear

func (em *EventManager) Clear(event string)

func (*EventManager) Count

func (em *EventManager) Count() int

func (*EventManager) Empty

func (em *EventManager) Empty()

func (*EventManager) Events

func (em *EventManager) Events() []string

func (*EventManager) Fire

func (em *EventManager) Fire(event string, params ...interface{}) ([]reflect.Value, error)

func (*EventManager) FireBackground

func (em *EventManager) FireBackground(event string, params ...interface{}) (chan []reflect.Value, error)

func (*EventManager) HasEvent

func (em *EventManager) HasEvent(event string) bool

func (*EventManager) On

func (em *EventManager) On(event string, function interface{})

type IBomb

type IBomb interface {
	ICreature

	Explode(bool)
}

type IConnection

type IConnection interface {
	Run()
	Count() int
}

type ICreature

type ICreature interface {
	IGameObject

	Move(bool, int, int)
	Next(bool, int, int)
	GetNext() (int, int)
	Battle(func(ICreature))
	ChangeHealth(bool, int)
	ChangeStrength(bool, int)
	ChangeTreasure(bool, int)
	GetHealth() int
	GetStrength() int
	GetTreasure() int
	Dead() bool
	Stay(bool)
	Release(bool)
	Halted() bool
	LoadRooms(IRooms)
}

type IGameManager

type IGameManager interface {
	Event(string, ...interface{})
}

type IGameObject

type IGameObject interface {
	Start(bool)
	Stop(bool)
	Run(bool)
	Running() bool
	Loop(int, int, func())
	Body()
	Delete(bool)
	Deleted() bool

	GetClass() string
	SetName(bool, string)
	GetName() string
	GetSymbol() rune
	SetColor(tb.Attribute)
	GetColor() tb.Attribute
	SetID(bool, string)
	GetID() string
	SetPosition(bool, int, int)
	GetPosition() (int, int)

	JSON() ([]byte, error)
	Event(string) *Message
}

type IGameObjectMap

type IGameObjectMap interface {
	Set(string, IGameObject)
	Get(string) (IGameObject, error)
	Delete(string)
	Len() int
	GetMap() map[string]IGameObject
	GetKeys() []string
	GetValues() []IGameObject
	GetRandomKey() (string, error)
	GetRandomValue() (IGameObject, error)
}

type IHealth

type IHealth interface {
	IItem
}

type IItem

type IItem interface {
	IGameObject

	GetPoints() int
}

type IMissle

type IMissle interface {
	ICreature

	Flash()
}

type IMonster

type IMonster interface {
	ICreature

	Blink()
	SetPlayer(bool, string)
	LoadPlayers(IGameObjectMap)
	LoadPlayer()
}

type IPlayer

type IPlayer interface {
	ICreature

	Collect(bool)
}

type IPortal

type IPortal interface {
	ICreature

	Teleport()
}

type IRing

type IRing interface {
	SetCapacity(size int)
	Capacity() int
	Enqueue(i interface{})
	Dequeue() interface{}
	Peek() interface{}
	Values() []interface{}
	Empty() []interface{}
	Clear()
}

type IRoom

type IRoom interface {
	HasRoom() bool
	HasRoomForTwo() bool
	Enter(bool, IGameObject)
	Leave(bool, IGameObject)
	GetCreatures() []ICreature
	GetHealths() []IHealth
	GetStrengths() []IStrength
	GetTreasures() []ITreasure
	GetGameObjects() []IGameObject
}

type IRooms

type IRooms interface {
	HasRoom(int, int) bool
	HasRoomForTwo(int, int) bool
	Enter(bool, int, int, IGameObject)
	Leave(bool, int, int, IGameObject)
	GetCreatures(int, int) []ICreature
	GetHealths(int, int) []IHealth
	GetStrengths(int, int) []IStrength
	GetTreasures(int, int) []ITreasure
	GetGameObjects(int, int) []IGameObject
}

type IStrength

type IStrength interface {
	IItem
}

type ITreasure

type ITreasure interface {
	IItem
}

type Message

type Message struct {
	Class       string
	ID          string
	Action      string
	Params      map[string]string
	MultiParams map[string][]string
}

func NewMessage

func NewMessage(class, id, action string) *Message

func (*Message) JSON

func (m *Message) JSON() ([]byte, error)

type Ring

type Ring struct {
	DefaultCapacity int

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRing

func NewRing() *Ring

func (*Ring) Capacity

func (r *Ring) Capacity() int

func (*Ring) Clear

func (r *Ring) Clear()

func (*Ring) Dequeue

func (r *Ring) Dequeue() interface{}

func (*Ring) Empty

func (r *Ring) Empty() []interface{}

func (*Ring) Enqueue

func (r *Ring) Enqueue(i interface{})

func (*Ring) Peek

func (r *Ring) Peek() interface{}

func (*Ring) SetCapacity

func (r *Ring) SetCapacity(size int)

func (*Ring) Values

func (r *Ring) Values() []interface{}

type Status

type Status struct {
	Text  string
	Color tb.Attribute
}

func NewStatus

func NewStatus() *Status

Jump to

Keyboard shortcuts

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