Added ability to configure game at creation time
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
// "encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"sort"
|
||||
"sync"
|
||||
@@ -53,31 +51,17 @@ type MapLock struct {
|
||||
// get is a function that returns a game if found, and creates one if
|
||||
// not found and force is true. In order to get a hash (rather than use
|
||||
// the string you pass) send "" for id.
|
||||
func (ml *MapLock) get(id string, force bool) (*game, error) {
|
||||
func (ml *MapLock) get(id string) *game {
|
||||
ml.Lock()
|
||||
g, ok := games.m[id]
|
||||
g, _ := ml.m[id]
|
||||
ml.Unlock()
|
||||
return g
|
||||
}
|
||||
|
||||
if ok {
|
||||
return g, nil
|
||||
}
|
||||
|
||||
if !force {
|
||||
return nil, errors.New("game not found")
|
||||
}
|
||||
|
||||
if id == "" {
|
||||
id = idg.Hash()
|
||||
}
|
||||
|
||||
_g := NewGame(id, float32(*width), float32(*height))
|
||||
go _g.run()
|
||||
|
||||
func (ml *MapLock) add(g *game) {
|
||||
ml.Lock()
|
||||
ml.m[id] = _g
|
||||
ml.m[g.id] = g
|
||||
ml.Unlock()
|
||||
|
||||
return _g, nil
|
||||
}
|
||||
|
||||
type game struct {
|
||||
|
||||
Reference in New Issue
Block a user