-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quiz.cs
172 lines (153 loc) · 5.61 KB
/
Quiz.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
using System.Collections;
namespace PersonalityQuizTelegram
{
public class PersonalityQuiz
{
public PersonalityQuiz(Question[] questions, Result[] results)
{
if (questions == null || results == null)
{
throw new ArgumentNullException(nameof(questions));
}
this.Questions = questions;
this.Results = results;
}
public Question[]? Questions { get; set; }
public Result[]? Results { get; set; }
public Result? CalculateResult(int[] selections)
{
Hashtable resultsTally = new();
foreach (Result result in this.Results)
{
resultsTally.Add(result.Name, 0);
}
int i = 0;
foreach (Question question in this.Questions)
{
foreach (DictionaryEntry pointValue in question.Answers[selections[i]].Points)
{
int value = (int)(long)pointValue.Value;
int ogvalue = (int)resultsTally[pointValue.Key];
int v = value + ogvalue;
resultsTally[pointValue.Key] = v;
}
i++;
}
return totalResult(resultsTally);
}
public Result? CalculateResult(string[] selections)
{
Hashtable resultsTally = new();
foreach (Result result in this.Results)
{
resultsTally.Add(result.Name, 0);
}
int i = 0;
foreach (Question question in this.Questions)
{
foreach (Answer answer in question.Answers)
{
if (selections[i].Equals(answer.AnswerField))
{
foreach (DictionaryEntry pointValue in answer.Points)
{
int v = (int)(long)pointValue.Value + (int)(long)resultsTally[pointValue.Key];
resultsTally[pointValue.Key] = v;
}
}
}
i++;
}
return totalResult(resultsTally);
}
private Result totalResult(Hashtable resultsTally) {
string finalKey = "";
int finalValue = 0;
foreach (DictionaryEntry result in resultsTally)
{
Console.WriteLine(result.Key.ToString() + " " + result.Value.ToString());
if ((int)result.Value > finalValue)
{
finalKey = (string)result.Key;
finalValue = (int)result.Value;
}
}
foreach (Result result in Results)
{
if (finalKey.Equals(result.Name))
{
return result;
}
}
return null;
}
public static PersonalityQuiz GetPreGenQuiz()
{
Result[]
results = {
new Result("Darth Vader", "He breath funny he a bit evil but not all the way", "https://upload.wikimedia.org/wikipedia/en/0/0b/Darth_Vader_in_The_Empire_Strikes_Back.jpg"),
new Result("Luke Skywalker", "No hand :( but he fly x wing good", "https://i.redd.it/x7f4u19956e41.jpg"),
new Result("Yoda", "Tiny Green Dude he hit with stick", "https://static.wikia.nocookie.net/starwars/images/d/d6/Yoda_SWSB.png/revision/latest/scale-to-width-down/1000?cb=20150206140125")
};
Hashtable points1 = new();
points1.Add("Yoda", 10);
Hashtable points2 = new();
points2.Add("Luke Skywalker", 10);
points2.Add("Darth Vader", 10);
Hashtable points3 = new();
points3.Add("Yoda", 10);
points3.Add("Luke Skywalker", 10);
Hashtable points4 = new();
points4.Add("Darth Vader", 10);
Answer[] answers1 =
{
new Answer("yes",points1),
new Answer("no",points2)
};
Answer[] answers2 =
{
new Answer("yes",points3),
new Answer("no",points4)
};
Question[] questions =
{
new Question("Are you short?",answers1),
new Question("Are you a Jedi Master?",answers2)
};
PersonalityQuiz quiz = new(questions, results);
return quiz;
}
}
public class Question
{
public Question(string questionField, Answer[] answers)
{
this.QuestionField = questionField;
this.Answers = answers;
}
public string? QuestionField { get; set; }
public Answer[]? Answers { get; set; }
}
public class Result
{
public Result(string name, string description, string imageurl)
{
this.Name = name;
this.Description = description;
this.Imageurl = imageurl;
}
public string? Name { get; set; }
public string? Description { get; set; }
public string? Imageurl { get; set; }
}
public class Answer
{
public Answer(string answerField, Hashtable points)
{
this.AnswerField = answerField;
this.Points = points;
}
public string? AnswerField { get; set; }
public Hashtable? Points { get; set; }
}
}