From 4ff9dbd2313f5d10e530fa895f46a6dcd0084301 Mon Sep 17 00:00:00 2001 From: jwberent Date: Sat, 6 Dec 2025 22:54:28 -0500 Subject: [PATCH] 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. --- __pycache__/car_back.cpython-312.pyc | Bin 0 -> 504 bytes __pycache__/path.cpython-312.pyc | Bin 1311 -> 1505 bytes __pycache__/spawner.cpython-312.pyc | Bin 1269 -> 1348 bytes car_back.py | 5 ++++ path.py | 36 ++++----------------------- spawner.py | 13 +++------- 6 files changed, 14 insertions(+), 40 deletions(-) create mode 100644 __pycache__/car_back.cpython-312.pyc create mode 100644 car_back.py diff --git a/__pycache__/car_back.cpython-312.pyc b/__pycache__/car_back.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ae3924a4b2bec96e640974cf2d77c1f27f8eb5fb GIT binary patch literal 504 zcmX|7F;Buk6n@thEd(Ob#4y6xg~sS;9Aq#qxOcf6*9ryN;Z4kk>#*A_3i@4naX``%sOSEEq_Txx&gkMaDb;<${GWGy6H(BJ`F*nrDEwL)=V zsad)_`srk4kzFF$f(H(B!O>ji=&rT_$5`r?k)HO1x)*YivL{*g%5%hZ+}U}aUa=MM zTp(D2#rhUY%~=%ti64cQmKw1)eO4!^#*}Th4?TMn1)e=#3_Rt9i5-ZE9}fA#Pexou zu4e}ed1cQ-Ke@JNDjIt-;X{E5DHI>zo4T`QYI5$QgY(yB`O@z33k@Z%BCKK8YQGup zjSLIuTNO%$*opJB#(5CA^C|H<=Pz?HEtRSq2_glnkeK=$g$TMW51fgIzNDr2mSz}4{(zJ literal 0 HcmV?d00001 diff --git a/__pycache__/path.cpython-312.pyc b/__pycache__/path.cpython-312.pyc index 80b629dfa4c4fc2fa3a88b9798ba9e16d2cb1f5f..0b20f3e0797955dc8bf197446ad8fd02d7b3e83a 100644 GIT binary patch delta 757 zcmbQw^^lwIG%qg~0}%Z9Vv$v zSjEP`kiwL$!N5>-Zt_e27#SvCU=nB2YW;vuW0w_bLo>;#wTo)bNo)%Sxu1CMGE_vB<2Ga*m{ERq8f zD;bJFaahDTc{PiCC=;vXXD%UDLx>nNP{L1>u?R#LDT4@zQXuOWhfQvNN@-52U6Bfq b3rZBl{6OLZGb1D8cP1%D!%qxA0;~Z5RdSZL delta 481 zcmaFJJ)ev3G%qg~0}%KH>Su0bo52BGmy38gfl>_&HzX7~SbBLUM>0w?=1neTv}G!qG5G+aGB;Bd(BNzh28JS`$pTCg zMynYiW-&5U0!_~X=|%%7%rG^z>@}<@Oq27Nv}3`>)G`5efZd6zC55Gese(xoD44=j zCCx+%sP`dF)Q(~gOsqOC+4OW@lSrhEXl|>`4_VSBgbTE7Fjls!Nof!+p)+pU*eXY zoWY{Zd{sbw@&XoF)(=t)A_|iauz2vQ8cuMT>ifZ%fk&o@YqBbR$*Qf MM#E1GKmx1;04Z@?x&QzG diff --git a/__pycache__/spawner.cpython-312.pyc b/__pycache__/spawner.cpython-312.pyc index 420f4abde544a9416641791f81a572a73ceeeb7e..9c719c3e8bfa11ab8bf24dd03a453036f3d058a6 100644 GIT binary patch delta 541 zcmey$d4!AiG%qg~0}zycH_0@Z$ScWcGf`dEErlV4Ifo^eHHwvyfr-JLA%&%dA%%4{ z6G$ZkLlj#jn3Wi%+85LK#CnmIVC1%Pb`iG8h5^pH@buq zq!N4_9p1>$3P{SI}4iRQxsA0?!oVgMxuxfD1D11FSVlN7H48gN_=8^D$osVll_@gSc^fDlk1tX**JiV;+DxDn5?|+ z2#C*MoME;=ai+y(0hJENJHlc>zTt$j$<`e%cO>K&2re*Oz&e|+!==ab29H3$U#H&; zlPf$5aQ1x5nU+_1R6lS}E?^E97Xq4G#1Aqa6eDV09pO6@ds=AT9=ZxrN~dpKycwCl(G?wa+4qta=dDAT@rP?6=rJ zp`4#v!~*2sVkt;0$tVJ8y~UB7SQMWG3~X?KfQ>9t07}5@GG}1;#bJ}1pHiBWYFDHJ llwkzoVvr*~Ff%eT-er)w%OG->LFPLPAEVwU1|R{}3IJXLki1kCXg%xLljFTt0vn^ z5OXEtE%u_syp+tm5>3Wi%+85L6T6}rpA{5}#6beQlciY{7{w>s zu*fn>PL5(Rsh0o?1BsOkMUo&kSRKd>MIeF&h>Hb*L<_?WKH&!UPb_?_ik}r2S@j^Q zL2CRoS#Pm{!Z1I#2&DcNOF?2uMiDEJ2{xlh9>jth{)@vVH$SB`C)KVToxF#rj$J^=UnWx)Ud 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