diff --git a/__pycache__/car_back.cpython-312.pyc b/__pycache__/car_back.cpython-312.pyc new file mode 100644 index 0000000..ae3924a Binary files /dev/null and b/__pycache__/car_back.cpython-312.pyc differ diff --git a/__pycache__/path.cpython-312.pyc b/__pycache__/path.cpython-312.pyc index 80b629d..0b20f3e 100644 Binary files a/__pycache__/path.cpython-312.pyc and b/__pycache__/path.cpython-312.pyc differ diff --git a/__pycache__/spawner.cpython-312.pyc b/__pycache__/spawner.cpython-312.pyc index 420f4ab..9c719c3 100644 Binary files a/__pycache__/spawner.cpython-312.pyc and b/__pycache__/spawner.cpython-312.pyc differ diff --git a/car_back.py b/car_back.py new file mode 100644 index 0000000..48a6f90 --- /dev/null +++ b/car_back.py @@ -0,0 +1,5 @@ +class CarBack: + character = 'O' + + def __init__(self, position): + self.position = position \ No newline at end of file diff --git a/path.py b/path.py index e934da3..54fe442 100644 --- a/path.py +++ b/path.py @@ -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 \ No newline at end of file diff --git a/spawner.py b/spawner.py index ba86c35..df1dbaf 100644 --- a/spawner.py +++ b/spawner.py @@ -1,5 +1,6 @@ from random import randint from path import Car +from car_back import CarBack class CarSpawner: display = False @@ -8,17 +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))) - #car2 = Car((30,randint(0, height - 1))) - #game.add_agent(car) - #game.add_agent(car2) - y = randint(0, height - 1) + y = randint(1, height-1) car3 = Car((0, y)) - car4 = Car((1,y)) + car3.next = CarBack((1,y)) game.add_agent(car3) - game.add_agent(car4) + game.add_agent(car3.next) def should_spawn_car(self, turn_number): return randint(0, 1000) < turn_number \ No newline at end of file