This is my third commit. I made the cars 2 in length although I am having a problem where they break apart sometimes.

I am getting very close to finishing the project.  I was having a problem where I made the symbol for the cars 'OO' and only one of the 'O' was leaving the screen when it made it to the far right of the screen.
I emailed you and you said to only make the symbol 'O' and spawn 2 right next to each other.  I figured out how to do this by myself but am now trying to figure out why they are breaking apart.
This commit is contained in:
jwberent
2025-12-03 21:32:04 -05:00
parent d047592c5c
commit abca9dbd4f
6 changed files with 13 additions and 5 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

2
new.py
View File

@@ -3,7 +3,7 @@ from person import Person
from spawner import CarSpawner from spawner import CarSpawner
from path import Car from path import Car
board_size = (25, 25) board_size = (30, 35)
person = Person(board_size) person = Person(board_size)
spawner = CarSpawner() spawner = CarSpawner()
game = Game([person,spawner], {"score": 0,"lives":3}, board_size=board_size,color="black_on_white") game = Game([person,spawner], {"score": 0,"lives":3}, board_size=board_size,color="black_on_white")

View File

@@ -1,5 +1,5 @@
class Car: class Car:
character = 'OO' character = 'O'
def __init__(self, position): def __init__(self, position):
self.position = position self.position = position
@@ -25,7 +25,7 @@ class Car:
def play_turn(self, game): def play_turn(self, game):
lives = 3 lives = 3
width, height = game.board_size width, height = game.board_size
if game.turn_number % 2 == 0: if game.turn_number: #% 3 == 0:
x, y = self.position x, y = self.position
if x == width - 1: if x == width - 1:
game.remove_agent(self) game.remove_agent(self)

View File

@@ -9,8 +9,16 @@ class CarSpawner:
game.state['score'] += 1 game.state['score'] += 1
if self.should_spawn_car(game.turn_number): if self.should_spawn_car(game.turn_number):
#car = Car((randint(0, width - 1), 0)) #car = Car((randint(0, width - 1), 0))
car = Car((0, randint(0, height - 1)))
game.add_agent(car) #car = Car((0, randint(0, height - 1)))
#car2 = Car((30,randint(0, height - 1)))
#game.add_agent(car)
#game.add_agent(car2)
y = randint(0, height - 1)
car3 = Car((0, y))
car4 = Car((1,y))
game.add_agent(car3)
game.add_agent(car4)
def should_spawn_car(self, turn_number): def should_spawn_car(self, turn_number):
return randint(0, 1000) < turn_number return randint(0, 1000) < turn_number