generated from mwc/project_game
At first it was tough for me to figure out how to get the cars to move from left to right. I was able to figure this out by emailing you and also thinking about where it was telling the cars to spawn in the retro lab and changing that part of the code. I had to change a few lines of code where it used the height parameter and changed it to width. I was able to overcome this by thinking about what each individual line of code did and what I needed to change to fix it. I have gotten a lot better at debugging code and understanding what each line of code is doing throughout the semester. I would tell a future student to really think about what each line of code is doing and try to follow along and you should find many of your mistakes.
16 lines
484 B
Python
16 lines
484 B
Python
from random import randint
|
|
from path import Car
|
|
|
|
class CarSpawner:
|
|
display = False
|
|
|
|
def play_turn(self, game):
|
|
width, height = game.board_size
|
|
game.state['score'] += 1
|
|
if self.should_spawn_car(game.turn_number):
|
|
#car = Car((randint(0, width - 1), 0))
|
|
car = Car((0, randint(0, height - 1)))
|
|
game.add_agent(car)
|
|
|
|
def should_spawn_car(self, turn_number):
|
|
return randint(0, 1000) < turn_number |