From 98198e1019791c879ab1a182346626e0263f97db Mon Sep 17 00:00:00 2001 From: harsh_v <96617032+HARSHV10@users.noreply.github.com> Date: Sun, 2 Oct 2022 16:54:53 +0530 Subject: [PATCH 1/2] hey added a ping pong ball game added a ping pong ball game hoping for a merge Signed-off-by: harsh_v <96617032+HARSHV10@users.noreply.github.com> --- pingpong/__pycache__/ball.cpython-310.pyc | Bin 0 -> 1309 bytes pingpong/__pycache__/play.cpython-310.pyc | Bin 0 -> 942 bytes .../__pycache__/scoreboard.cpython-310.pyc | Bin 0 -> 1205 bytes pingpong/ball.py | 24 +++++++++ pingpong/main.py | 48 ++++++++++++++++++ pingpong/play.py | 18 +++++++ pingpong/scoreboard.py | 28 ++++++++++ 7 files changed, 118 insertions(+) create mode 100644 pingpong/__pycache__/ball.cpython-310.pyc create mode 100644 pingpong/__pycache__/play.cpython-310.pyc create mode 100644 pingpong/__pycache__/scoreboard.cpython-310.pyc create mode 100644 pingpong/ball.py create mode 100644 pingpong/main.py create mode 100644 pingpong/play.py create mode 100644 pingpong/scoreboard.py diff --git a/pingpong/__pycache__/ball.cpython-310.pyc b/pingpong/__pycache__/ball.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..acbf49c9f9477a2c165ab8fc60d76e33729a0d79 GIT binary patch literal 1309 zcmZ`(J#Q015Z%2mpB+1d5Qv2MNI`QFqz6R=5d@u^Kx0{2Iky|z;e2=Oo=F^;Dv{FB zLzR^I2~_+6_ygBcph)}z8hEpIkON_@do!~;=XriJ>#WhJF|2Q!pSRvSuoTQL55W^W zW(6RboM)>q>rtAAlWCI#bV=E_u=$GZ9#8lkXxr@ZuxO15FELc~eO7$HvC&j%Zi+OLe##$x-KGOvp)Z|9?;m!<8zpLX*s z?Y6fd%xXT;M9yll0H?-7UbCNo2eA7M(r@*g=mjC^CF=YJ9&;Z6vDgW4hcB~td?F?y z7m-6kj``R*aUdYc#hZ~|dV6uE^%cBZdLwd)L+N$1B8yyo4MEFG)$U$NIMO$;F@a^9 zM_Sb3nE)`)=lKHPuUf)%a)Io5*Dcvaq>sUU2c!CsIZR9_InA?QSP{20G-dr=vZB>C zCbl4+23LVC^8LE4I6e4((G_H0ENUZ+w55O{hbnGU-$q{d>la!-)+5KNqpxD~QbNI2 zHcVqhTn#m2o`cbxWi&bYhtQvv-9tLH47ZBgwxCG@ZG$ejw3d`(NqJ38^68L(=%F_^ z$+xVidzVrpt+X<|>qxL2s$-;P^`b-E23&)*Gf=n&H6aF>946$~g?KaUB$E?6r1}JMjNCFP>>rV)EW0`L VJ$B~oxP@yIa*s(2D|VeN@!#Rz5!e6# literal 0 HcmV?d00001 diff --git a/pingpong/__pycache__/play.cpython-310.pyc b/pingpong/__pycache__/play.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e0c2ff19a53ba74e65378db3e282450e1f84c21a GIT binary patch literal 942 zcma)5&1%~~5T2D*itN~_DQ+9+4?Xk}X!8K2lt5Z?^Cj&?7#3H%u|;LAvMb@*q$eBl z8u8Ijk@whZPd@k7Q)gtmm_nf|^zHmHKi^2Y-EIP&`N#V&_YB|%Df@?`a)z&cg&;w) z48|;GV=wj?T!8eXzX0hgHuqy+@=G`g)))yVo(n%!rp%NJFB79wo{)L}_*=!kMnOT$ zB*fk=TrtU{w}>zuCR{+wWgtVmgInMbhgjmk@r%J&CEi{-lBrqBYR?c#n8O`g0)rd4 z^R~Ay*^<>3F1@W3P@N@?gK^aud9JkYs$YymZ*ckR)sPy5+cph zQV16mDz6F`Bs$Xu-J?OFT%*2hI#Z4hb*YgSZdG>WqC(rWOm)6ut|3H{4XhPn1;5^$ zzwLjv%GetFAC&!C>Y`sv%aP9eMVb!_oe%p(Hkh6kQ$yRMwrmTb$s*Ror^SxgtW6Z1 z?%GSJ?cLdNb&dx65&_>@_Oqo#;ttEr-?S^0VPdb? zuIC7|!);x%;`(rJIr4*hYYH*evdTzq34xo=HlCVW^NcdQKydBtni7>|LhKcMNFg+@ y`SSrrs6{w%bkOl@Ywv`+u&jRwL-ZT^PHWFzqI!m!xai%cr}wlrOKCgM^?m~|L(Vq< literal 0 HcmV?d00001 diff --git a/pingpong/__pycache__/scoreboard.cpython-310.pyc b/pingpong/__pycache__/scoreboard.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..feca1f01bfa04a1a6ef808012864e92248548956 GIT binary patch literal 1205 zcmZ`(zi-n(6n^Jlb{5h0Gj33w2%V2GCSchgeIlr8zCIk~2;w-IVMf>U+| z3=ZMcS&Z&t^aMM@41{wC+_xB@)e4;ozz}ZV_+Q3ZEfx8VLgVYElFEdfXGKB~H(o@wCi`IJP)X^F(XT&*AU$omYboS}JXE z@K)+iby*FngL+&RgDNXVRauM%niAeG6D78)0~K5*+QUhkh4{2tfKSJr_AEDBmlwT3 z61}^FUB5@bq)|}eoH<0(M~2<`hJp&q{#VbE2dKcZg=;NB(uXW8VXc1l{o>+c_7k1% zAq8?+M{evVDogU&1Kc!0QL0IjM~?B6JR23p8JVQm2!~iwACZ8U-~cBwuGI@A zcJB0Nwgg;z9n?6NiL$|OyOrssjZ(6}!XMVC`UXWJ#(OAHhfO!;*Sl`?-#e;D_@;V{ z5V>lzEXNG1{sy3P5d6irU^4(FenB%hzy zYMTdrLJprHnC_y6Q<>+SFKM$zCRQL~8viGtNyiW+3RlBm-BYyRk6aVXKO03hc5}&# V)tbDRaC?5M*QA1`e^CcE*grY63UmMf literal 0 HcmV?d00001 diff --git a/pingpong/ball.py b/pingpong/ball.py new file mode 100644 index 0000000..75b244e --- /dev/null +++ b/pingpong/ball.py @@ -0,0 +1,24 @@ +from turtle import Turtle +class Ball(Turtle): + def __init__(self): + super().__init__() + self.penup() + self.speed("slowest") + self.shape("circle") + self.color("white") + self.xmove= 10 + self.ymove= 10 + self.move_speed =0.1 + def move(self): + newx= self.xcor()+self.xmove + newy= self.ycor()+self.ymove + self.goto(newx,newy) + def reflect(self): + self.ymove *= -1 + def bounce(self): + self.xmove *= -1 + self.move_speed *= 0.9 + def refresh(self): + self.goto(0,0) + self.move_speed = 0.1 + self.xmove *= -1 diff --git a/pingpong/main.py b/pingpong/main.py new file mode 100644 index 0000000..ed03829 --- /dev/null +++ b/pingpong/main.py @@ -0,0 +1,48 @@ +from turtle import Turtle ,Screen +from play import Game +from ball import Ball +from scoreboard import Score +import time +screen = Screen() +paddle1 = Game((350,0)) +paddle2 = Game((-350,0)) +ball = Ball() +score = Score() +screen.tracer(0) + +paddle1.goto(350,0) +paddle2.goto(-350,0) + +screen.setup(width=800,height=600) +screen.bgcolor("black") +screen.title("PONG") + + +screen.listen() +if paddle1.xcor()<390 or paddle2.ycor()<-350: + screen.onkey(fun=paddle1.goup,key="Up") + screen.onkey(fun=paddle1.godown,key="Down") + screen.onkey(fun=paddle2.goup,key="w") + screen.onkey(fun=paddle2.godown,key="s") + +game_on = True +while game_on: + time.sleep(ball.move_speed) + ball.move() + if ball.ycor()>280 or ball.ycor()<-280: + ball.reflect() + if ball.distance(paddle1)<40 or ball.distance(paddle2)<40: + ball.bounce() + + if ball.xcor()>400 : + ball.refresh() + score.goto(-300, 250) + score.currentleftscr() + if ball.xcor() < -400: + ball.refresh() + score.goto(300, 250) + score.currentrightscr() + screen.update() + + +screen.exitonclick() diff --git a/pingpong/play.py b/pingpong/play.py new file mode 100644 index 0000000..3378bec --- /dev/null +++ b/pingpong/play.py @@ -0,0 +1,18 @@ +from turtle import Turtle , Screen + +class Game(Turtle) : + def __init__(self,position): + super().__init__() + self.penup() + self.color("white") + self.shape("square") + self.shapesize(4, 1) + self.goto(position) + def goup(self): + newy = self.ycor()+20 + self.goto(self.xcor(),newy) + def godown (self): + newy = self.ycor()-20 + self.goto(self.xcor(),newy) + + diff --git a/pingpong/scoreboard.py b/pingpong/scoreboard.py new file mode 100644 index 0000000..92e8e4b --- /dev/null +++ b/pingpong/scoreboard.py @@ -0,0 +1,28 @@ +from turtle import Turtle +class Score(Turtle): + def __init__(self): + super().__init__() + self.penup() + self.hideturtle() + self.color("white") + self.lscr=0 + self.rscr=0 + + + self.updatescr() + + def updatescr(self): + self.goto(-100, 200) + self.write(f"{self.lscr}", True, align="left", font=("arial", 24, "normal")) + self.goto(100, 200) + self.write(f"{self.rscr}", True, align="right", font=("arial", 24, "normal")) + + def currentleftscr(self): + self.lscr+=1 + self.clear() + self.updatescr() + def currentrightscr(self): + self.rscr+=1 + self.clear() + self.updatescr() + From b8383c8bcacec975f29a7c63506a28a50a035ea5 Mon Sep 17 00:00:00 2001 From: harsh_v <96617032+HARSHV10@users.noreply.github.com> Date: Mon, 3 Oct 2022 22:37:05 +0530 Subject: [PATCH 2/2] hey added a snake game hoping for a merge hey added a snake game hoping for a merge Signed-off-by: harsh_v <96617032+HARSHV10@users.noreply.github.com> --- snakegame/snake_game/README.md | 3 + .../__pycache__/food.cpython-310.pyc | Bin 0 -> 895 bytes .../__pycache__/scorecard.cpython-310.pyc | Bin 0 -> 1488 bytes .../__pycache__/snake.cpython-310.pyc | Bin 0 -> 2277 bytes snakegame/snake_game/check.py | 38 ++++++++++++ snakegame/snake_game/data | 1 + snakegame/snake_game/food.py | 18 ++++++ snakegame/snake_game/highscore.txt | 0 snakegame/snake_game/main.py | 49 ++++++++++++++++ snakegame/snake_game/scorecard.py | 36 ++++++++++++ snakegame/snake_game/snake.py | 55 ++++++++++++++++++ 11 files changed, 200 insertions(+) create mode 100644 snakegame/snake_game/README.md create mode 100644 snakegame/snake_game/__pycache__/food.cpython-310.pyc create mode 100644 snakegame/snake_game/__pycache__/scorecard.cpython-310.pyc create mode 100644 snakegame/snake_game/__pycache__/snake.cpython-310.pyc create mode 100644 snakegame/snake_game/check.py create mode 100644 snakegame/snake_game/data create mode 100644 snakegame/snake_game/food.py create mode 100644 snakegame/snake_game/highscore.txt create mode 100644 snakegame/snake_game/main.py create mode 100644 snakegame/snake_game/scorecard.py create mode 100644 snakegame/snake_game/snake.py diff --git a/snakegame/snake_game/README.md b/snakegame/snake_game/README.md new file mode 100644 index 0000000..1a9d552 --- /dev/null +++ b/snakegame/snake_game/README.md @@ -0,0 +1,3 @@ +# snake_game +classic snake game "eat more to grow more" +a basic snake game diff --git a/snakegame/snake_game/__pycache__/food.cpython-310.pyc b/snakegame/snake_game/__pycache__/food.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d3bce018056877a98dae5ff7e6a315841c7e3b4b GIT binary patch literal 895 zcmY*X!EVz)5Z&FZ9Va*?h$8U;9PlOLj1W{R0*ON|z{QHRa=n|xbYq*{jY^_$YNej| zhxXWCK;lRCgv13t0S=TI$AvH}KhNw;-pstX8Vvdb?Dpp`M?Wbc-!RxU4#5FD_91{I zl4`P`DW&K$%~JM~$d2S^L~=z>J84I<*CYvkKs8CI58o_}(`uY!ylb5{un)jdB&Cw1 z?3_%gq>`OQz|*j%{G4!-2FU68i>i`2O!?Q)#|e?mz5;OMlw8nDLdk|)Fi9_AQt)7^ z*5hq1*uLL|&<8qwVohCF23RKv^b5y6%nOrimGUFKR5PFl`}!C>b#*FxNjBg zjEnETudj>y@HZvg41mLjCM#vNNW1thO6U2ka#hkXL(K9IIVi(dfaWe-Y+)b07yuWr z5kN#^I77OQoB3NMlMux&VRsO_FT|pfOO1Xk#QSBYx0yzdhRzRKS#zbe5IY_3V8^EI vjS3bOj7ZFek-@u!`_MJtwqaO&4*?T9EX@YU;-e?qS)Sqt+fc=@!#?{1Y*o3Xrb^yLhBGWh|aU_bg_^mphrPyP#jNoKSc_uTBF(X3`9ee=!CR?EvR0?*mAf1ff= z$ZPyqd|-|I2*ca~A&H~~*`*1kM6!g*APLrqE$guNhJR8q+fq9l-klv1JuylfFMB^Lvtz4KZ?tCzRoOFTwxjyluIl-t z@=VLSqdom01QEh8S5aXrY?WSr(`vM6L|0(6>Hf+F#&!1{;0q~3egup)JmD)4Krflo z3)L_s+w2vTBFw=n@(;J%3K<+ivOK}OyB}_>J^ttOA`&u>q~Hx{s4q){`BbKdiU4+-A%`TdEDJRq52vcKRXv4)II_65e$R< z64Bdq|8gDG0=e%6hIQxzy9vq^s%#r7@;kzyC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ew() + snake.new() + + + # collision with the tail + for i in snake.segment[1:]: + if i == snake.head: + pass + elif snake.head.distance(i)<10: + score.renew() + snake.new() + + + + +screen.exitonclick() \ No newline at end of file diff --git a/snakegame/snake_game/scorecard.py b/snakegame/snake_game/scorecard.py new file mode 100644 index 0000000..96ba8f2 --- /dev/null +++ b/snakegame/snake_game/scorecard.py @@ -0,0 +1,36 @@ +from turtle import Turtle +ALIGNMENT="center" +FONT=('joker', 24, 'normal') + +class Score(Turtle): + def __init__(self): + + self.scoreval =0 + + with open("data", mode="r") as file: + self.highscore = int(file.read()) + + + # file= open("data") + # data=file.read() + # self.data=int(data) + super().__init__() + self.color("white") + self.penup() + self.goto(x=0, y=250) + self.hideturtle() + self.updatescore() + def updatescore(self): + self.clear() + self.write(f"SCORE:{self.scoreval} HIGH SCORE:{self.highscore}", align=ALIGNMENT, font=FONT) + def currentscore(self): + self.scoreval+=1 + self.clear() + self.updatescore() + def renew(self): + if self.scoreval>self.highscore: + self.highscore = self.scoreval + with open("data", mode="w") as change: + change.write(str(self.scoreval)) + self.scoreval=0 + self.updatescore() \ No newline at end of file diff --git a/snakegame/snake_game/snake.py b/snakegame/snake_game/snake.py new file mode 100644 index 0000000..fd2213d --- /dev/null +++ b/snakegame/snake_game/snake.py @@ -0,0 +1,55 @@ +#ab hum snake ki class banaenge jo humar acoe tidy kar degi +from turtle import Turtle +BODY = [(0, 0), (-20, 0), (-40, 0)] +STEP = 20 +UP = 90 +DOWN = 270 +LEFT = 180 +RIGHT = 0 +SHAPE="square" +COLOR="white" +class Snake : + def __init__(self): + self.segment=[] + self.createsnake() + self.head = self.segment[0] + + def createsnake(self): + for parts in BODY: + self.addseg(parts) + def new(self): + for i in self.segment: + i.goto(700,700) + self.segment.clear() + self.createsnake() + self.head = self.segment[0] + def addseg(self,parts): + # is wale function se segment add ho rahe hai + moti = Turtle() + moti.color(COLOR) + moti.shape(SHAPE) + moti.penup() + moti.goto(parts) + self.segment.append(moti) + def extend(self): + self.addseg(self.segment[-1].position()) + def move(self): + for seg in range(len(self.segment) - 1, 0, -1): + new_xpos = self.segment[seg - 1].xcor() + new_ypos = self.segment[seg - 1].ycor() + self.segment[seg].goto(new_xpos, new_ypos) + self.head.forward(STEP) + def up(self): + if self.head.heading() != DOWN: + self.head.setheading(UP) + def down(self): + if self.head.heading() != UP: + self.head.setheading(DOWN) + def left(self): + if self.head.heading() != RIGHT: + self.head.setheading(LEFT) + def right(self): + if self.head.heading() != LEFT: + self.head.setheading(RIGHT) + +