Bonjour, je suis nouveau sur le site et j'ai créé un programme dans mon cours de programmation et j'ai quelques problèmes avec le code. En gros, j'ai un petit jeu et il faut dire si les deux images sont pareilles ou pas pareilles. J'ai un random pour choisir une des 3 paires d'images et un autre pour choisir si l'image va être différente ou non(à chaque image choisie par le 1er random). Quand je clique sur le bouton jouer, une paire d'image apparaît, ensuite on dit si les 2 images sont pareilles et on clique sur le bouton prochaines images pour qu'il y ait d'autre images qui apparaissent, etc. Jusque la tout va bien mais quand on clique une 2e fois sur le bouton prochaines images les images restent les mêmes. Pourriez vous m'aider? Merci
Le bouton jouer :
Le bouton Prochaines cartes :
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 jButton1.setVisible(false); jButton2.setEnabled(true); jButton3.setEnabled(true); jButton5.setVisible(false); jLabel4.setText("Les images sont elles pareilles"); jLabel5.setText("ou différentes?"); Random carte1 = new Random(); int range = 3; int randomNum = carte1.nextInt(range) + 1; switch (randomNum) { case 1: image1 = true; image2 = false; image3 = false; Random cartea1 = new Random(); int rangea = 2; int randomNuma = cartea1.nextInt(rangea) + 1; ImageIcon imagea1 = new ImageIcon("src/dust21.png"); jLabel2.setIcon(imagea1); if (randomNuma == 1) { ImageIcon imagea2 = new ImageIcon("src/dust21.png"); jLabel3.setIcon(imagea2); vraia1 = true; b = 0; } else{ ImageIcon imagea2 = new ImageIcon("src/dust22.png"); jLabel3.setIcon(imagea2); vraia1 = true; b = 1; } break; case 2: image1 = false; image2 = true; image3 = false; Random carteb1 = new Random(); int rangeb = 2; int randomNumb = carteb1.nextInt(rangeb) + 1; ImageIcon imageb1 = new ImageIcon("src/train.png"); jLabel2.setIcon(imageb1); if (randomNumb == 1) { ImageIcon imageb2 = new ImageIcon("src/train.png"); jLabel3.setIcon(imageb2); vraia2 = true; b = 0; } else { ImageIcon imageb2 = new ImageIcon("src/Train1.png"); jLabel3.setIcon(imageb2); vraia2 = true; b = 1; } break; case 3: image1 = false; image2 = false; image3 = true; Random cartec1 = new Random(); int rangec = 2; int randomNumc = cartec1.nextInt(rangec) + 1; ImageIcon imagec1 = new ImageIcon("src/inferno1.png"); jLabel2.setIcon(imagec1); if (randomNumc == 1) { ImageIcon imagec2 = new ImageIcon("src/inferno1.png"); jLabel3.setIcon(imagec2); vraia3 = true; b = 0; } else { ImageIcon imagec2 = new ImageIcon("src/inferno2.png"); jLabel3.setIcon(imagec2); vraia3 = true; b = 1; } break; }
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 ImageIcon image = new ImageIcon(); jLabel6.setIcon(image); jLabel2.setIcon(image); jLabel3.setIcon(image); jLabel7.setVisible(false); jLabel8.setVisible(false); jLabel9.setVisible(false); if (vraia1 == true) { image1 = false; image2 = true; image3 = false; Random carteb1 = new Random(); int rangeb = 2; int randomNumb = carteb1.nextInt(rangeb) + 1; ImageIcon imageb1 = new ImageIcon("src/train.png"); jLabel2.setIcon(imageb1); if (randomNumb == 1) { ImageIcon imageb2 = new ImageIcon("src/train.png"); jLabel3.setIcon(imageb2); vraib1 = true; vraia1 = false; b = 0; } else { ImageIcon imageb2 = new ImageIcon("src/Train1.png"); jLabel3.setIcon(imageb2); vraib1 = true; vraia1 = false; b = 1; } } if (vraia2 = true) { Random cartec1 = new Random(); int rangec = 2; int randomNumc = cartec1.nextInt(rangec) + 1; ImageIcon imagec1 = new ImageIcon("src/inferno1.png"); jLabel2.setIcon(imagec1); if (randomNumc == 1) { ImageIcon imagec2 = new ImageIcon("src/inferno1.png"); jLabel3.setIcon(imagec2); vraib2 = true; vraia2 = false; b = 0; } else { ImageIcon imagec2 = new ImageIcon("src/inferno2.png"); jLabel3.setIcon(imagec2); vraib2 = true; vraia2 = false; b = 1; } } if (vraia3 = true) { image1 = true; image2 = false; image3 = false; Random cartea1 = new Random(); int rangea = 2; int randomNuma = cartea1.nextInt(rangea) + 1; ImageIcon imagea1 = new ImageIcon("src/dust21.png"); jLabel2.setIcon(imagea1); if (randomNuma == 1) { ImageIcon imagea2 = new ImageIcon("src/dust21.png"); jLabel3.setIcon(imagea2); vraib3 = true; vraia3 = false; b = 0; } else{ ImageIcon imagea2 = new ImageIcon("src/dust22.png"); jLabel3.setIcon(imagea2); vraib3 = true; vraia3 = false; b = 1; } } if (vraib1 == true) { Random cartec1 = new Random(); int rangec = 2; int randomNumc = cartec1.nextInt(rangec) + 1; ImageIcon imagec1 = new ImageIcon("src/inferno1.png"); jLabel2.setIcon(imagec1); if (randomNumc == 1) { ImageIcon imagec2 = new ImageIcon("src/inferno1.png"); jLabel3.setIcon(imagec2); vraib1 = false; b = 0; } else { ImageIcon imagec2 = new ImageIcon("src/inferno2.png"); jLabel3.setIcon(imagec2); vraib1 = false; b = 1; } } if (vraib2 == true) { image1 = true; image2 = false; image3 = false; Random cartea1 = new Random(); int rangea = 2; int randomNuma = cartea1.nextInt(rangea) + 1; ImageIcon imagea1 = new ImageIcon("src/dust21.png"); jLabel2.setIcon(imagea1); if (randomNuma == 1) { ImageIcon imagea2 = new ImageIcon("src/dust21.png"); jLabel3.setIcon(imagea2); vraib2 = false; b = 0; } else{ ImageIcon imagea2 = new ImageIcon("src/dust22.png"); jLabel3.setIcon(imagea2); vraib2 = false; b = 1; } } if (vraib3 == true) { image1 = false; image2 = true; image3 = false; Random carteb1 = new Random(); int rangeb = 2; int randomNumb = carteb1.nextInt(rangeb) + 1; ImageIcon imageb1 = new ImageIcon("src/train.png"); jLabel2.setIcon(imageb1); if (randomNumb == 1) { ImageIcon imageb2 = new ImageIcon("src/train.png"); jLabel3.setIcon(imageb2); vraib3 = false; b = 0; } else { ImageIcon imageb2 = new ImageIcon("src/Train1.png"); jLabel3.setIcon(imageb2); vraib3 = false; b = 1; } }
Partager