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, obs: observer.NewProperty(syncdata.SyncData{}), } return &engine } func (engine *Engine) Run() { r := rand.New(rand.NewSource(time.Now().UnixNano())) for { value := engine.obs.Value().(syncdata.SyncData) fmt.Printf("game %s: %d\n", engine.id, value.VersionRef) wait := int(1 + r.Float32()*5) for i := 0; i < wait; i++ { time.Sleep(1 * time.Second) } value.VersionRef++ engine.obs.Update(value) } }