From aa23466c8a0becd0f30314cdced625e7f3c85641 Mon Sep 17 00:00:00 2001 From: Usman Irfan <usmanirfan@USERs-MacBook-Pro.local> Date: Tue, 20 Nov 2018 17:55:31 -0500 Subject: [PATCH] fixed bug --- BlankProjectTemplate/src/Food.py | 6 +++++- BlankProjectTemplate/src/Gameplay.py | 8 ++++---- .../src/__pycache__/Food.cpython-37.pyc | Bin 969 -> 1047 bytes .../src/__pycache__/Snake.cpython-37.pyc | Bin 820 -> 813 bytes .../src/__pycache__/init.cpython-37.pyc | Bin 529 -> 522 bytes 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/BlankProjectTemplate/src/Food.py b/BlankProjectTemplate/src/Food.py index 4256507..aaed113 100644 --- a/BlankProjectTemplate/src/Food.py +++ b/BlankProjectTemplate/src/Food.py @@ -26,7 +26,11 @@ class Food(): # @param y is the location of snake's y-axis head location # @param location is a list that gives the location of present food # @param screenSize is the size of the screen - def redraw_food(self, x, y, location,screenSize): + def redraw_food(self, x, y, location,screenSize, snake_loc): + if(abs(x - location[0]) < 15 and abs(y - location[1]) < 15): location[0] = randint(0, grid_length - 1) * self.size location[1] = randint(0, grid_length - 1) * self.size + if(location[0], location[1] in snake_loc): + location[0] = randint(0, grid_length - 1) * self.size + location[1] = randint(0, grid_length - 1) * self.size diff --git a/BlankProjectTemplate/src/Gameplay.py b/BlankProjectTemplate/src/Gameplay.py index 04af693..7172913 100644 --- a/BlankProjectTemplate/src/Gameplay.py +++ b/BlankProjectTemplate/src/Gameplay.py @@ -111,10 +111,7 @@ while run: font = pygame.font.SysFont("times",30) text = font.render("Score = " + str(score),True,[0,0,0]) win.blit(text,(0,0)) - #function to print - #consumption of food block - food.redraw_food(x, y, food_location, screenSize) - + if ([x,y] in snake_loc) and snake_length > 1: pygame.time.delay(1000) pygame.quit() #quit for now, but should return to main menu @@ -125,6 +122,9 @@ while run: snake_loc.append(snake_head) + #function to print + #consumption of food block + food.redraw_food(x, y, food_location, screenSize, snake_loc) snake_blocks = len(snake_loc) diff --git a/BlankProjectTemplate/src/__pycache__/Food.cpython-37.pyc b/BlankProjectTemplate/src/__pycache__/Food.cpython-37.pyc index 6b0953264c84128a6d088c3e19e941613b4f95b1..9a830c92d74ee361f1368ca26cb0c6d707d95e30 100644 GIT binary patch delta 235 zcmX@fKAnTliI<m)0SMYAe2MmDo5=T4$x%PFIJKx)zqB|vF)y<yEiq5uCAB!aB)>qv zIMui!(O7@70;344esNK<{$xwW=Z<V3{XhVsS%BCXh>I5hi4uky#v0}nMo9(<hGxbT zrfi0yIY2Qcpcpf<*yKbe0}+Tqh*S-0Hd`7~(Hx*ess>vT$lzOy6}K2Giv&STuHxjP w)YQD-%&OE|oW*&G*{Sh4`N@+XGb!@&0Oc8&G#Dj-P-HSUvpb{I<Y4A90G~`cD*ylh delta 198 zcmbQvagv?SiI<m)0SI1+zKyP6oyhmn$-~(yCbT%Us5qu9*~r*1#wE2lyClCLrZP3L z$T%j#(Kx0!)wm+jIL0X_F)uryC_gJTxg;btw;(66BsHeEC^=@b5#w_)R*<Pc0HRrd z*cph6V<zh}iHSy(Fw`*BFsCp}GDt8qGo~<QGZaNkp2w6b%UZ++RCbH8;ud3Nksyf4 jRh(Runwl4!S(Q3jn^}<^B+tO8F*%aiol$b~Lgq36Z6`IF diff --git a/BlankProjectTemplate/src/__pycache__/Snake.cpython-37.pyc b/BlankProjectTemplate/src/__pycache__/Snake.cpython-37.pyc index d1439d6a6f3d19a239cca60542761a16a4361e2c..64ed5e1ffc62e81f7a69696008571de8734360c2 100644 GIT binary patch delta 70 zcmdnOww8_CiI<m)0SMNcz23;p!>Ht>A6lGRRIFcGoST@JS(KKTr|*(loL!P%pkJJ7 YT#;z3KiPp%gjK(|C|Q4VB;##H0L<zYdH?_b delta 92 zcmZ3>wuOz`iI<m)0SI1+zTL>p!|3GcY!wq)oLW>IQ<iLGY#8H`TAW>yUl3E7npk8U u6X9qaQ=DpCk!T#_l#`g39Z-~?m6}`<lA2qPlUR}(Q(TlBvpI<IHX{HepdTLq diff --git a/BlankProjectTemplate/src/__pycache__/init.cpython-37.pyc b/BlankProjectTemplate/src/__pycache__/init.cpython-37.pyc index cce923f0e289ed3fb9a8cb0638c6cb526bac5e44..5ef93ec9897c680e94b72d19d335652862a2b13f 100644 GIT binary patch delta 84 zcmbQp(#68<#LLUY00c_buQzf}V6=AB4=qkDD%LM8&P~kAEJ{nv(|1WN&MwI>&@WCk mu1GZ2cgji3%MK{Y&q_@$2}#W@$Vn_o)h{ke)}MTr(F6c4qZ|$Z delta 91 zcmeBTnaINJ#LLUY00gf@-)`id!06=RY!wq)oLW>IQ<iLGY#8H`TAW>yUl3E7npk8U t6X9qaQ=DpCk!T#_l#`g39Z-~?m6}`<lA2qPlUR}(Q(TlBGx-{$2>=m99~1xp -- GitLab