-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeftPanel.cs
More file actions
176 lines (137 loc) · 4.76 KB
/
Copy pathLeftPanel.cs
File metadata and controls
176 lines (137 loc) · 4.76 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using Godot;
using System;
using System.Collections;
using System.Collections.Generic;
public partial class LeftPanel : TextureRect
{
const int NumberOfButtons = 6;
private IList<Button> _buttons = new List<Button>(NumberOfButtons);
private bool[] _buttonDisabled = new bool[NumberOfButtons];
private Main _mainScene;
public bool PanelCompleted { get; set; } = false;
public int PanelTotal { get; set; } = 0;
public Main MainScene
{
get { return _mainScene; }
set
{
_mainScene = value;
for (int i = 1; i <= Constants.NumberOfDice; i++)
{
_buttons.Add(GetNode<Button>("Button" + i));
}
_buttons.Add(GetNode<Button>("Button6"));
value.MustRoll += MainScene_MustRoll;
value.FirstRoll += MainScene_FirstRoll;
}
}
public void MainScene_MustRoll(object sender, EventArgs e)
{
foreach (Button button in _buttons)
{
button.Disabled = true;
}
}
public void MainScene_FirstRoll(object sender, EventArgs e)
{
bool allDisabled = true;
for (int i = 0; i < _buttons.Count; i++)
{
if (!_buttonDisabled[i])
{
allDisabled = false;
}
_buttons[i].Disabled = _buttonDisabled[i];
}
if (allDisabled && !PanelCompleted)
{
if (PanelTotal >= 63)
{
MainScene.TotalScore += 35;
MainScene.BonusScore += 35;
PanelCompleted = true;
}
}
}
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
public void OneClicked()
{
_buttons[(int)DiceFrame.One].Disabled = true;
int total = 0;
(int[] instanceCounts, bool foundFive) = MainScene.GetInstanceCounts();
total += instanceCounts[(int)DiceFrame.One];
GetNode<Label>("OneLabel/Label").Text = total.ToString();
PanelTotal += total;
_buttonDisabled[(int)DiceFrame.One] = true;
MainScene.ResetForNextRoll(total, foundFive);
}
public void TwoClicked()
{
_buttons[(int)DiceFrame.Two].Disabled = true;
int total = 0;
foreach (Dice die in MainScene.DiceList)
{
if (die.Value == DiceValue.Two)
{
total += (int)DiceValue.Two;
}
}
(int[] instanceCounts, bool foundFive) = MainScene.GetInstanceCounts();
total += instanceCounts[(int)DiceFrame.Two] * 2;
GetNode<Label>("TwoLabel/Label").Text = total.ToString();
PanelTotal += total;
_buttonDisabled[(int)DiceFrame.Two] = true;
MainScene.ResetForNextRoll(total, foundFive);
}
public void ThreeClicked()
{
_buttons[(int)DiceFrame.Three].Disabled = true;
int total = 0;
(int[] instanceCounts, bool foundFive) = MainScene.GetInstanceCounts();
total += instanceCounts[(int)DiceFrame.Three] * 3;
GetNode<Label>("ThreeLabel/Label").Text = total.ToString();
PanelTotal += total;
_buttonDisabled[(int)DiceFrame.Three] = true;
MainScene.ResetForNextRoll(total, foundFive);
}
public void FourClicked()
{
_buttons[(int)DiceFrame.Four].Disabled = true;
int total = 0;
(int[] instanceCounts, bool foundFive) = MainScene.GetInstanceCounts();
total += instanceCounts[(int)DiceFrame.Four] * 4;
GetNode<Label>("FourLabel/Label").Text = total.ToString();
PanelTotal += total;
_buttonDisabled[(int)DiceFrame.Four] = true;
MainScene.ResetForNextRoll(total, foundFive);
}
public void FiveClicked()
{
_buttons[(int)DiceFrame.Five].Disabled = true;
int total = 0;
(int[] instanceCounts, bool foundFive) = MainScene.GetInstanceCounts();
total += instanceCounts[(int)DiceFrame.Five] * 5;
GetNode<Label>("FiveLabel/Label").Text = total.ToString();
PanelTotal += total;
_buttonDisabled[(int)DiceFrame.Five] = true;
MainScene.ResetForNextRoll(total, foundFive);
}
public void SixClicked()
{
_buttons[(int)DiceFrame.Six].Disabled = true;
int total = 0;
(int[] instanceCounts, bool foundFive) = MainScene.GetInstanceCounts();
total += instanceCounts[(int)DiceFrame.Six] * 6;
GetNode<Label>("SixLabel/Label").Text = total.ToString();
PanelTotal += total;
_buttonDisabled[(int)DiceFrame.Six] = true;
MainScene.ResetForNextRoll(total, foundFive);
}
}