generated from mwc/project_game
Checkpoint 2: Attaching the "asteroid" to the player if the player touches the "asteroid" This part was challenging as there were new commands I learned while trying to incorporate the retro lab componemets. I included the "asteroid sprawner" to get more than on "asteroid" on the screen. The next part is to end the game.
This commit is contained in:
19
apple_sprawner.py
Normal file
19
apple_sprawner.py
Normal file
@@ -0,0 +1,19 @@
|
||||
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
|
||||
Reference in New Issue
Block a user