game

package
v0.0.0-...-0cb0207 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Provide(func(motd string, dbaccess *dba.DBAccess, repository dba.Repository) *Game {
	game := GetInstance()
	game.MOTD = motd
	game.Repository = repository
	return game
})

Module ... fx module export

Functions

This section is empty.

Types

type Avatar

type Avatar struct {
	CurrentUser *users.User `json:"id,omitempty" bson:"-"`
	// contains filtered or unexported fields
}

Avatar ... default active entity that moves in the world Avatars can be either controlled by Players/Users or be attached/belong to bots Once a user is logged in he automatically gets attached his last used aavatar

func LoadAvatar

func LoadAvatar(avatars *dba.AvatarDAO, id string) (*Avatar, error)

LoadAvatar ... loads and returns the avatar

func NewAvatar

func NewAvatar() *Avatar

NewAvatar ... creates and returns a new room instance

func (*Avatar) Description

func (avatar *Avatar) Description() string

Description ... returns the description

func (*Avatar) Name

func (avatar *Avatar) Name() string

Name ... returns the name

func (*Avatar) SetCurrentRoomID

func (avatar *Avatar) SetCurrentRoomID(currentRoomID string) err

SetCurrentRoomID ... returns the name

type AvatarJoinedRoom

type AvatarJoinedRoom struct {
	Avatar *Avatar
	Room   *Room
}

AvatarJoinedRoom ... asdd

type AvatarLeftRoom

type AvatarLeftRoom struct {
	Avatar *Avatar
	Room   *Room
}

AvatarLeftRoom ... asdd

type Command

type Command interface {
	Execute(game *Game, message *Message) bool
}

Command ... commands

type CommandProcessor

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

CommandProcessor ... global user struct to control logins

func NewCommandProcessor

func NewCommandProcessor() *CommandProcessor

NewCommandProcessor .. creates a new command processor

func (*CommandProcessor) Process

func (commandProcessor *CommandProcessor) Process(game *Game, message *Message) bool

Process ...asd

func (*CommandProcessor) RegisterCommand

func (commandProcessor *CommandProcessor) RegisterCommand(key string, command Command)

RegisterCommand ... register

type Game

type Game struct {
	Repository dba.Repository

	MOTD string

	SystemUser *users.User

	// messages
	OnMessageReceived chan *Message
	OnUserJoined      chan *UserJoined
	OnUserQuit        chan *UserQuit

	OnAvatarJoinedRoom chan *AvatarJoinedRoom
	OnAvatarLeftRoom   chan *AvatarLeftRoom

	Receivers []Receiver

	CommandProcessor *CommandProcessor

	Avatars map[string]*Avatar
	// contains filtered or unexported fields
}

Game ... default entity to structure rooms This is the main class that controls the real-time game flow for tcp and websocket clients. this is the live world, all changes to it will be stored to the database. The game instance can be recreated/loaded from a World instance inside the database

func Instance

func Instance() *Game

Instance ... returns the game instance

func (*Game) CreateRoom

func (game *Game) CreateRoom(title string) *Room

CreateRoom ... processes every entity

func (*Game) ID

func (game *Game) ID() string

ID ... returns the id of the room

func (*Game) Subscribe

func (game *Game) Subscribe(receiver Receiver)

Subscribe ... sub

type Message

type Message struct {
	FromUser *users.User
	ToUser   *users.User
	Data     string
}

Message ... main message container to pass data from users to server and back

func NewMessage

func NewMessage(fromUser *users.User, data string) *Message

NewMessage ... creates a new message

type Receiver

type Receiver interface {
	OnMessage(message interface{})
}

Receiver ... rec

type Room

type Room struct {
	ID           bson.ObjectId `json:"id,omitempty" bson:"_id,omitempty"`
	Title        string        `json:"title"`
	Description  string        `json:"description"`
	CreationDate time.Time     `json:"creationDate,omitempty"`

	Avatars []*Avatar `json:"avatars"`
}

Room ... default entity to structure rooms

func NewRoom

func NewRoom(id string, title string, description string) *Room

NewRoom ... creates and returns a new room instance

func (*Room) Enter

func (room *Room) Enter(avatar *Avatar)

Enter ... processes every entity

func (*Room) Leave

func (room *Room) Leave(avatar *Avatar)

Leave ... processes every entity

type ScreamCommand

type ScreamCommand struct {
}

ScreamCommand ... foo

func (*ScreamCommand) Execute

func (screamCommand *ScreamCommand) Execute(game *Game, message *Message) bool

Execute ... executes scream command

type UserJoined

type UserJoined struct {
	User *users.User
}

UserJoined ... player joined event

func NewUserJoined

func NewUserJoined(user *users.User) *UserJoined

NewUserJoined ... creates a new User Joined event

type UserQuit

type UserQuit struct {
	User *users.User
}

UserQuit ... player joined event

func NewUserQuit

func NewUserQuit(user *users.User) *UserQuit

NewUserQuit ... creates a new User Joined event

type World

type World struct {
	ID          bson.ObjectId `json:"id,omitempty" bson:"_id,omitempty"`
	DateCreated time.Time     `json:"dateCreated,omitempty"`

	Rooms          []*Room   `json:"rooms,omitempty"`
	Avatars        []*Avatar `json:"avatars,omitempty"`
	StartingRoomID string    `json:"startingRoomId,omitempty"`
}

World ... default entity to structure rooms Everything regarding content and live/dynamic data such as items, avatars, room shall be managed from the World class - all generic game/message/command related things will reside in the game class

func NewWorld

func NewWorld(id string) *World

NewWorld ... creates and returns a new room instance

func (*World) AddRoom

func (world *World) AddRoom(room Room)

AddRoom ... adds a room to the world

func (*World) GetRoom

func (world *World) GetRoom(id string) (Room, error)

GetRoom ...

func (*World) GetStartingRoom

func (world *World) GetStartingRoom() *Room

GetStartingRoom ... returns the StartingRoom for this world

Jump to

Keyboard shortcuts

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