game

package
v0.0.0-...-c76701d Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DashboardRequestHandler

func DashboardRequestHandler(w http.ResponseWriter, r *http.Request)

DashboardRequestHandler coordinates the response to a dashboard load

func TurnRequestHandler

func TurnRequestHandler(w http.ResponseWriter, r *http.Request)

TurnRequestHandler coordinates the execution of a turn

Types

type DashboardRequest

type DashboardRequest struct {
	UserID string `json:"user_id"`
}

DashboardRequest models a request to load a dashboard

type Dice

type Dice struct {
	NormFloat64 func() float64
}

Dice permits us to inject random

func NewDice

func NewDice() *Dice

func (*Dice) NormalRandomAdjustment

func (d *Dice) NormalRandomAdjustment(basis, stdev int64) int64

type Dicer

type Dicer interface {
	NormalRandomAdjustment(basis, stdev int64) int64
}

type Storefront

type Storefront struct {
	// status
	UserID    string `json:"user_id" db:"user_id"`
	Turn      int64  `json:"turn" db:"turn"`
	Backstock int64  `json:"backstock" db:"backstock"`
	Cash      int64  `json:"cash" db:"cash"`

	// weather
	CurrentTemperature    int64 `json:"cur_temp" db:"cur_temp"`
	ForecastTemperature   int64 `json:"for_temp" db:"for_temp"`
	CurrentPrecipitation  int64 `json:"cur_prec" db:"cur_prec"`
	ForecastPrecipitation int64 `json:"for_prec" db:"for_prec"`

	// turn summary
	Purchased int64 `json:"purchased" db:"purchased"`
	Prepared  int64 `json:"prepared" db:"prepared"`
	Sales     int64 `json:"sales" db:"sales"`
	Demand    int64 `json:"demand" db:"demand"`
	Waste     int64 `json:"waste" db:"waste"`

	// submitted values
	Preparing  int64 `json:"preparing" db:"preparing"`
	Purchasing int64 `json:"purchasing" db:"purchasing"`
	Price      int64 `json:"price" db:"price"`
}

Storefront is the core game object that records status from turn to turn

func LoadStorefront

func LoadStorefront(ctx context.Context, userID string) (*Storefront, error)

LoadStorefront loads up a storefront from the database

func NewStorefront

func NewStorefront(userID string) *Storefront

NewStorefront creates a storefront for the supplied userID and populates it with defaults

func (*Storefront) ProcessTurn

func (s *Storefront) ProcessTurn(purchasing, preparing, price int64) *Storefront

ProcessTurn is the meat of the game. It advances one turn.

func (*Storefront) Save

func (s *Storefront) Save(ctx context.Context) error

Save stores a storefront in the database

type TurnRequest

type TurnRequest struct {
	UserID     string `json:"user_id"`
	Purchasing int64  `json:"purchasing"`
	Preparing  int64  `json:"preparing"`
	Price      int64  `json:"price"`
}

TurnRequest contains everything we need to process a turn

Jump to

Keyboard shortcuts

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