Bonjour,
j'ai comme projet professionnel, développer une application dans le style de trivial poursuite. Au fur est à mesure je rencontre plusieurs problèmes.
Dans les exigences, mon programme doit lire les questions depuis un fichier et les afficher. Jusqu'ici tout va bien.
Voici le problème: Lorsque l'événement click de mon button s'effectue le programme doit lire une ligne de mon fichier texte et l'afficher et ceci a chaque clique. Ex:
- Clique 1, lire et affiche ligne 1 du fichier
- Clique 2, lire et affiche ligne 2 du fichier
Print screen de ma form(histoire de visualiser la chose):
FormScreen | Flickr - Photo Sharing!@@AMEPARAM@@http://farm7.static.flickr.com/6229/6247436537_25e53097c5_m.jpg@@AMEPARAM@@6247436537@@AMEPARAM@@25e53097c5
Voici mon code(veuillez-m'excuser mais je préfère vous mettre la totalité de mon code afin que vous compreniez mieu mon problème):
Merci de m'éclairer, avant que je m'arrache la totalité de mes cheveux.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public partial class Form1 : Form { List<Question> LeQuizz = new List<Question>(); // String const string PicCorrecte = "c:\\303\\Image\\Juste.gif"; // Image correcte const string PicIncorrecte = "c:\\303\\Image\\Faux.gif"; // Image fausse const int Point = 0; // Point du joueur // Integer int QuestionCourante = 0; // DateTime DateTime TempsUtil = DateTime.Now; // Temps du joueur public Form1() { InitializeComponent(); } private void LireEtChargerQuestion() // Lire dans un fichier les questions et les charger dans le formulaire. { string ligne = null; string ID; string Cat; string Question; string choix1; string choix2; string choix3; string réponse; string bonneréponse; StreamReader R = new StreamReader("C:\\303\\QUIZZ.txt"); ligne = R.ReadLine(); // ligne lue string[] Tab = ligne.Split('\t'); // Désassemble la ligne avec comme référence TAB ID = Tab[0]; Cat = Tab[1]; Question = Tab[2]; choix1 = Tab[3]; choix2 = Tab[4]; choix3 = Tab[5]; réponse = Tab[6]; bonneréponse = Tab[7]; LeQuizz.Add(new Question(int.Parse(ID), Cat.ToString(), Question.ToString(), choix1.ToString(), choix2.ToString(), choix3.ToString(), int.Parse(réponse), int.Parse(bonneréponse))); lblNumQuestion.Text = "Question numéro " + (QuestionCourante + 1).ToString() + " (" + LeQuizz[QuestionCourante].Cat.ToString() + ")"; lblEnoncé.Text = LeQuizz[QuestionCourante].Enoncé; optR1.Text = LeQuizz[QuestionCourante].Choix1; optR2.Text = LeQuizz[QuestionCourante].Choix2; optR3.Text = LeQuizz[QuestionCourante].Choix3; optR1.Checked = false; optR2.Checked = false; optR3.Checked = false; QuestionCourante++; } private void Form1_Load(object sender, EventArgs e) { LireEtChargerQuestion(); } private void cmdNext_Click(object sender, EventArgs e) { if (QuestionCourante >= LeQuizz.Count) { MessageBox.Show("Y'a plus"); StreamWriter F = new StreamWriter("C:\\303\\Resultat.txt"); F.WriteLine("Ce bozo n'a fait qu'un point"); F.Close(); } else LireEtChargerQuestion(); } }
Bonne soirée et merci d'avance.
Partager