generated from mwc/lab_retro
This is completely different than anything we did in unit 1. When creating the nav game all the code feels connected as the code was broken up into asteroid, asteroid spawner, game, and spaceship. I think this is so much easier to follow as it was easy to figure out what each thing did. Also, this uses classes which we did not use in unit 1.
This commit is contained in:
@@ -2,3 +2,18 @@
|
||||
# -------------------
|
||||
# By MWC Contributors
|
||||
# This module defines an AsteroidSpawner agent class.
|
||||
from random import randint
|
||||
from asteroid import Asteroid
|
||||
|
||||
class AsteroidSpawner:
|
||||
display = False
|
||||
|
||||
def play_turn(self, game):
|
||||
width, height = game.board_size
|
||||
game.state['score'] += 1
|
||||
if self.should_spawn_asteroid(game.turn_number):
|
||||
asteroid = Asteroid((randint(0, 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