From 0247bdb16ace2efc27d57051ab5cc61af8723f6f Mon Sep 17 00:00:00 2001 From: jwberent Date: Fri, 28 Nov 2025 19:10:04 -0500 Subject: [PATCH] I made it so the cars go from left to right instead of top to bottom. I also added that players get 3 lives and changed the color of the background to black on white. I also made the cars 2 wide. 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. --- __pycache__/path.cpython-312.pyc | Bin 1349 -> 1339 bytes __pycache__/person.cpython-312.pyc | Bin 1429 -> 1422 bytes __pycache__/spawner.cpython-312.pyc | Bin 1203 -> 1163 bytes new.py | 11 ++++++----- path.py | 26 +++++++++++++++++++------- person.py | 4 ++-- spawner.py | 13 +++++++------ 7 files changed, 34 insertions(+), 20 deletions(-) diff --git a/__pycache__/path.cpython-312.pyc b/__pycache__/path.cpython-312.pyc index 5ac257319a0b642a40e3307beae1248dae14fbb5..4f9af41dfce8f15a3861127e7c2e64b66838f362 100644 GIT binary patch delta 195 zcmX@gwVR9YG%qg~0}vEiYGrOe4I7Nvw=7DJ{yA1WFelntX&g zP)kzwx}^R^N&O8RmnAJHu-#BlT%fp+c|qWeiU~X)q!>gL7MLx!Uub_x*l4mXiyNcy kzca0s6oP5gE67Q#j4vrI%98}DC_XTG z2Xml?xb$^#-HYP7E7C5Dn@(W4p`f_Ha6#ch(-~D0cy0*GFECkdyU_NMu)$pI8`K6+deUOn$@S#H+z*_=y2X6oEVd0F(gl**?=_;0OZ^m z-3vpe3eK313Lqc@nm)85P1QRjeJ0&7~~=a zg(6Xq056cJk_K5ZpIMXzXea;Vz09(V;*)PPn+S=)RIFqu5(lwGCo8hZbFr~1d=_A2 z)hiO8?8Tz#APbU#NCR2FIBatBQ%ZAE?TQqDT#!GDK{kD0W@Kc%%OG`^LF79N52M~E J1|R{}1_0O)TH62s delta 435 zcmeC?+|0>)nwOW00SH8d6f-YRWP4x8Nkl+v73yCOv( h7Zh5>qCnyUGb1D8T?VPU43ghjxEb|6F#rj$HUQ3!b}s+` diff --git a/new.py b/new.py index 5846492..49ca655 100644 --- a/new.py +++ b/new.py @@ -1,9 +1,10 @@ from retro.game import Game -from person import Spaceship -from spawner import AsteroidSpawner +from person import Person +from spawner import CarSpawner +from path import Car board_size = (25, 25) -ship = Spaceship(board_size) -spawner = AsteroidSpawner() -game = Game([ship, spawner], {"score": 0,"lives":5}, board_size=board_size) +person = Person(board_size) +spawner = CarSpawner() +game = Game([person,spawner], {"score": 0,"lives":3}, board_size=board_size,color="black_on_white") game.play() \ No newline at end of file diff --git a/path.py b/path.py index 547fef0..de0da70 100644 --- a/path.py +++ b/path.py @@ -1,5 +1,5 @@ -class Asteroid: - character = 'O' +class Car: + character = 'OO' def __init__(self, position): self.position = position @@ -23,16 +23,28 @@ class Asteroid: # self.position = new_position def play_turn(self, game): - lives = 5 + lives = 3 width, height = game.board_size if game.turn_number % 2 == 0: x, y = self.position - if y == height - 1: + if x == width - 1: game.remove_agent(self) else: - ship = game.get_agent_by_name('ship') - new_position = (x, y + 1) - if new_position == ship.position: + 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: diff --git a/person.py b/person.py index a473abf..5ba17e5 100644 --- a/person.py +++ b/person.py @@ -1,5 +1,5 @@ -class Spaceship: - name = "ship" +class Person: + name = "person" character = '^' def __init__(self, board_size): diff --git a/spawner.py b/spawner.py index 884e579..0160ce7 100644 --- a/spawner.py +++ b/spawner.py @@ -1,15 +1,16 @@ from random import randint -from path import Asteroid +from path import Car -class AsteroidSpawner: +class CarSpawner: display = False def play_turn(self, game): width, height = game.board_size game.state['score'] += 1 - if self.should_spawn_asteroid(game.turn_number): - asteroid = Asteroid((randint(0, width - 1), 0)) - game.add_agent(asteroid) + 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_asteroid(self, turn_number): + def should_spawn_car(self, turn_number): return randint(0, 1000) < turn_number \ No newline at end of file