Added ability to configure game at creation time

This commit is contained in:
sm
2013-11-07 22:11:54 -08:00
parent 164c37e7d6
commit caea45741f
3 changed files with 61 additions and 33 deletions
+6 -22
View File
@@ -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 {