-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRound.das
87 lines (71 loc) · 1.97 KB
/
Round.das
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
require Die
require Combos
let NUM_DICE = 5
class Round
score: int = 0
dice: array<Die?>
combos: array<array<Die?>>
canThrowDice: bool = true
canSetAside: bool = false
canBankScore: bool = false
completed: bool = false
prizeRound: bool = false
def throwDice
if !canThrowDice
return
canThrowDice = false
canBankScore = false
if dice |> length() == 0
for i in range(NUM_DICE)
push(dice, new Die())
for die in dice
if !die.setAside
die->roll()
var vals <- self->getVals()
if !hasComb(vals)
score = 0
completed = true
else
canSetAside = true
def setAside
if !canSetAside
return
var selectedVals <- self->getSelectedVals()
if selectedVals |> length() == 0
return
let combsValue = selectedVals |> calculate()
if combsValue == 0
return
prizeRound = true
for die in dice
if die.selected
die.selected = false
die.setAside = true
if !die.setAside
canThrowDice = true
prizeRound = false
score += combsValue
canSetAside = false
canBankScore = true
if prizeRound
canThrowDice = true
for die in dice
die.setAside = false
def private getSelectedVals(): array<int>
var res: array<int>
for die in dice
if die.selected
push(res, die.value)
return <- res
def private getVals(): array<int>
var res: array<int>
for die in dice
if !die.setAside
push(res, die.value)
return <- res
def bankScore
if canBankScore
canBankScore = false
canSetAside = false
canThrowDice = false
completed = true