-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_dice.py
More file actions
51 lines (38 loc) · 1.08 KB
/
new_dice.py
File metadata and controls
51 lines (38 loc) · 1.08 KB
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
'''
new_dice.py
new dice functions / classes
'''
import random
class Die(object):
faces = (None,' \n| * |\n \none',' *\n| |\n * \ntwo',' *\n| * |\n *\nthree','* *\n| |\n * *\nfour','* *\n| * |\n * *\nfive','***\n| |\n ***\nsix')
def __init__(self, faces=None):
if faces is not None:
self.faces = faces
self.value = 1
def print_faces(self):
count = 1
tmp = [][:]
for itm in self.faces:
tmp.append('face {}'.format(count) + '\n' + itm)
count += 1
print ' '.join(map(str,tmp))
def __str__(self):
return self.faces[self.value]
def roll(self):
self.value = random.randrange(1,len(self.faces))
def test():
myRoll = (Die(),Die(),Die(),Die(),Die(),Die())
dieFormat = '''{} {} {}
{} {} {}
'''
for d in range(len(myRoll)):
myRoll[d].roll()
#print ' '.join(map(str,myRoll))
print dieFormat.format(*myRoll)
#d = Die()
#d.print_faces()
#print d
#d.roll()
#print d
if __name__ == "__main__":
test()