-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1.py
119 lines (86 loc) · 2.56 KB
/
1.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
import random
from time import sleep
player1=0
player2=0
choice='y'
print ("---------------------------")
print ("| SNAKES AND LADDERS GAME |")
print ("---------------------------")
"""This method checks for the presence of snakes or ladders in the board"""
def check_for_snakes_and_ladders(n):
ladders = {4:14,9:31,28:84,18:45,21:42,51:67,71:91,78:97}
snakes = {26:11,52:29,62:19,66:59,74:17,89:69,95:75,98:79}
if n in ladders:
print ("\nYipee!")
print ("Its a ladder,Climb up\n")
n = ladders[n]
elif n in snakes:
print ("\nOops!")
print ("Its a snake,Come down\n")
n = snakes[n]
return n
"""This method generates random number for dice"""
def roll_dice():
d =random.randint(1,6)
print ("----------------------")
print ("| Dice has shown :",d,"|")
print ("----------------------")
return d
"""This method display output for number less than 10 """
def s_out(player1,player2):
print ("------------------")
print ("| Current Status |")
print ("------------------")
print ("---------------- \t ----------------")
print ("| PLAYER 1:",player1," |\t","| PLAYER 2:",player2," |")
print ("---------------- \t ----------------")
sleep(2)
"""This method display output for number greater than and equal to 10 """
def out(player1,player2):
print ("------------------")
print ("| Current Status |")
print ("------------------")
print ("-----------------\t -----------------")
print ("| PLAYER 1:",player1," |\t","| PLAYER 2:",player2," |")
print ("-----------------\t -----------------")
sleep(2)
""" Main Game function """
def game():
player1=0
player2=0
while True:
print ("\n\nIts turn of PLAYER 1\n")
player1 += roll_dice()
player1 = check_for_snakes_and_ladders(player1)
if player1>99:
player1=100
if(player1<10 or player2<10):
s_out(player1,player2)
else:
out(player1,player2)
if player1 > 99:
print ("\n---------------------------------")
print ("| Winner of the game is player1 |")
print ("---------------------------------")
break
print ("\n\nIts turn of PLAYER 2\n")
player2 += roll_dice()
player2 = check_for_snakes_and_ladders(player2)
if player2>99:
player2=100
if(player1<10 or player2<10):
s_out(player1,player2)
else:
out(player1,player2)
if player2 > 99:
print ("\n---------------------------------")
print ("| Winner of the game is player2 |")
print ("---------------------------------")
break
print ("-------------")
print ("| GAME OVER |")
print ("-------------")
""" Start Here"""
while(choice=='y'):
game()
choice=input('DO you want to play again(y/n): ')