Commit ca257807 authored by Sam Rushing's avatar Sam Rushing

worm.kill(): remove from arena.worms at this point, rather than relying on the...

worm.kill(): remove from arena.worms at this point, rather than relying on the try/finally in the thread.
parent 001e1072
...@@ -63,10 +63,14 @@ class arena: ...@@ -63,10 +63,14 @@ class arena:
x, y = self.random_pos() x, y = self.random_pos()
self.worms.append (worm (self, x, y)) self.worms.append (worm (self, x, y))
def cull (self, hoffa=False): def cull (self, hoffa=False):
removed = []
for worm in self.worms: for worm in self.worms:
if worm.stunned: if worm.stunned:
W ('culling worm %r\n' % (worm.chr,)) W ('culling worm %r\n' % (worm.chr,))
worm.kill (hoffa) worm.kill (hoffa)
removed.append (worm)
for r in removed:
self.worms.remove (r)
class worm: class worm:
...@@ -91,7 +95,6 @@ class worm: ...@@ -91,7 +95,6 @@ class worm:
coro.spawn (self.go) coro.spawn (self.go)
def go (self): def go (self):
try:
while not self.exit: while not self.exit:
coro.sleep_relative (self.speed / 10000.0) coro.sleep_relative (self.speed / 10000.0)
if random.randrange (0,20) == 10: if random.randrange (0,20) == 10:
...@@ -104,8 +107,6 @@ class worm: ...@@ -104,8 +107,6 @@ class worm:
return return
nx, ny = self.update() nx, ny = self.update()
self.move ((nx, ny)) self.move ((nx, ny))
finally:
self.arena.worms.remove (self)
def update (self): def update (self):
x, y = self.head x, y = self.head
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment