-
Notifications
You must be signed in to change notification settings - Fork 0
/
Questions.cs
80 lines (71 loc) · 2.46 KB
/
Questions.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
// ReSharper disable All
namespace Quiz
{
public class Questions
{
public string Question { get; }
public string? Response { get; }
public Dictionary<int, string>? MultipleResponse { get; }
public int GoodResponse { get; }
public Questions(string question, Dictionary<int, string> response, int good)
{
this.Question = question;
this.MultipleResponse = response;
this.GoodResponse = good;
}
public Questions(string question, string response)
{
this.Question = question;
this.Response = response;
this.GoodResponse = -1;
}
public static bool AskQuestions(Questions qu)
{
Console.WriteLine(qu.Question);
var resp = Console.ReadLine()?.Trim();
if (resp == null)
{
throw new Exception("erreur d'entrée");
}
if (resp == qu.Response)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Vrai");
Console.ResetColor();
return true;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Faux");
Console.WriteLine(qu.Question + $"\n La réponse est {qu.Response}");
Console.ResetColor();
return false;
}
public static bool AskQcm(Questions qu)
{
Console.WriteLine(qu.Question);
foreach (var re in qu.MultipleResponse!)
{
Console.WriteLine($"{re.Key}: {re.Value}");
}
Console.WriteLine("Veuillez répondre avec le numéro de la réponse");
var resp = Console.ReadLine()?.Trim();
if (resp == null)
{
throw new Exception("erreur d'entrée");
}
var number = resp.ToCharArray()[0] - '0';
if (number == qu.GoodResponse)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Vrai");
Console.ResetColor();
return true;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Faux");
Console.WriteLine(qu.Question + $"\n La réponse est {qu.MultipleResponse[qu.GoodResponse]}");
Console.ResetColor();
return false;
}
}
}