forked from keshavsingh4522/hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdice_game.py
50 lines (36 loc) · 1.59 KB
/
dice_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
# import modules
import turtle
import random
# creating the screen
d = turtle.Screen()
d.setup(width=300, height=300)
d.bgcolor('white')
d.title('Dice Play')
d.tracer(1)
# creating the dots
dot_positions = [[(0, 0, 'red'), (-100, 100, 'white'), (-100, 0, 'white'), (-100, -100, 'white'), (100, 100, 'white'),
(100, 0, 'white'), (100, -100, 'white')],
[(0, 0, 'white'), (-100, 100, 'red'), (-100, 0, 'white'), (-100, -100, 'white'), (100, 100, 'white'), (100, 0, 'white'),
(100, -100, 'red')],
[(0, 0, 'red'), (-100, 100, 'red'), (-100, 0, 'white'), (-100, -100, 'white'), (100, 100, 'white'), (100, 0, 'white'),
(100, -100, 'red')],
[(0, 0, 'white'), (-100, 100, 'red'), (-100, 0, 'white'), (-100, -100, 'red'), (100, 100, 'red'), (100, 0, 'white'), (100, -
100, 'red')],
[(0, 0, 'red'), (-100, 100, 'red'), (-100, 0, 'white'), (-100, -100, 'red'), (100, 100, 'red'), (100, 0, 'white'), (100, -
100, 'red')],
[(0, 0, 'white'), (-100, 100, 'red'), (-100, 0, 'red'), (-100, -100, 'red'), (100, 100, 'red'), (100, 0, 'red'), (100, -
100, 'red')]]
dot = [turtle.Turtle() for _ in range(7)]
def click():
# generating random number
num = random.randint(1, 6)
print(f" The number rolled on dice is {num}\n ")
for i in range(7):
dot[i].shape('circle')
dot[i].color(dot_positions[num-1][i][2])
dot[i].penup()
dot[i].goto(dot_positions[num-1][i][0], dot_positions[num-1][i][1])
dot[i].dot()
d.listen()
d.onkeypress(click, 'space')
d.mainloop()