refactoring
This commit is contained in:
parent
cbc7369b8d
commit
09b61c7dc9
@ -11,21 +11,25 @@ import (
|
||||
func NewEngine(id string) *Engine {
|
||||
engine := Engine{
|
||||
id: id,
|
||||
versionRef: 0,
|
||||
obs: observer.NewProperty(syncdata.SyncData{}),
|
||||
}
|
||||
return &engine
|
||||
}
|
||||
|
||||
func (engine *Engine) Run() {
|
||||
func (eng *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)
|
||||
|
||||
eng.versionRef++
|
||||
fmt.Printf("game %s: %d\n", eng.id, eng.versionRef)
|
||||
data := syncdata.SyncData{
|
||||
VersionRef: eng.versionRef,
|
||||
}
|
||||
eng.obs.Update(data)
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,6 @@ type HandleFunc func(http.ResponseWriter, *http.Request)
|
||||
|
||||
type Engine struct {
|
||||
id string
|
||||
versionRef int
|
||||
obs observer.Property
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user