package engine import ( "fmt" "github.com/imkira/go-observer" "math/rand" "sirlab.de/go/knyt/syncdata" "time" ) func NewEngine(id string) *Engine { engine := Engine{ id: id, versionRef: 0, obs: observer.NewProperty(syncdata.SyncData{}), } return &engine } func (eng *Engine) Run() { r := rand.New(rand.NewSource(time.Now().UnixNano())) for { wait := int(1 + r.Float32()*5) for i := 0; i < wait; i++ { time.Sleep(1 * time.Second) } eng.versionRef++ fmt.Printf("game %s: %d\n", eng.id, eng.versionRef) data := syncdata.SyncData{ VersionRef: eng.versionRef, } eng.obs.Update(data) } }