-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFenetreChoix.java
More file actions
335 lines (278 loc) · 10.4 KB
/
FenetreChoix.java
File metadata and controls
335 lines (278 loc) · 10.4 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import javax.swing.*; //fenêtre
import java.awt.*; //couleur
import java.awt.event.*; //événements
import java.io.*; //images
import javax.imageio.*; //BufferedImage
/**
* \class FenetreChoix : fenêtre permettant de choisir le robot avec lequel l'utilisateur veut jouer
*/
public class FenetreChoix extends JFrame implements ActionListener{ //fenêtre du choix du rover
//<!rover Andie
private Rover Andie;
//<!rover Marjorie
private Rover Marjorie;
//<!rover Maël
private Rover Mael;
//<!rover Florent
private Rover Florent;
//<!rover Janelle
private Rover Janelle;
//<!bouton de choix sur lequel l'utilisateur appuie pour commencer le jeu
private JButton Choisir;
//<!bouton sélection du robot Andie
private JButton Didi;
//<!bouton sélection du robot Marjorie
private JButton Marjo;
//<!bouton sélection du robot Maël
private JButton Mama;
//<!bouton sélection du robot Florent
private JButton Floflo;
//<!bouton sélection du robot Janelle
private JButton Jaja;
//<!bouton permettant de couper le son
private JButton Son;
//<!booléen permettant de savoir si le son est activé ou non
private boolean audioOn;
//<!zone de fond bleu à droite de la fenêtre
private JPanel Fond2;
//<!zone de texte où l'on va afficher la description de chaque robot
private JTextArea Texte;
//<!rover choisi
private Rover roverChoisi;
//<!fond sonore
private Audio a = new Audio("audio/choixRover.wav");
//<!son du bouton de sélection de chaque rover
private Audio aChoix = new Audio("audio/boutonSelection.wav");
//<!son du bouton choix si aucun rover sélectionné
private Audio erreurChoix = new Audio("audio/erreurChoix.wav");
//<!son du bouton choix si un rover a été sélectionné
private Audio aStart = new Audio("audio/bouton.wav");
/**
* \fn FenetreChoix(boolean b) : constructeur FenetreChoix
*
* @param boolean b : booléen indiquant si le son était allumé ou non dans la fenêtre start
*/
public FenetreChoix (boolean b, JFrame fenetreParent) throws IOException{
audioOn=b;
//initialisation de la fenêtre
this.setTitle("Choix du Rover");
this.setSize(1000,1000);
// Positionner la nouvelle fenêtre à l'emplacement de la fenêtre parent
this.setLocationRelativeTo(fenetreParent);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//initialisation des composants
JPanel Fond = new JPanel();
Fond.setLayout(null);
Fond.setBounds(0,0,1000,1000);
Fond.setBackground(Color.white);
this.add(Fond);
JLabel Titre = new JLabel ("SELECTION DU ROVER:");
Titre.setLayout(null);
Titre.setBounds(10,0,400,100);
Titre.setFont(new Font("Agency FB",Font.BOLD,25));
Titre.setForeground(new Color(249,200,93));
Fond.add(Titre);
JLabel NomJeu = new JLabel ("PERSEVERANCE");
NomJeu.setLayout(null);
NomJeu.setBounds(730,10,270,100);
NomJeu.setFont(new Font("Agency FB",Font.BOLD,45));
NomJeu.setForeground(new Color(249,200,93));
Fond.add(NomJeu);
JLabel A = new JLabel(new ImageIcon("images/Andie200.png"));
A.setBounds(100,90,200,200);
Fond.add(A);
JLabel B = new JLabel(new ImageIcon("images/Marjo200.png"));
B.setBounds(400,90,200,200);
Fond.add(B);
JLabel C = new JLabel(new ImageIcon("images/Florent200.png"));
C.setBounds(100,390,200,200);
Fond.add(C);
JLabel D = new JLabel(new ImageIcon("images/Mael200.png"));
D.setBounds(400,390,200,200);
Fond.add(D);
JLabel E = new JLabel(new ImageIcon("images/Janelle200.png"));
E.setBounds(250,690,200,200);
Fond.add(E);
Didi = new JButton("Andie");
Didi.setLayout(null);
Didi.setBounds(100,305,200,50);
Didi.setBackground(new Color(219,190,242));
Didi.addActionListener(this);
Didi.setFont(new Font("Agency FB",Font.BOLD,25));
Fond.add(Didi);
Marjo = new JButton("Marjo");
Marjo.setLayout(null);
Marjo.setBounds(400,305,200,50);
Marjo.setBackground(new Color(242,190,214));
Marjo.addActionListener(this);
Marjo.setFont(new Font("Agency FB",Font.BOLD,25));
Fond.add(Marjo);
Mama= new JButton("Ma\u00ebl");
Mama.setLayout(null);
Mama.setBounds(400,605,200,50);
Mama.setBackground(new Color(251,236,225));
Mama.setFont(new Font("Agency FB",Font.BOLD,25));
Mama.addActionListener(this);
Fond.add(Mama);
Floflo = new JButton("Florent");
Floflo.setLayout(null);
Floflo.setBounds(100,605,200,50);
Floflo.setBackground(new Color(180,207,250));
Floflo.addActionListener(this);
Floflo.setFont(new Font("Agency FB",Font.BOLD,25));
Fond.add(Floflo);
Jaja = new JButton("Janelle");
Jaja.setLayout(null);
Jaja.setBounds(250,905,200,50);
Jaja.setBackground(new Color(247,198,197));
Jaja.addActionListener(this);
Jaja.setFont(new Font("Agency FB",Font.BOLD,25));
Fond.add(Jaja);
Choisir = new JButton("CHOISIR");
Choisir.setLayout(null);
Choisir.setBounds(725,800,250,100);
Choisir.setBackground(new Color(249,200,93));
Choisir.setForeground(new Color(52,62,162));
Choisir.addActionListener(this);
Choisir.setFont(new Font("Agency FB",Font.BOLD,35));
Fond.add(Choisir);
Texte = new JTextArea();
Texte.setEditable(false);
Texte.setLayout(null);
Texte.setBackground(new Color(52,62,162));
Texte.setForeground(new Color(249,200,93));
Texte.setFont(new Font("Agency FB",Font.BOLD,25));
Texte.setBounds(725,300,300,400);
Fond.add(Texte);
Fond2 = new JPanel();
Fond2.setLayout(null);
Fond2.setBounds(700,0,300,1000);
Fond2.setBackground(new Color(52,62,162));
Fond.add(Fond2);
Son = new JButton();
if(audioOn){
Son.setIcon(new ImageIcon("images/son on.png"));
}else{
Son.setIcon(new ImageIcon("images/son off.png"));
}
Son.setSize(50,50);
Son.setLocation(825,100);
Son.setBackground(new Color(52,62,162));
Son.addActionListener(this);
Fond.add(Son);
//initialisation des rovers
Andie = new Rover(ImageIO.read(new File("images/Andie.png")),"texte/Andie.txt");
Marjorie = new Rover(ImageIO.read(new File("images/Marjo.png")),"texte/Marjo.txt");
Mael = new Rover(ImageIO.read(new File("images/Mael.png")),"texte/Mael.txt");
Florent = new Rover(ImageIO.read(new File("images/Florent.png")),"texte/Florent.txt");
Janelle = new Rover(ImageIO.read(new File("images/Janelle.png")),"texte/Janelle.txt");
this.setVisible(true);
if(audioOn){
a.enBoucle(); //lecture du fond sonore
}
}
/**
* \fn void actionPerformed(ActionEvent e) : méthode permettant de lancer le jeu si
* l'utilisateur appuie sur le bouton de choix ou de couper le son si il appuie sur le bouton correspondant
*
* @param ActionEvent e : événement associé
*/
public void actionPerformed (ActionEvent e){
if(e.getSource()==Son){
if(audioOn){
a.arret();
audioOn=false;
Son.setIcon(new ImageIcon("images/son off.png"));
}else{
a.enBoucle();
audioOn=true;
Son.setIcon(new ImageIcon("images/son on.png"));
}
}
//le rover sélectionné est enregistré
if (e.getSource() == Didi){
Texte.repaint();
if(audioOn){
aChoix.lecture();
}
Texte.setText(readFile(Andie.description));
roverChoisi=Andie;
}
if (e.getSource() == Floflo){
Texte.repaint();
if(audioOn){
aChoix.lecture();
}
Texte.setText(readFile(Florent.description));
roverChoisi=Florent;
}
if (e.getSource() == Jaja){
Texte.repaint();
if(audioOn){
aChoix.lecture();
}
Texte.setText(readFile(Janelle.description));
roverChoisi=Janelle;
}
if (e.getSource() == Mama){
Texte.repaint();
if(audioOn){
aChoix.lecture();
}
Texte.setText(readFile(Mael.description));
roverChoisi=Mael;
}
if (e.getSource() == Marjo){
Texte.repaint();
if(audioOn){
aChoix.lecture();
}
Texte.setText(readFile(Marjorie.description));
roverChoisi=Marjorie;
}
//appui sur le bouton choisir
if(e.getSource()==Choisir){
if(roverChoisi!=null){ //si l'utilisateur a choisi un rover
try{
if(audioOn){
aStart.lecture(); //lecture du son du bouton start
a.arret();
}
new FenetreJeu(roverChoisi,audioOn, this); //création de la fenêtre principale de jeu
setVisible(false);
}catch(IOException exception){
}
}else{ //si l'utilisateur n'a choisi aucun rover
if(audioOn){
erreurChoix.lecture(); //son erreur
}
JOptionPane.showMessageDialog(this,"Veuillez s\u00e9lectionner un rover !"); //message d'erreur
}
}
}
/**
* \fn static String readFile(String chemin) : méthode permettant de convertir des fichiers texte en String en conservant la présentation du texte
*
* @param String chemin : localisation du fichier à convertir
*/
public static String readFile(String chemin) {
try{
InputStream flux= new FileInputStream(chemin);
InputStreamReader lecture= new InputStreamReader(flux,"UTF-8");
try (BufferedReader buff = new BufferedReader(lecture)) {
String ligne = "";
String contenu = "";
while ((ligne = buff.readLine()) != null){
contenu += ligne + "\n";
}
return contenu;
} catch (Exception e) {
System.out.println(e.toString());
}
} catch (IOException e){
System.out.println(e.toString());
}
return null;
}
}