jsonapp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Jsonapp contains an example of a simple game application that uses JSON as inputs and outputs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddMonsterPayload

type AddMonsterPayload = Monster

AddMonsterPayload is the payload for the AddMonster input.

type AttackMonsterPayload

type AttackMonsterPayload struct {
	MonsterName string `json:"monsterName"`
	Damage      int    `json:"damage"`
}

AttackMonsterPayload is the payload for the AttackMonster input.

type GameApplication

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

GameApplication is an application for a simple RPG game. The GM can add monsters and the players can attack them. Anyone can attack the the monsters. For each input, the application emits a report with the current game state.

func NewGameApplication

func NewGameApplication(gm common.Address) *GameApplication

func (*GameApplication) Advance

func (a *GameApplication) Advance(
	env rollmelette.Env,
	metadata rollmelette.Metadata,
	deposit rollmelette.Deposit,
	payload []byte,
) error

func (*GameApplication) Inspect

func (a *GameApplication) Inspect(env rollmelette.EnvInspector, payload []byte) error

type GameState

type GameState struct {
	Monsters map[string]Monster `json:"monsters"`
}

GameState is represents the state of the game.

type Input

type Input struct {
	Kind    InputKind       `json:"kind"`
	Payload json.RawMessage `json:"payload"`
}

Input has a kind and a payload with specific data.

type InputKind

type InputKind string

InputKind is an enum that represents the kind of input.

const (
	// AddMonster adds a monster to the game. It should be called by the GM.
	AddMonster InputKind = "AddMonster"

	// AttackMonster attacks the given monster.
	AttackMonster InputKind = "AttackMonster"
)

type Monster

type Monster struct {
	Name      string `json:"name"`
	HitPoints int    `json:"hitPoints"`
}

Monster represents a monster in the game.

Jump to

Keyboard shortcuts

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