lab_retro/asteroid_spawner.py

25 lines
736 B
Python

# asteroid_spawner.py
# -------------------
# 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
self.ast_num = 1
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), self.ast_num)
game.add_agent(asteroid)
self.ast_num = self.ast_num + 1
def should_spawn_asteroid(self, turn_number):
return randint(0, 1000) < turn_number