-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrainingPage.xaml.cs
165 lines (146 loc) · 4.97 KB
/
TrainingPage.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
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.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
using ZTProj.modes;
namespace ZTProj
{
/// <summary>
/// Logika interakcji dla klasy TrainingPage.xaml
/// </summary>
public partial class TrainingPage : Page
{
private DifficultyLevel dificulty;
private IDatabase facade = new IDatabase();
private Action action;
WordTrans wordTrans;
private string mode;
Test test;
Caretaker caretaker;
List<string> previousAnswers;
public TrainingPage(string lvl, string lang, string type, string mode)
{
switch(type)
{
case "training":
action = new Training();
break;
case "Test":
action = new Test();
break;
}
switch (lvl)
{
case "Łatwy":
dificulty = new DifficultyLevel(new Easy());
break;
case "Normalny":
dificulty = new DifficultyLevel(new Normal());
break;
case "Trudny":
dificulty = new DifficultyLevel(new Hard());
break;
case "Ekspert":
dificulty = new DifficultyLevel(new Expert());
break;
case "Mistrz":
dificulty = new DifficultyLevel(new Master());
break;
}
this.mode = mode;
InitializeComponent();
if (type == "Test")
{
wrongAnswerLabel.Content = "pytanie 1/10";
}
if (action.GetType() == typeof(Training))
{
previousQuestion.Visibility = Visibility.Hidden;
TestButton.Margin = new Thickness(0, 0, 0, 10);
}
else
{
previousQuestion.IsEnabled = false;
}
wordTrans = facade.getRandomTransWord(lang);
dificulty.generateAns(radios);
if (mode == "Polski->Obcy")
{
previousAnswers = dificulty.randomizeAnswers(radios, wordTrans, lang);
WordLabel.Content = wordTrans.wordPol.content;
action.actualWord = wordTrans;
}
else
{
previousAnswers = dificulty.randomizeAnswers(radios, wordTrans, "pol");
WordLabel.Content = wordTrans.content;
action.actualWord = wordTrans;
}
}
private void TestButton_Click(object sender, RoutedEventArgs e)
{
if (action.GetType() != typeof(Training))
{
test = (Test)action;
}
if(mode == "Polski->Obcy")
{
action.Stud(radios, dificulty, wordTrans.lang,previousAnswers);
previousAnswers = action.answers;
}
else
{
action.Stud(radios, dificulty, "pol",previousAnswers);
previousAnswers = action.answers;
}
if (action.GetType() != typeof(Training))
{
caretaker = new Caretaker();
caretaker.Memento = test.question.CreateMemento();
}
previousQuestion.IsEnabled = true;
}
private void GoBackButton_Click(object sender, RoutedEventArgs e)
{
NavigationService.GoBack();
}
private void previousQuestion_Click(object sender, RoutedEventArgs e)
{
test.question.RestoreMemento(caretaker.Memento);
action.actualWord = (WordTrans)test.question.Word;
if (mode == "Polski->Obcy")
{
WordLabel.Content = action.actualWord.wordPol.content;
}
else
{
WordLabel.Content = action.actualWord.content;
}
test.score = test.question.Score;
test.counter = test.question.Counter;
if(dificulty.strategy.GetType() != typeof(Master))
{
for (int i = 0; i < test.question.Answers.Count; i++)
{
radios.Children.OfType<RadioButton>().ElementAt(i).Content = test.question.Answers[i];
}
previousAnswers = test.question.Answers;
}
previousQuestion.IsEnabled = false;
wrongAnswerLabel.Content = "pytanie " + (test.question.Counter + 1) + "/10";
}
}
}