simonsays

package
v0.0.0-...-ce3f598 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2016 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package simonsays is a generated protocol buffer package.

It is generated from these files:

simonsays.proto

It has these top-level messages:

Request
Response

Index

Constants

View Source
const Version string = "v0.1e"

Version is the current version of this implementation of Simon Says.

Variables

View Source
var Color_name = map[int32]string{
	0: "RED",
	1: "GREEN",
	2: "YELLOW",
	3: "BLUE",
}
View Source
var Color_value = map[string]int32{
	"RED":    0,
	"GREEN":  1,
	"YELLOW": 2,
	"BLUE":   3,
}
View Source
var ErrColorPressedOutOfTurn = errors.New("Color pressed outside of player turn")

ErrColorPressedOutOfTurn is returned when a colour is pressed outside of the Game player's turn.

View Source
var Response_State_name = map[int32]string{
	0: "BEGIN",
	1: "START_TURN",
	2: "STOP_TURN",
	3: "WIN",
	4: "LOSE",
}
View Source
var Response_State_value = map[string]int32{
	"BEGIN":      0,
	"START_TURN": 1,
	"STOP_TURN":  2,
	"WIN":        3,
	"LOSE":       4,
}

Functions

func RegisterSimonSaysServer

func RegisterSimonSaysServer(s *grpc.Server, srv SimonSaysServer)

Types

type Color

type Color int32
const (
	Color_RED    Color = 0
	Color_GREEN  Color = 1
	Color_YELLOW Color = 2
	Color_BLUE   Color = 3
)

func (Color) EnumDescriptor

func (Color) EnumDescriptor() ([]byte, []int)

func (Color) String

func (x Color) String() string

type Game

type Game struct {
	ID string
	// contains filtered or unexported fields
}

Game represents a Game that an individual player is playing. It keeps track of internal Game state for that player. Only use exported methods are guaranteed to be concurrently safe.

func NewGame

func NewGame(id string) *Game

NewGame returns a new Game for a player

func (*Game) EncodePresses

func (g *Game) EncodePresses() ([]byte, error)

EncodePresses encodes the current set of Color presses into an []bytes for transmission.

func (*Game) IsMyTurn

func (g *Game) IsMyTurn() bool

IsMyTurn Is this this player's turn?

func (*Game) Match

func (g *Game) Match() bool

Match checks to see if the currently entered presses, line up with what we have as valid presses.

func (*Game) PressColor

func (g *Game) PressColor(c Color) error

PressColor should be called when this player presses a colour. This will append the colour value to the list of currentPresses. Returns a ErrColorPressedOutOfTurn if it not this player's turn Will set IsMyTurn() to false when the number of currentPresses is one more than the current validPresses (what colours the last player pressed) value, or colours don't match up to the previous turn's colour sequence.

func (*Game) StartTurn

func (g *Game) StartTurn(p []Color)

StartTurn starts the player's turn. It is passed the sequence of Colors the player needs to match during this turn to continue to the next round.

type Request

type Request struct {
	// Types that are valid to be assigned to Event:
	//	*Request_Join
	//	*Request_Press
	Event isRequest_Event `protobuf_oneof:"event"`
}

func (*Request) Descriptor

func (*Request) Descriptor() ([]byte, []int)

func (*Request) GetEvent

func (m *Request) GetEvent() isRequest_Event

func (*Request) GetJoin

func (m *Request) GetJoin() *Request_Player

func (*Request) GetPress

func (m *Request) GetPress() Color

func (*Request) ProtoMessage

func (*Request) ProtoMessage()

func (*Request) Reset

func (m *Request) Reset()

func (*Request) String

func (m *Request) String() string

func (*Request) XXX_OneofFuncs

func (*Request) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})

XXX_OneofFuncs is for the internal use of the proto package.

type Request_Join

type Request_Join struct {
	Join *Request_Player `protobuf:"bytes,1,opt,name=join,oneof"`
}

type Request_Player

type Request_Player struct {
	Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
}

A Player of the Simon says game.

func (*Request_Player) Descriptor

func (*Request_Player) Descriptor() ([]byte, []int)

func (*Request_Player) ProtoMessage

func (*Request_Player) ProtoMessage()

func (*Request_Player) Reset

func (m *Request_Player) Reset()

func (*Request_Player) String

func (m *Request_Player) String() string

type Request_Press

type Request_Press struct {
	Press Color `protobuf:"varint,2,opt,name=press,enum=simonsays.Color,oneof"`
}

type Response

type Response struct {
	// Types that are valid to be assigned to Event:
	//	*Response_Turn
	//	*Response_Lightup
	Event isResponse_Event `protobuf_oneof:"event"`
}

func (*Response) Descriptor

func (*Response) Descriptor() ([]byte, []int)

func (*Response) GetEvent

func (m *Response) GetEvent() isResponse_Event

func (*Response) GetLightup

func (m *Response) GetLightup() Color

func (*Response) GetTurn

func (m *Response) GetTurn() Response_State

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) Reset

func (m *Response) Reset()

func (*Response) String

func (m *Response) String() string

func (*Response) XXX_OneofFuncs

func (*Response) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})

XXX_OneofFuncs is for the internal use of the proto package.

type Response_Lightup

type Response_Lightup struct {
	Lightup Color `protobuf:"varint,2,opt,name=lightup,enum=simonsays.Color,oneof"`
}

type Response_State

type Response_State int32
const (
	Response_BEGIN      Response_State = 0
	Response_START_TURN Response_State = 1
	Response_STOP_TURN  Response_State = 2
	Response_WIN        Response_State = 3
	Response_LOSE       Response_State = 4
)

func (Response_State) EnumDescriptor

func (Response_State) EnumDescriptor() ([]byte, []int)

func (Response_State) String

func (x Response_State) String() string

type Response_Turn

type Response_Turn struct {
	Turn Response_State `protobuf:"varint,1,opt,name=turn,enum=simonsays.Response_State,oneof"`
}

type SimonSays

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

SimonSays is the data structure that implements the SimonSaysServer interface for our gRPC server.

func NewSimonSays

func NewSimonSays(address string) (*SimonSays, error)

NewSimonSays Create a new Simon Says.

func (SimonSays) Close

func (s SimonSays) Close() error

Close closes all resources.

func (*SimonSays) Game

func (s *SimonSays) Game(stream SimonSays_GameServer) error

Game function is an implementation of the gRPC Game Service. When connected, this is the main functionality of running a Game for the connected player.

type SimonSaysClient

type SimonSaysClient interface {
	//
	// Game process is the following:
	//
	// A Join Request should be sent to the game. This tells it
	// to join a game (or start a new one if one isn't already waiting on a game).
	//
	// The Response stream will send through a BEGIN Response.State to let you know that
	// the Game has been started.
	//
	// When the player recieves a START_TURN response, the server can take your input for the turn.
	//
	// When the player recieves a STOP_TURN response, the serer is no longer taking input for the turn.
	//
	// A WIN state says you won the game. A LOSE state means that you got an input wrong, and have lost.
	//
	// To send input, send a Request with an event type of Color.
	//
	// When you recieve a Response of type Color, then light up that colour.
	Game(ctx context.Context, opts ...grpc.CallOption) (SimonSays_GameClient, error)
}

func NewSimonSaysClient

func NewSimonSaysClient(cc *grpc.ClientConn) SimonSaysClient

type SimonSaysServer

type SimonSaysServer interface {
	//
	// Game process is the following:
	//
	// A Join Request should be sent to the game. This tells it
	// to join a game (or start a new one if one isn't already waiting on a game).
	//
	// The Response stream will send through a BEGIN Response.State to let you know that
	// the Game has been started.
	//
	// When the player recieves a START_TURN response, the server can take your input for the turn.
	//
	// When the player recieves a STOP_TURN response, the serer is no longer taking input for the turn.
	//
	// A WIN state says you won the game. A LOSE state means that you got an input wrong, and have lost.
	//
	// To send input, send a Request with an event type of Color.
	//
	// When you recieve a Response of type Color, then light up that colour.
	Game(SimonSays_GameServer) error
}

type SimonSays_GameClient

type SimonSays_GameClient interface {
	Send(*Request) error
	Recv() (*Response, error)
	grpc.ClientStream
}

type SimonSays_GameServer

type SimonSays_GameServer interface {
	Send(*Response) error
	Recv() (*Request, error)
	grpc.ServerStream
}

Directories

Path Synopsis
Package logger is logging that is specific to this application Need to track the game, and the player, so we can see everything that is going on.
Package logger is logging that is specific to this application Need to track the game, and the player, so we can see everything that is going on.

Jump to

Keyboard shortcuts

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