Beispiel #1
0
func initGame(e joak.Entity) joak.Entity {
	g := e.(*game)
	g.State = _WAITING_FOR_OPPONENT
	dur, _ := time.ParseDuration(_DELETE_AFTER)
	g.DeleteAfter = now().Add(dur)
	g.PlayerIds = []string{sid.ObjectId(), ``}
	g.CurrentChoices = []string{``, ``}
	return g
}
Beispiel #2
0
func (g *game) RegisterNewUser() (string, error) {
	if g.PlayerIds[1] == `` {
		g.PlayerIds[1] = sid.ObjectId()
		dur, _ := time.ParseDuration(strconv.Itoa(_START_TIME_BUF) + _TIME_UNIT)
		g.TurnStart = now().Add(dur)
		g.State = _GAME_IN_PROGRESS
		return g.PlayerIds[1], nil
	}
	return ``, errors.New(`all player slots taken`)
}