-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZiehenPage.xaml.cs
269 lines (218 loc) · 8.81 KB
/
ZiehenPage.xaml.cs
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FLAD.Models;
namespace FLAD
{
/// <summary>
/// Interaktionslogik für ZiehenPage.xaml
/// </summary>
public partial class ZiehenPage : Page
{
public bool isEditMode { get; set; }
public bool isFresh { get; set; } = true;
public bool isFinished { get; set; }
public static ZiehenPage instance;
List<Position> positions;
public ZiehenPage()
{
instance = this;
InitializeComponent();
positions = new List<Position>
{
new Position(0, "STM"),
new Position(1, "STF"),
new Position(2, "WTM"),
new Position(3, "WTF"),
new Position(4, "ATM"),
new Position(5, "ATF"),
new Position(6, "Maschinist"),
new Position(7, "Melder"),
new Position(8, "GK")
};
}
private void btSTM_Click(object sender, RoutedEventArgs e)
{
SetOpacity("STM", imgSTM);
}
private void btSTF_Click(object sender, RoutedEventArgs e)
{
SetOpacity("STF", imgSTF);
}
private void btWTM_Click(object sender, RoutedEventArgs e)
{
SetOpacity("WTM", imgWTM);
}
private void btWTF_Click(object sender, RoutedEventArgs e)
{
SetOpacity("WTF", imgWTF);
}
private void btATM_Click(object sender, RoutedEventArgs e)
{
SetOpacity("ATM", imgATM);
}
private void btATF_Click(object sender, RoutedEventArgs e)
{
SetOpacity("ATF", imgATF);
}
private void btMelder_Click(object sender, RoutedEventArgs e)
{
SetOpacity("Melder", imgMelder);
}
private void btMaschinist_Click(object sender, RoutedEventArgs e)
{
SetOpacity("Maschinist", imgMaschinist);
}
private void btGK_Click(object sender, RoutedEventArgs e)
{
SetOpacity("GK",imgGK);
}
private void SetOpacity(string positionName,Image image)
{
positions.Where(s => s.Name == positionName).First().isEnabled = !positions.Where(s => s.Name == positionName).First().isEnabled;
var isEnabled = positions.Where(s => s.Name == positionName).First().isEnabled;
if (isEnabled) { image.Opacity = 1; }
else { image.Opacity = 0.3; }
}
private void btEdit_Click(object sender, RoutedEventArgs e)
{
var bgreen = new BrushConverter().ConvertFromString("#76CD65");
var green = bgreen as SolidColorBrush;
lbZiehen.Visibility = Visibility.Hidden;
isEditMode = !isEditMode;
if(isEditMode)
{
borderBack.BorderThickness = new Thickness(5);
borderBack.BorderBrush = green;
btSTM.IsEnabled = true;
btSTF.IsEnabled = true;
btWTM.IsEnabled = true;
btWTF.IsEnabled = true;
btATF.IsEnabled = true;
btATM.IsEnabled = true;
btMaschinist.IsEnabled=true;
btMelder.IsEnabled=true;
btGK.IsEnabled=true;
btSTM.Visibility=Visibility.Visible;
btSTF.Visibility = Visibility.Visible;
btWTM.Visibility = Visibility.Visible;
btWTF.Visibility = Visibility.Visible;
btATM.Visibility = Visibility.Visible;
btATF.Visibility = Visibility.Visible;
btMaschinist.Visibility = Visibility.Visible;
btMelder.Visibility = Visibility.Visible;
btGK.Visibility = Visibility.Visible;
}
else
{
borderBack.BorderThickness = new Thickness(0);
btSTM.IsEnabled = false;
btSTF.IsEnabled = false;
btWTM.IsEnabled = false;
btWTF.IsEnabled = false;
btATF.IsEnabled = false;
btATM.IsEnabled = false;
btMaschinist.IsEnabled = false;
btMelder.IsEnabled = false;
btGK.IsEnabled = false;
btSTM.Visibility = positions.Where(s => s.Name == "STM").First().GetVisibility();
btSTF.Visibility = positions.Where(s => s.Name == "STF").First().GetVisibility();
btWTM.Visibility = positions.Where(s => s.Name == "WTM").First().GetVisibility();
btWTF.Visibility = positions.Where(s => s.Name == "WTF").First().GetVisibility();
btATM.Visibility = positions.Where(s => s.Name == "ATM").First().GetVisibility();
btATF.Visibility = positions.Where(s => s.Name == "ATF").First().GetVisibility();
btMaschinist.Visibility = positions.Where(s => s.Name == "Maschinist").First().GetVisibility();
btMelder.Visibility = positions.Where(s => s.Name == "Melder").First().GetVisibility();
btGK.Visibility = positions.Where(s => s.Name == "GK").First().GetVisibility();
MainWindow.instance.btZiehen.Focus();
isFresh = true;
isFinished = false;
}
}
public void GetPosition()
{
if (isEditMode)
{
return;
}
var bred = new BrushConverter().ConvertFromString("#0A0A0A");
var red = bred as SolidColorBrush;
if (isFresh)
{
btSTM.Visibility = Visibility.Hidden;
btSTF.Visibility = Visibility.Hidden;
btWTM.Visibility = Visibility.Hidden;
btWTF.Visibility = Visibility.Hidden;
btATM.Visibility = Visibility.Hidden;
btATF.Visibility = Visibility.Hidden;
btMaschinist.Visibility = Visibility.Hidden;
btMelder.Visibility = Visibility.Hidden;
btGK.Visibility = Visibility.Hidden;
isFresh = false;
lbZiehen.Visibility = Visibility.Visible;
borderBack.BorderThickness = new Thickness(0);
positions.ForEach(s => s.isDrawn = false);
return;
}
else
{
var enabledPositions = positions.Where(s=>s.isEnabled == true).ToList();
var notDrawnPositions = enabledPositions.Where(s => s.isDrawn == false).ToList();
if (notDrawnPositions.Count == 1)
{
borderBack.BorderThickness = new Thickness(5);
borderBack.BorderBrush = red;
MainWindow.instance.btStopuhr.Focus();
isFresh = true;
}
lbZiehen.Visibility = Visibility.Hidden;
Random rnd = new Random();
var r = rnd.Next(notDrawnPositions.Count);
var next = notDrawnPositions[r];
next.isDrawn = true;
switch (next.Name)
{
case "STM":
btSTM.Visibility = Visibility.Visible;
break;
case "STF":
btSTF.Visibility = Visibility.Visible;
break;
case "WTM":
btWTM.Visibility = Visibility.Visible;
break;
case "WTF":
btWTF.Visibility = Visibility.Visible;
break;
case "ATM":
btATM.Visibility = Visibility.Visible;
break;
case "ATF":
btATF.Visibility = Visibility.Visible;
break;
case "Maschinist":
btMaschinist.Visibility = Visibility.Visible;
break;
case "Melder":
btMelder.Visibility = Visibility.Visible;
break;
case "GK":
btGK.Visibility = Visibility.Visible;
break;
}
}
}
}
}