game reset cleanup

slack
Jordan Orelli 10 years ago
parent 6ee3051976
commit e7472a6d10

@ -6,6 +6,7 @@ import (
)
type Bomb struct {
NopReset
player *Connection
origin *System
target *System

@ -6,6 +6,7 @@ import (
)
type broadcast struct {
NopReset
start time.Time
origin *System
dist float64

@ -49,6 +49,7 @@ func (conn *Connection) Reset() {
Conn: conn.Conn,
Reader: bufio.NewReader(conn.Conn),
bombs: 1,
player: conn.player,
}
currentGame.Join(conn)
}

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

@ -6,6 +6,7 @@ import (
)
type scan struct {
NopReset
start time.Time
origin *System
dist float64

@ -34,6 +34,11 @@ func (s *System) Dead() bool {
return false
}
func (s *System) Reset() {
s.players = make(map[*Connection]bool, 32)
s.colonizedBy = nil
}
func (s *System) Arrive(conn *Connection) {
conn.SetSystem(s)
log_info("player %s has arrived at system %s", conn.PlayerName(), s.name)

Loading…
Cancel
Save