Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v0 source realm

Package pingpong is a two-player game where the only move is to pass the turn. It exists to demonstrate gnotif: every...

Overview

Package pingpong is a two-player game where the only move is to pass the turn. It exists to demonstrate gnotif: every turn emits TurnPlayed, and the realm declares a verified gnotif trigger that tells the next player.

Functions 6

func Accept

crossing Action
1func Accept(cur realm, game string)
source

Accept starts a pending game. Only the invited player may call it.

func DeclareTriggers

crossing Action
1func DeclareTriggers(cur realm)
source

DeclareTriggers declares the "your turn" trigger in the gnotif registry. The registry sees this realm as the caller, so the trigger is verified.

func Leave

crossing Action
1func Leave(cur realm, game string)
source

Leave cancels a pending game or ends a started one, and deletes it.

func NewGame

crossing Action
1func NewGame(cur realm, opponent address) string
source

NewGame invites opponent to a game and returns its id. The caller plays first once opponent accepts.

func Play

crossing Action
1func Play(cur realm, game string)
source

Play takes the caller's turn in game and passes it to the other player.

func Render

1func Render(path string) string
source

Render serves "" (the first page), "page/N" and "game/<id>".

Types 1

type Game

struct
1type Game struct {
2	ID                  string
3	First, Second, Next address
4	Turn                int
5	Started             bool
6}
source

Game is a match between First and Second. First plays turn 1. It is pending until Second accepts, and only then are players named in events that notify them.

Dependencies

Source Files 3