Compare commits

..

2 Commits

Author SHA1 Message Date
jwberent
4ff9dbd231 This is my fourth commit. I fixed the issue I was having with the cars breaking apart.
I am very happy that I was able to fix this problem.  I had to email you about this problem and you showed me how this could be completed by creating another class.  This makes so much sense now as you could spawn one part of the car right behind the other to give the illusion that it is one car.
I learned the new skill of using 2 different classes together when making the car 2 wide.
2025-12-06 22:54:28 -05:00
jwberent
abca9dbd4f 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.
2025-12-03 21:32:04 -05:00
8 changed files with 18 additions and 36 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

5
car_back.py Normal file
View File

@@ -0,0 +1,5 @@
class CarBack:
character = 'O'
def __init__(self, position):
self.position = position

2
new.py
View File

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

38
path.py
View File

@@ -1,53 +1,27 @@
class Car:
character = 'OO'
character = 'O'
def __init__(self, position):
self.position = position
self.next = None
#def play_turn(self, game):
# lives = 5
# width, height = game.board_size
# if game.turn_number % 2 == 0:
# x, y = self.position
# if y == height - 1:
# game.remove_agent(self)
# else:
# ship = game.get_agent_by_name('ship')
# new_position = (x, y + 1)
# if new_position == ship.position:
# lives = lives-1
# game.state["lives"] -=1
# if game.state["lives"] == 0:
# game.end()
#else:
# self.position = new_position
def play_turn(self, game):
lives = 3
width, height = game.board_size
if game.turn_number % 2 == 0:
if game.turn_number % 3 == 0:
x, y = self.position
if x == width - 1:
game.remove_agent(self)
game.remove_agent(self.next)
else:
person = game.get_agent_by_name('person')
new_position = (x+1, y)
# if game.turn_number % 2 == 1:
# x, y = self.position
#if x == width - 1:
# game.remove_agent(self)
# else:
# person = game.get_agent_by_name('person')
# new_position = (x-1, y)
if new_position == person.position:
lives = lives-1
game.state["lives"] -=1
if game.state["lives"] == 0:
game.end()
else:
self.next.position = self.position
self.position = new_position

View File

@@ -1,5 +1,6 @@
from random import randint
from path import Car
from car_back import CarBack
class CarSpawner:
display = False
@@ -8,9 +9,11 @@ class CarSpawner:
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)
y = randint(1, height-1)
car3 = Car((0, y))
car3.next = CarBack((1,y))
game.add_agent(car3)
game.add_agent(car3.next)
def should_spawn_car(self, turn_number):
return randint(0, 1000) < turn_number