forked from RK1905101/Mini_Python_Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnake_game.py
128 lines (98 loc) · 2.46 KB
/
snake_game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import random
snakes={
17:7,
54:34,
62:19,
98: 79}
ladders={
3:38,
24:33,
42:93,
72: 84}
#start of game
print("\n###### Welcome to Snake & Ladder game ######\n")
#taking player input
print("\nEnter the name of player 1: ")
pname1 = input()
print("\nEnter the name of player 2: ")
pname2 = input()
p1 = p2 = 0
game = 0
while (game == 0):
#PLAYER 1 stuff
print("\n### " + pname1 + "'s Chance ###\n")
print("Enter 0 for auto mode and 1 for manual mode: ")
mode1 = int(input())
if (mode1 == 1):
num = int(input())
p1 = p1 + num
if (p1 == 100):
print("\n### " + pname1 + " Wins!! ###\n")
game = 1
elif (p1 < 100):
print("Your new position is " + str(p1))
else:
p1 = p1 - num
print("Rolled value overshoots goal, position will remain unchanged at " + str(p1))
elif (mode1 == 0):
print("Roll or Quit: ")
x = input()
if (x == "roll"):
num = random.randint(1, 6)
print("You got a " + str(num))
p1 = p1 + num
if (p1 == 100):
print("\n### " + pname1 + " Wins!! ###\n")
game = 1
elif (p1 < 100):
print("Your new position is " + str(p1))
else:
p1 = p1 - num
print("Rolled value overshoots goal, position will remain unchanged at " + str(p1))
elif (x == "quit"):
print("\n### " + pname2 + " Wins!! ###\n")
break
for key,value in snakes.items():
if p1 == key:
p1 = value
print("Snake brought you to " + str(p1))
for key,value in ladders.items():
if p1 == key:
p1 = value
print("Ladder brought you to " + str(p1))
#PLAYER 2 stuff
print("\n### " + pname2 + "'s Chance ###\n")
print("Enter 0 for auto mode and 1 for manual mode: ")
mode2 = int(input())
if (mode2 == 1):
num = int(input())
p2 = p2 + num
if (p2 >= 100):
print("\n### " + pname2 + " Wins!! ###\n")
game = 1
else:
print("Your new position is " + str(p2))
elif (mode2 == 0):
print("Roll or Quit: ")
x = input()
if (x == "roll"):
num = random.randint(1, 6)
print("You got a " + str(num))
p2 = p2 + num
if (p2 >= 100):
print("\n### " + pname2 + " Wins!! ###\n")
game = 1
else:
print("Your new position is " + str(p2))
elif (x == "quit"):
print("\n### " + pname1 + " Wins!! ###\n")
break
for key,value in snakes.items():
if p2 == key:
p2 = value
print("Snake brought you to " + str(p2))
for key,value in ladders.items():
if p2 == key:
p2 = value
print("Ladder brought you to " + str(p2))
print("### Thank You for Playing! ###")