|
|
@ -95,6 +95,9 @@ func (g *Game) Win(winner *Connection, method string) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *Game) Reset() {
|
|
|
|
func (g *Game) Reset() {
|
|
|
|
|
|
|
|
for elem, _ := range g.elems {
|
|
|
|
|
|
|
|
elem.Reset()
|
|
|
|
|
|
|
|
}
|
|
|
|
connections := g.connections
|
|
|
|
connections := g.connections
|
|
|
|
fresh := NewGame()
|
|
|
|
fresh := NewGame()
|
|
|
|
*g = *fresh
|
|
|
|
*g = *fresh
|
|
|
@ -117,18 +120,25 @@ func (g *Game) Register(elem GameElement) {
|
|
|
|
|
|
|
|
|
|
|
|
func (g *Game) tick() {
|
|
|
|
func (g *Game) tick() {
|
|
|
|
g.frame += 1
|
|
|
|
g.frame += 1
|
|
|
|
|
|
|
|
for elem := range g.elems {
|
|
|
|
|
|
|
|
elem.Tick(g.frame)
|
|
|
|
|
|
|
|
}
|
|
|
|
for elem := range g.elems {
|
|
|
|
for elem := range g.elems {
|
|
|
|
if elem.Dead() {
|
|
|
|
if elem.Dead() {
|
|
|
|
log_info("delete game object: %v", elem)
|
|
|
|
log_info("delete game object: %v", elem)
|
|
|
|
delete(g.elems, elem)
|
|
|
|
delete(g.elems, elem)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for elem := range g.elems {
|
|
|
|
|
|
|
|
elem.Tick(g.frame)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type GameElement interface {
|
|
|
|
type GameElement interface {
|
|
|
|
Tick(frame int64)
|
|
|
|
Tick(frame int64)
|
|
|
|
Dead() bool
|
|
|
|
Dead() bool
|
|
|
|
|
|
|
|
Reset()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type NopReset struct {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (n NopReset) Reset() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|