Salut,
J'apprends le developpement en autodidacte depuis seulement 3 semaines et je suis entrain de faire mon tout premier programme ! Le kiff
Pour l'instant ce n'est qu'un quizz de questions aleatoires. Cependant je compte y ajouter et modifier beaucoup de choses. Je souhaite aussi apprendre de mes erreurs concernant la propreté de mon code. C'est pourquoi j'ai besoin de vous bien que ce que j'ai fait marche impec pour le moment.
Est-ce que des codeurs pro peuvent me dire ce que j'ai mal fait dans mon code ? Ce qui est mal optimisé et ce qui n'est pas conventionnel. (la liste risque d'être longue )
(Et si jamais j'ai fais quelque chose de bien pour mon niveau n'hesitez pas a me le dire ça sera motivant.)
Avant toute chose 2-3 precisions sur ce que je compte rajouter par la suite (comme ça vous pourrez me dire si je suis parti sur des bonnes bases ou si je risque d'être emmerder par la suite):
_ Remplacer le tableau tableauQuestionsReponses par une BDD SQL (quand j'aurais appris a me servir de cette dernière) et y ajouter des milliers de questions a savoir que les questions seront des phrases et que ça ne sera pas un quizz mathematique. la table des 7 ici présent n'est qu'un essai. (Ca explique pourquoi je l'ai declarer en String)
_ Faire un graphisme perso de la fenettre principale et des boutons.
_ Ajouter un systeme de point (chaque bonne reponse rapportant + ou - de points en fonction du nombre d'erreurs, du temps de reponse, etc)
_ Instaurer un classement en ligne.
_ Un systeme de "duel" 1 joueur contre 1 joueur en ligne. Ou même de matchs par equipe.
_ Modifier la randomisation des questions de maniere a ce que certaines questions aient + ou - de chances de resortir que d'autres selon les facilités/difficultés que l'utilisateur montre a repondre a ces questions (temps de réponse, fréquence des erreurs, etc ..)
Et encore quelques details qui ne valent pas trop la peine d'être cités.
Pis aussi surement d'autres idées qui me viendront par la suite.
Voila l'integralité de mon code:
Il y a 3 classes:
Main:
FenetrePrincipale:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 public class MainClass { public static void main(String[] args) { // TODO Auto-generated method stub FenetrePrincipale fenetrePrincipale = new FenetrePrincipale(); } }
Et Moteur:
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
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 import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class FenetrePrincipale { JFrame jframePrincipale = new JFrame(); JPanel jpanel0 = new JPanel(); JPanel jpanel0North = new JPanel(); JPanel jpanel0West = new JPanel(); JPanel jpanel0Center = new JPanel(); JPanel jpanel0East = new JPanel(); JPanel jpanel0South = new JPanel(); JPanel jpanelQuestion = new JPanel(); JPanel jpanelReponses = new JPanel(); JPanel jpanelCorrection = new JPanel(); public static JLabel labelQuestion = new JLabel(); public static JLabel labelCorrection = new JLabel(); public static JButton buttonReponse1 = new JButton(); public static JButton buttonReponse2 = new JButton(); public static JButton buttonReponse3 = new JButton(); public static JButton buttonReponse4 = new JButton(); public static JButton buttonReponse5 = new JButton(); public static JButton buttonReponse6 = new JButton(); static String currentText = ""; static String currentQuestion = ""; static String currentValidReponse = ""; FenetrePrincipale() { Moteur.randomQR(); jpanel0.setBackground(Color.BLUE); jpanel0.setLayout(new BorderLayout()); jpanel0.add(jpanel0Center, BorderLayout.CENTER); jpanel0.add(jpanel0North, BorderLayout.NORTH); jpanel0.add(jpanel0West, BorderLayout.WEST); jpanel0.add(jpanel0East, BorderLayout.EAST); jpanel0.add(jpanel0South, BorderLayout.SOUTH); jpanel0North.setPreferredSize(new Dimension(50, 50)); jpanel0West.setPreferredSize(new Dimension(50, 50)); jpanel0Center.setBackground(Color.RED); jpanel0Center.setLayout(new BorderLayout()); jpanel0Center.add(jpanelQuestion, BorderLayout.NORTH); jpanel0Center.add(jpanelReponses, BorderLayout.CENTER); jpanel0Center.add(jpanelCorrection, BorderLayout.SOUTH); jpanel0East.setPreferredSize(new Dimension(50, 50)); jpanel0South.setPreferredSize(new Dimension(50, 50)); jpanelQuestion.add(labelQuestion); jpanelQuestion.setPreferredSize(new Dimension(300, 100)); jpanelReponses.setLayout(new GridLayout(2, 3)); jpanelReponses.add(buttonReponse1); jpanelReponses.add(buttonReponse2); jpanelReponses.add(buttonReponse3); jpanelReponses.add(buttonReponse4); jpanelReponses.add(buttonReponse5); jpanelReponses.add(buttonReponse6); jpanelCorrection.add(labelCorrection); jpanelCorrection.setPreferredSize(new Dimension(300, 100)); labelQuestion.setFont(new Font("Arial", Font.PLAIN, 57)); labelCorrection.setFont(new Font("Arial", Font.PLAIN, 57)); // LISTENERS buttonReponse1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { currentText = buttonReponse1.getText(); Moteur.correction(); } }); buttonReponse2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { currentText = buttonReponse2.getText(); Moteur.correction(); } }); buttonReponse3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { currentText = buttonReponse3.getText(); Moteur.correction(); } }); buttonReponse4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { currentText = buttonReponse4.getText(); Moteur.correction(); } }); buttonReponse5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { currentText = buttonReponse5.getText(); Moteur.correction(); } }); buttonReponse6.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { currentText = buttonReponse6.getText(); Moteur.correction(); } }); jframePrincipale.add(jpanel0); jframePrincipale.setSize(700, 600); jframePrincipale.setMinimumSize(new Dimension(600,500)); jframePrincipale.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframePrincipale.setLocationRelativeTo(null); jframePrincipale.setVisible(true); } }
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 import java.util.Random; public class Moteur { static String[][] tableauQuestionsReponses = { {"0", "7 x 0", "0", ""}, {"1", "7 x 1", "7", ""}, {"2", "7 x 2", "14",""}, {"3", "7 x 3", "21",""}, {"4", "7 x 4", "28",""}, {"5", "7 x 5", "35",""}, {"6", "7 x 6", "42",""}, {"7", "7 x 7", "49",""}, {"8", "7 x 8", "56",""}, {"9", "7 x 9", "63",""}, {"10","7 x 10","70",""}, {"11","7 x 11","77",""} }; public static void randomQR() { Random rand = new Random(); int rand12Question = rand.nextInt(12); int rand6 = rand.nextInt(6); int[] rand12Reponses = { rand.nextInt(12), rand.nextInt(12), rand.nextInt(12), rand.nextInt(12), rand.nextInt(12), rand.nextInt(12) }; rand12Reponses[rand6] = rand12Question; String question = tableauQuestionsReponses[rand12Question][1]; String reponse1 = tableauQuestionsReponses[(rand12Reponses[0])][2]; String reponse2 = tableauQuestionsReponses[(rand12Reponses[1])][2]; String reponse3 = tableauQuestionsReponses[(rand12Reponses[2])][2]; String reponse4 = tableauQuestionsReponses[(rand12Reponses[3])][2]; String reponse5 = tableauQuestionsReponses[(rand12Reponses[4])][2]; String reponse6 = tableauQuestionsReponses[(rand12Reponses[5])][2]; FenetrePrincipale.labelQuestion.setText(question); FenetrePrincipale.buttonReponse1.setText(reponse1); FenetrePrincipale.buttonReponse2.setText(reponse2); FenetrePrincipale.buttonReponse3.setText(reponse3); FenetrePrincipale.buttonReponse4.setText(reponse4); FenetrePrincipale.buttonReponse5.setText(reponse5); FenetrePrincipale.buttonReponse6.setText(reponse6); FenetrePrincipale.currentValidReponse = tableauQuestionsReponses[rand12Question][2]; ; } public static void correction() { if (FenetrePrincipale.currentText.equals(FenetrePrincipale.currentValidReponse)) { FenetrePrincipale.labelCorrection.setText("<html><font color='green'>Correct !</font></html>"); randomQR(); } else if (FenetrePrincipale.currentText.equals("")) { } else FenetrePrincipale.labelCorrection.setText("<html><font color='red'>Incorrect :(</font></html>"); } }
Un grand Merci d'avance a ceux qui prendrons le temps de me corriger.
Partager