rahh je commence à désespérer...
Même en changeant le nom de le méthode ca ne marche pas (même erreur)
je pense avoir compris l'histoire du static. Un variable static est la même pour toutes les instances d'un objet.
Mais la question ne devrait pas trop se poser vu qu'on utilise une seule instance des objets.
je poste l'intégralité du code source...
BlackJack.java
gui :
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
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386 ////////////////////////////////////////// // Jeu de BlackJack // // // // Kuhn Alexandre // // Shaame Shaban // // Hausmann Jody // ////////////////////////////////////////// import classe.*; import java.io.*; import GUI.gui; public class BlackJack { public joueur j1; public deck deck_init; public jeu tour; public boolean blackj = false; public BlackJack bj ; public static void main(String arg[] )throws IOException { BlackJack bj = new BlackJack(); } public String message( int id) { String mess = ""; switch(id) { case 1: { mess = "Voulez-vous faire une nouvelle partie ? (1/oui 2/non)"; break; } case 2: { mess = "Veuillez entrer un mise pour ce tour"; break; } case 3: { mess = "Votre mise est trop grande, veuillez entrer une nouvelle mise"; break; } case 4: { mess = "BlackJack !!!!!!!!!!!"; break; } case 5: { mess = "Pour prendre une carte : (1) Pour rester : (2)"; break; } case 6: { mess = "Score : Joueur " + tour.affichescorej() + " Banque " + tour.affichescoreb() ; break; } case 7: { mess = "La banque gagne ! Vous perdez votre mise de: " + j1.affichemisetour() ; break; } case 8: { mess = "Vous gagnez la somme de: " + j1.affichemisetour() ; break; } case 9: { mess = "Egalité, vous récuperez votre mise de: " + j1.affichemisetour() ; break; } case 10: { mess = "Vos gains s'élève à " + j1.affichemise() ; break; } case 11: { mess = "Votre mise est doublée : " + j1.affichemisetour()*2; break; } case 12: { mess = "Vous avez tous perdu! Nouvelle partie? (1/oui 2/non) "; break; } } return mess; } public void game()throws IOException { BufferedReader LineInput = new BufferedReader(new InputStreamReader(System.in)); //début jeu //création carte deck_init = new deck(); deck_init.tricarte();//tri du deck blackj = false; //création jeu tour = new jeu(); //lancement tour int id = 2, repmise ,carte ; String questmise; boolean contmise = false; while(contmise == false) { //demande de mise System.out.println(); System.out.println( message(id) ); //shaban lecture de la mise while(gui.b < 1) { } System.out.println("variable de gui "+gui.b); int mise = gui.getmise() ; //repmise = Integer.parseInt(questmise); //enregistrementmise et controle mise //contmise = j1.controlemise(mise); //j1.misejeu(mise); id = 3; } //distribution des cartes carte = deck_init.donne(); tour.jeuj( carte , deck_init.valcarte(carte) ); //1ere carte joueur carte = deck_init.donne(); tour.jeub( carte , deck_init.valcarte(carte) ); //1ere carte banque carte = deck_init.donne(); tour.jeuj( carte , deck_init.valcarte(carte) ); //2eme carte joueur //affichage carte System.out.println(); System.out.println("Carte de la Banque: " + deck_init.nomcarte( tour.lecturejeub(0) ) ); System.out.println(); System.out.println("1ere carte du joueur: " + deck_init.nomcarte( tour.lecturejeuj(0) )); System.out.println("2eme carte du joueur: " + deck_init.nomcarte( tour.lecturejeuj(1) )); //affiche valeur tour.calculscorej(); tour.calculscoreb(); if(tour.affichescorej() > 21) { tour.convertiASj(); } System.out.println(); System.out.println(message(6) ); //proposition if (tour.affichescorej() != 21) { proposition(); if(tour.affichescorej() < 22) { banque(); } } else { blackj = true; System.out.println(); System.out.println(message(4)); } resultat(); } public void proposition()throws IOException { BufferedReader LineInput = new BufferedReader(new InputStreamReader(System.in)); String question; int rep, carte, next = 2; boolean d = true; while(d) { //selon score if ( tour.affichescorej() == 21) { d = false; System.out.println(); System.out.println(message(6) ); } if(tour.affichescorej() > 21 ) { if(tour.detectASj() == true) { tour.convertiASj(); System.out.println(); System.out.println(message(6) ); } else { System.out.println(); System.out.println(message(6) ); d = false; } } if ( tour.affichescorej() < 21) { System.out.println(); System.out.println(message(5)); question = LineInput.readLine(); rep = Integer.parseInt(question); if(rep == 1 || rep == 2) { switch(rep) { case 1: { //tire une carte carte = deck_init.donne(); tour.jeuj( carte , deck_init.valcarte(carte) ); System.out.println(); System.out.println("Carte suivante joueur: " + deck_init.nomcarte( tour.lecturejeuj(next) ) ); next++; tour.calculscorej(); if ( tour.affichescorej() < 22) { System.out.println(); System.out.println(message(6) ); } break; } case 2: { //stand d = false; break; } } } } } } public void banque() { int carte, next =1; System.out.println(); System.out.println("Tour de la banque"); while (tour.affichescoreb() < 17) { carte = deck_init.donne(); tour.jeub( carte , deck_init.valcarte(carte) ); System.out.println(); System.out.println("Carte suivante banque: " + deck_init.nomcarte( tour.lecturejeub(next) ) ); next++; tour.calculscoreb(); if ( tour.affichescoreb() > 21) { tour.convertiASb(); } } System.out.println(); System.out.println(message(6) ); } public void resultat() { if ( tour.affichescorej() < 22 && blackj == false) { if ( tour.affichescoreb() < 22) { if(tour.affichescorej() < tour.affichescoreb())//perd { System.out.println(); System.out.println(message(7)); j1.miseperd(j1.affichemisetour()); } if(tour.affichescorej() > tour.affichescoreb())//gagne { System.out.println(); System.out.println(message(8)); j1.misegagne(j1.affichemisetour()); } if( tour.affichescorej() == tour.affichescoreb())//egalité { System.out.println(); System.out.println(message(9)); } } if ( tour.affichescoreb() > 21)//banque perd { System.out.println(); System.out.println(message(8)); j1.misegagne(j1.affichemisetour()); } } if ( tour.affichescorej() > 21)//explose 21 { System.out.println(); System.out.println(message(7)); j1.miseperd(j1.affichemisetour()); } if(blackj == true)//blackjack { System.out.println(); System.out.println(message(11)); j1.misegagne(2*j1.affichemisetour()); } System.out.println(message(10)); } public void BlackJack() throws IOException{ BufferedReader LineInput = new BufferedReader(new InputStreamReader(System. in)); //initialisation du jeu //création joueur j1 = new joueur("j1"); //affiche mise de départ System.out.println(message(10)); //lancement du jeu //modification GUI gui gui = new gui(); boolean gamecontinu = true; while (gamecontinu) { if (j1.affichemise() == 0) { System.out.println(); System.out.println(message(12)); //String ques = LineInput.readLine(); //obtenir les réponses par l'interface while (gui.b < 1) { } System.out.println("variable de gui " + gui.b); //int rep = Integer.parseInt(ques); if (gui.b == 1) { j1 = new joueur("j1"); //affiche mise de départ System.out.println(message(10)); bj.game(); } else { gamecontinu = false; } //on remet le bouton hit a son stade ini gui.b = 0; } bj.game(); System.out.println(message(1)); String question = LineInput.readLine(); int reponse = Integer.parseInt(question); if (reponse == 2) { gamecontinu = false; } } } }
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 package GUI; import javax.swing.*; /** * <p>Titre : </p> * * <p>Description : </p> * * <p>Copyright : Copyright (c) 2006</p> * * <p>Société : </p> * * @author non attribuable * @version 1.0 */ /** * <p>Titre : </p> * * <p>Description : </p> * * <p>Copyright : Copyright (c) 2006</p> * * <p>Société : </p> * * @author non attribuable * @version 1.0 */ import java.awt.BorderLayout; import java.awt.event.MouseEvent; import java.awt.event.MouseAdapter; import com.borland.jbcl.layout.XYLayout; import com.borland.jbcl.layout.*; import java.awt.Color; import java.awt.Dimension; public class gui extends JFrame { public static int b = 0; public gui() { try { jbInit(); } catch (Exception ex) { ex.printStackTrace(); } // this.show(); } public void main(String arg[] ) { //modification GUI gui gui =new gui(); } public void jbInit() throws Exception { jPanel1.setLayout(xYLayout1); jLabel1.setIcon(new ImageIcon(new java.net.URL("file:///C:/jasblackjack/titre.gif"))); jPanel1.setBackground(Color.white); jPanel1.setMinimumSize(new Dimension(640, 480)); jToggleButton1.addMouseListener(new uneinterf_jToggleButton1_mouseAdapter(this)); jLabel2.setIcon(new ImageIcon(new java.net.URL("file:///C:/jasblackjack/tapis.jpg"))); carte1.setIcon(new ImageIcon(new java.net.URL("cartes/coeur/simple_d_2.png"))); jButton1.setText("Stand"); this.setTitle("SJA BlackJack"); this.setBounds(0,0,640,510); jLabel4.setText("Votre mise :"); jLabel5.setText("Votre avoir :"); editAvoir.setText("jTextField1"); jButton2.setText("Valider"); jLabel3.setText("jLabel3"); jPanel1.add(jLabel1, new XYConstraints(2, 1, -1, -1)); jPanel1.add(jLabel2, new XYConstraints(17, 101, -1, -1)); jPanel1.add(carte1, new XYConstraints(17, 151, -1, -1)); jPanel1.add(jToggleButton1, new XYConstraints(93, 425, -1, -1)); jPanel1.add(jButton1, new XYConstraints(217, 425, -1, -1)); jPanel1.add(jLabel4, new XYConstraints(408, 114, -1, -1)); jPanel1.add(jLabel5, new XYConstraints(408, 169, -1, -1)); jPanel1.add(jSpinner1, new XYConstraints(407, 130, 75, -1)); jPanel1.add(editAvoir, new XYConstraints(407, 191, 75, -1)); jPanel1.add(jButton2, new XYConstraints(407, 368, -1, -1)); jPanel1.add(jLabel3, new XYConstraints(386, 253, -1, -1)); this.getContentPane().add(jPanel1, java.awt.BorderLayout.EAST); jToggleButton1.setText("Hit"); } JPanel jPanel1 = new JPanel(); JToggleButton jToggleButton1 = new JToggleButton(); XYLayout xYLayout1 = new XYLayout(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JLabel carte1 = new JLabel(); JButton jButton1 = new JButton(); JSpinner jSpinner1 = new JSpinner(); JLabel jLabel4 = new JLabel(); JLabel jLabel5 = new JLabel(); JTextField editAvoir = new JTextField(); JButton jButton2 = new JButton(); JLabel jLabel3 = new JLabel(); public void jToggleButton1_mouseClicked(MouseEvent e) { this.b = 1; System.out.println("bouton hit appuyé"); } //fonctions de controles public void DefinirAvoir(String Newavoir) { this.editAvoir.setText(Newavoir); } public int getmise() { String stmise ; stmise = (String) this.jSpinner1.getValue(); int mise = Integer.parseInt(stmise); return mise; } } class uneinterf_jToggleButton1_mouseAdapter extends MouseAdapter { private gui adaptee; uneinterf_jToggleButton1_mouseAdapter(gui adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jToggleButton1_mouseClicked(e); } }
Partager