-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToss.py
More file actions
51 lines (44 loc) · 1.42 KB
/
Toss.py
File metadata and controls
51 lines (44 loc) · 1.42 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
from __future__ import print_function
import sys
from Dice import *
from DB import *
class Toss:
def __init__(self):
self.db = DB()
self.dice1 = Dice()
self.dice2 = Dice()
self.number = 0
def roll(self):
self.dice1.roll()
self.dice2.roll()
self.db.insertToss(self.dice1.result, self.dice2.result)
if self.number or not self.isPasch():
self.number += 1
self.print()
def isPasch(self):
return self.dice1.result == self.dice2.result
def print(self):
if not self.number:
print(str(self.dice1.result) + ',' + str(self.dice2.result) + " Pasch in initial roll. Rolling again..." + '\n')
elif self.number & 1:
print(str((self.number+2) >>1) + '\t', end='')
print(str(self.dice1.result) + ' ', end='')
self.dice1.speak()
print(str(self.dice2.result) + ' ', end='')
self.dice2.speak()
else:
print("\t", end='')
print(str(self.dice1.result) + ' ', end='')
self.dice1.speak()
print(str(self.dice2.result) + ' ', end='')
self.dice2.speak()
print('')
sys.stdout.flush()
def initial(self):
while True:
self.roll()
if not self.isPasch():
self.number = 1
return
else:
self.number = 0