-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
115 lines (106 loc) · 3.96 KB
/
Program.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
// ReSharper disable All
namespace Quiz
{
class Quiz
{
static async Task Main()
{
var questionsFile = "../../../questions.txt";
List<Questions>? questionsList = null;
try
{
questionsList = QuestionManager.LoadQuestions(questionsFile);
if (questionsList == null) throw new ArgumentNullException("Le fichier est vide");
}
catch (System.IO.FileNotFoundException)
{
Console.WriteLine("Fichier non trouvé!");
}
catch (System.UnauthorizedAccessException)
{
Console.WriteLine("Impossible d'accéder au fichiers, manque de permissions!");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
await menu(questionsList,questionsFile);
}
private static void StartQuiz(List<Questions>? questionsList)
{
var res = 0;
foreach (var qu in questionsList)
{
if (qu.Response != null)
{
res += Questions.AskQuestions(qu) ? 1 : 0 ;
}
else
{
res += Questions.AskQcm(qu) ? 1 : 0 ;
}
}
Console.WriteLine($"vous avez eu {res} bonne réponses sur {questionsList.Count} !");
}
private static async Task menu(List<Questions>? questionsList,string questionsFile)
{
Console.WriteLine("1: Administration\n" +
"2: Lancer le quiz\n" +
"3: Quitter le programme\n" +
"(veuillez répondre avec le numéro)");
switch (Console.ReadLine()?.Trim())
{
case null:
Console.WriteLine("Erreur stdin fermé");
Environment.Exit(-1);
break;
case "1":
Console.WriteLine("Taper le mot de passe administrateur");
var password = Console.ReadLine();
if (password == null)
{
Console.WriteLine("Erreur stdin fermé");
System.Environment.Exit(-1);
}
QuestionManager? questionManager = null;
try
{
questionManager = QuestionManager.AdminLogin(password, questionsList, questionsFile);
}
catch (ArgumentException e)
{
Console.WriteLine(e.Message);
Environment.Exit(-2);
}
Console.WriteLine("1: Ajouter une question\n" +
"2: Supprimer une question\n" +
"3: Retour en arrière");
var chose = Console.ReadLine();
if (password == null)
{
Console.WriteLine("Erreur stdin fermé");
System.Environment.Exit(-1);
}
switch (chose)
{
case "1":
questionManager?.AddQestion();
break;
case "2":
await questionManager?.DeleteQuestion()!;
break;
case "3":
await menu(questionsList,questionsFile);
break;
}
break;
case "2":
StartQuiz(questionsList);
break;
case "3":
Environment.Exit(0);
break;
}
}
}
}