Skip to content

Commit 78ca52d

Browse files
committed
Added local files
1 parent a60eaa5 commit 78ca52d

File tree

10 files changed

+778
-0
lines changed

10 files changed

+778
-0
lines changed

Cater_pillar/Cater_pillar.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import turtle as t
2+
import random as rd
3+
4+
t.bgcolor('yellow')
5+
6+
caterpillar = t.Turtle()
7+
caterpillar.shape('square')
8+
caterpillar.speed(0)
9+
caterpillar.penup()
10+
caterpillar.hideturtle()
11+
12+
leaf = t.Turtle()
13+
leaf_shape = ((0,0),(14,2),(18,6),(20,20),(6,18),(2,14))
14+
t.register_shape('leaf',leaf_shape)
15+
leaf.shape('leaf')
16+
leaf.color('green')
17+
leaf.penup()
18+
leaf.hideturtle()
19+
leaf.speed()
20+
21+
game_started = False
22+
text_turtle = t.Turtle()
23+
text_turtle.write('Press SPACE to start',align='center',font=('Arial',16,'bold'))
24+
text_turtle.hideturtle()
25+
26+
score_turtle = t.Turtle()
27+
score_turtle.hideturtle()
28+
score_turtle.speed(0)
29+
30+
def outside_window():
31+
left_wall = -t.window_width()/2
32+
right_wall = t.window_width()/2
33+
top_wall = t.window_height()/2
34+
bottom_wall = -t.window_height()/2
35+
(x,y) = caterpillar.pos()
36+
outside = x < left_wall or x > right_wall or y < bottom_wall or y > top_wall
37+
return outside
38+
39+
def game_over():
40+
caterpillar.color('yellow')
41+
leaf.color('yellow')
42+
t.penup()
43+
t.hideturtle()
44+
t.write('GAME OVER!',align='center' , font=('Aerial',30,'normal'))
45+
46+
def display_score(current_score):
47+
score_turtle.clear()
48+
score_turtle.penup()
49+
x = (t.window_width() / 2)-50
50+
y = (t.window_height() / 2)-50
51+
score_turtle.setpos(x,y)
52+
score_turtle.write(str(current_score) , align = 'right',font=('Arial',40,'bold'))
53+
54+
def place_leaf():
55+
leaf.hideturtle()
56+
leaf.setx(rd.randint(-200,200))
57+
leaf.sety(rd.randint(-200,200))
58+
leaf.showturtle()
59+
60+
def start_game():
61+
global game_started
62+
if game_started:
63+
return
64+
game_started = True
65+
66+
score = 0
67+
text_turtle.clear()
68+
69+
caterpillar_speed = 2
70+
caterpillar_length = 3
71+
caterpillar.shapesize(1,caterpillar_length,1)
72+
caterpillar.showturtle()
73+
display_score(score)
74+
place_leaf()
75+
76+
while True:
77+
caterpillar.forward(caterpillar_speed)
78+
if caterpillar.distance(leaf)<20:
79+
place_leaf()
80+
caterpillar_length = caterpillar_length + 1
81+
caterpillar.shapesize(1,caterpillar_length,1)
82+
caterpillar_speed = caterpillar_speed + 1
83+
score = score + 10
84+
display_score(score)
85+
if outside_window():
86+
game_over()
87+
break
88+
89+
def move_up():
90+
if caterpillar.heading() == 0 or caterpillar.heading() == 180:
91+
caterpillar.setheading(90)
92+
93+
def move_down():
94+
if caterpillar.heading() == 0 or caterpillar.heading() == 180:
95+
caterpillar.setheading(270)
96+
97+
def move_left():
98+
if caterpillar.heading() == 90 or caterpillar.heading() == 270:
99+
caterpillar.setheading(180)
100+
101+
def move_right():
102+
if caterpillar.heading() == 90 or caterpillar.heading() == 270:
103+
caterpillar.setheading(0)
104+
105+
t.onkey(start_game,'space')
106+
t.onkey(move_up,'Up')
107+
t.onkey(move_right,'Right')
108+
t.onkey(move_down,'Down')
109+
t.onkey(move_left,'Left')
110+
t.listen()
111+
t.mainloop()

Dice_stimulator/Dice_stimulator.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import random
2+
print("This is a dice stimulator! ")
3+
x = "y"
4+
5+
while x == "y":
6+
number = random.randint(1,6)
7+
8+
if number == 1:
9+
print("----------")
10+
print("| |")
11+
print("| O |")
12+
print("| |")
13+
print("----------")
14+
if number == 2:
15+
print("----------")
16+
print("| |")
17+
print("| O O |")
18+
print("| |")
19+
print("----------")
20+
if number == 3:
21+
print("----------")
22+
print("| O |")
23+
print("| O |")
24+
print("| O |")
25+
print("----------")
26+
if number == 4:
27+
print("----------")
28+
print("| O O |")
29+
print("| |")
30+
print("| O O |")
31+
print("----------")
32+
if number == 5:
33+
print("----------")
34+
print("| O O |")
35+
print("| O |")
36+
print("| O O |")
37+
print("----------")
38+
if number == 6:
39+
print("----------")
40+
print("| O O |")
41+
print("| O O |")
42+
print("| O O |")
43+
print("----------")
44+
x = input("Press y to roll again: ")
45+

Dictionary/Dictionary.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import json
2+
from difflib import get_close_matches
3+
4+
data = json.load(open("data.json"))
5+
6+
def translate(word):
7+
word = word.lower()
8+
if word in data:
9+
return data[word]
10+
elif word.title() in data:
11+
return data[word.title()]
12+
elif word.upper() in data:
13+
return data[word.upper()]
14+
elif len(get_close_matches(word , data.keys())) > 0 :
15+
print("Did you mean %s instead: " %get_close_matches(word, data.keys())[0])
16+
decide = input("Press y for yes or n for no: ")
17+
if decide == "y":
18+
return data[get_close_matches(word , data.keys())[0]]
19+
elif decide == "n":
20+
return("Pugger your paw steps on wrong keys: ")
21+
else:
22+
return("You have entered wrong input please enter just y or n: ")
23+
else:
24+
print("Pugger your paw steps on wrong keys: ")
25+
26+
27+
a=True
28+
while(a):
29+
word = input("Enter the word you want to search: ")
30+
output = translate(word)
31+
if type(output) == list:
32+
for item in output:
33+
print(item)
34+
else:
35+
print(output)
36+
print()
37+
res=input("To know the meaning of another word press 'c' or for quit 'q': ")
38+
if res=='q':
39+
a=False

Dictionary/data.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

Egg_catcher/Egg_catcher.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
from itertools import cycle
2+
from random import randrange
3+
from tkinter import Tk , Canvas , messagebox , font
4+
5+
canvas_width = 800
6+
canvas_height = 400
7+
8+
win = Tk()
9+
c = Canvas(win , width = canvas_width , height = canvas_height , background = 'deep sky blue')
10+
c.create_rectangle(-5, canvas_height - 100 , canvas_width + 5 , canvas_height + 5 , fill='sea green', width=0)
11+
c.create_oval(-80,-80,120,120,fill='orange' , width=0)
12+
c.pack()
13+
14+
color_cycle = cycle(['light blue' , 'light pink' , 'light yellow','light green' , 'red', 'blue' , 'green','black'])
15+
egg_width = 45
16+
egg_height = 55
17+
egg_score = 10
18+
egg_speed = 500
19+
egg_interval = 4000
20+
difficulty_factor = 0.95
21+
22+
catcher_color = 'blue'
23+
catcher_width = 100
24+
catcher_height = 100
25+
catcher_start_x = canvas_width / 2 - catcher_width / 2
26+
catcher_start_y = canvas_height -catcher_height - 20
27+
catcher_start_x2 = catcher_start_x + catcher_width
28+
catcher_start_y2 = catcher_start_y + catcher_height
29+
30+
catcher = c.create_arc(catcher_start_x ,catcher_start_y ,catcher_start_x2,catcher_start_y2 , start=200 , extent = 140 , style='arc' , outline=catcher_color , width=3)
31+
32+
score = 0
33+
score_text = c.create_text(10,10,anchor='nw' , font=('Arial',18,'bold'),fill='darkblue',text='Score : ' + str(score))
34+
35+
lives_remaning = 3
36+
lives_text = c.create_text(canvas_width-10,10,anchor='ne' , font=('Arial',18,'bold'),fill='darkblue',text='Lives : ' + str(lives_remaning))
37+
38+
eggs = []
39+
40+
def create_eggs():
41+
x = randrange(10,740)
42+
y = 40
43+
new_egg = c.create_oval(x,y,x+egg_width,y+egg_height,fill=next(color_cycle),width=0)
44+
eggs.append(new_egg)
45+
win.after(egg_interval,create_eggs)
46+
47+
def move_eggs():
48+
for egg in eggs:
49+
(egg_x,egg_y,egg_x2,egg_y2) = c.coords(egg)
50+
c.move(egg,0,10)
51+
if egg_y2 > canvas_height:
52+
egg_dropped(egg)
53+
win.after(egg_speed,move_eggs)
54+
55+
def egg_dropped(egg):
56+
eggs.remove(egg)
57+
c.delete(egg)
58+
lose_a_life()
59+
if lives_remaning == 0:
60+
messagebox.showinfo('GAME OVER!' , 'Final Score : ' + str(score))
61+
win.destroy()
62+
63+
def lose_a_life():
64+
global lives_remaning
65+
lives_remaning -= 1
66+
c.itemconfigure(lives_text , text='Lives : ' + str(lives_remaning))
67+
68+
def catch_check():
69+
(catcher_x,catcher_y,catcher_x2,catcher_y2) = c.coords(catcher)
70+
for egg in eggs:
71+
(egg_x,egg_y,egg_x2,egg_y2) = c.coords(egg)
72+
if catcher_x < egg_x and egg_x2 < catcher_x2 and catcher_y2 - egg_y2 < 40:
73+
eggs.remove(egg)
74+
c.delete(egg)
75+
increase_score(egg_score)
76+
win.after(100,catch_check)
77+
78+
def increase_score(points):
79+
global score , egg_speed , egg_interval
80+
score += points
81+
egg_speed = int(egg_speed * difficulty_factor)
82+
egg_interval = int(egg_interval * difficulty_factor)
83+
c.itemconfigure(score_text , text='Score : ' + str(score))
84+
85+
def move_left(event):
86+
(x1,y1,x2,y2) = c.coords(catcher)
87+
if x1 > 0:
88+
c.move(catcher,-20,0)
89+
90+
def move_right(event):
91+
(x1,y1,x2,y2) = c.coords(catcher)
92+
if x2 < canvas_width:
93+
c.move(catcher,20,0)
94+
95+
c.bind('<Left>' , move_left)
96+
c.bind('<Right>' , move_right)
97+
c.focus_set()
98+
99+
win.after(1000,create_eggs)
100+
win.after(1000,move_eggs)
101+
win.after(1000,catch_check)
102+
103+
win.mainloop()

0 commit comments

Comments
 (0)