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.
This commit is contained in:
jwberent
2025-12-06 22:54:28 -05:00
parent abca9dbd4f
commit 4ff9dbd231
6 changed files with 14 additions and 40 deletions

36
path.py
View File

@@ -3,51 +3,25 @@ class Car:
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: #% 3 == 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