Skip to content

Commit f0831e4

Browse files
authored
Added a snake/water/gun game in python
1 parent 39b2e94 commit f0831e4

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

Snake_water_gun/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Snake_water_gun
2+
Snake Water Gun game

Snake_water_gun/main.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import random
2+
import time
3+
4+
class bcolors:
5+
HEADERS = '\033[95m'
6+
OKBLUE = '\033[94m'
7+
OKGREEN = '\033[93m'
8+
WARNING = '\033[92m'
9+
FAIL = '\033[91m'
10+
ENDC = '\033[0m'
11+
BOLD = '\033[1m'
12+
UNDERLINE = '\033[4m'
13+
14+
run = True
15+
li = ["s", "w", "g"]
16+
17+
print(bcolors.OKBLUE + bcolors.BOLD + "Welcome to the game 'Snake-Water-Gun'.\nWanna play? Type Y or N" + bcolors.ENDC)
18+
b = input()
19+
if b == "N" or b=="n":
20+
run = False
21+
print("Ok bubyeee! See you later")
22+
elif b=="Y" or b=="y":
23+
print("There will be 10 matches and the one who won max matches will win Let's start")
24+
25+
i=0
26+
w=0
27+
l=0
28+
while run and i<10:
29+
c = random.choice(li)
30+
a = input("Type s for snake,w for water or g for gun: ")
31+
32+
if a==c:
33+
print(bcolors.HEADERS + "Game draws.Play again" + bcolors.ENDC)
34+
i+=1
35+
print(f"{10-i} matches left")
36+
37+
elif a=="s" and c=="g":
38+
print(bcolors.FAIL +"It's Snake v/s Gun You lose!" + bcolors.ENDC)
39+
i+=1
40+
l+=1
41+
print(f"{10-i} matches left")
42+
elif a=="s" and c=="w":
43+
print(bcolors.OKGREEN + "It's Snake v/s Water. You won" + bcolors.ENDC)
44+
i += 1
45+
w += 1
46+
print(f"{10-i} matches left")
47+
48+
elif a=="w" and c=="s":
49+
print(bcolors.FAIL +"It's Snake v/s Gun You lose!" + bcolors.ENDC)
50+
i+=1
51+
l+=1
52+
print(f"{10-i} matches left")
53+
elif a=="w" and c=="g":
54+
print(bcolors.OKGREEN + "It's Snake v/s Water. You won" + bcolors.ENDC)
55+
i += 1
56+
w += 1
57+
print(f"{10-i} matches left")
58+
59+
elif a=="g" and c=="w":
60+
print(bcolors.FAIL +"It's Snake v/s Gun You lose!" + bcolors.ENDC)
61+
i+=1
62+
l+=1
63+
print(f"{10-i} matches left")
64+
elif a=="g" and c=="s":
65+
print(bcolors.OKGREEN + "It's Snake v/s Water. You won" + bcolors.ENDC)
66+
i += 1
67+
w += 1
68+
print(f"{10-i} matches left")
69+
70+
else:
71+
print("Wrong input")
72+
73+
if run == True:
74+
print(f"You won {w} times and computer won {l} times.Final result is...")
75+
time.sleep(3)
76+
if w >= l:
77+
print(bcolors.OKGREEN + bcolors.BOLD + "Woooh!!!!!!! Congratulations you won" + bcolors.ENDC)
78+
elif l==w:
79+
print("Game draws!!!!!!!")
80+
elif w <= l:
81+
print(bcolors.FAIL + bcolors.BOLD + "You lose!!!.Better luck next time" + bcolors.ENDC)
82+
83+
84+

0 commit comments

Comments
 (0)