generated from mwc/lab_retro
When I run the game, it works for a bit but then when the first asteroid
gets to the bottom I get this:
Traceback (most recent call last):
File "/root/making_with_code/mwc1/unit3/lab_retro/nav_game.py", line 14, in <module>
game.play()
File "/root/making_with_code/mwc1/unit3/lab_retro/retro/game.py", line 80, in play
agent.play_turn(self)
File "/root/making_with_code/mwc1/unit3/lab_retro/asteroid.py", line 16, in play_turn
game.remove_agent_by_name(self.name)
AttributeError: 'Asteroid' object has no attribute 'name'
This commit is contained in:
@@ -2,3 +2,22 @@
|
||||
# -------------------
|
||||
# By MWC Contributors
|
||||
# This module defines an AsteroidSpawner agent class.
|
||||
|
||||
from random import randint
|
||||
from asteroid import Asteroid
|
||||
|
||||
class AsteroidSpawner:
|
||||
display = False
|
||||
|
||||
def __init__(self, board_size):
|
||||
width, height = board_size
|
||||
self.board_width = width
|
||||
|
||||
def play_turn(self, game):
|
||||
game.state['score'] += 1
|
||||
if self.should_spawn_asteroid(game.turn_number):
|
||||
asteroid = Asteroid((randint(0, self.board_width - 1), 0))
|
||||
game.add_agent(asteroid)
|
||||
|
||||
def should_spawn_asteroid(self, turn_number):
|
||||
return randint(0, 1000) < turn_number
|
||||
Reference in New Issue
Block a user