generated from mwc/project_game
20 lines
534 B
Python
20 lines
534 B
Python
from random import randint
|
|
from apple import Apple
|
|
|
|
class AppleSpawner:
|
|
display = False
|
|
|
|
def play_turn(self, game):
|
|
width, height = game.board_size
|
|
game.state['score'] += 1
|
|
if self.should_spawn_apple(game.turn_number):
|
|
x = randint(0,width - 1)
|
|
y = randint(0, height - 1)
|
|
|
|
if game.is_empty((x,y)):
|
|
apple = Apple((x,y))
|
|
game.add_agent(apple)
|
|
|
|
def should_spawn_apple(self, turn_number):
|
|
return randint(0, 1000) < turn_number
|