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
| package test;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
public class Panneau extends JPanel {
public int posX1 = 90;
public int posY1 = 70;
public int posX2 = 90;
public int posY2 = 70;
public void paintComponent(Graphics g){
//On choisit une couleur de fond pour le rectangle
g.setColor(Color.white);
//On le dessine de sorte qu'il occupe toute la surface
try {
Image img = ImageIO.read(new File("Plateau-jeu.PNG"));
//g.drawImage(img, 0, 0, this);
//Pour une image de fond
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
} catch (IOException e) {
e.printStackTrace();
}
//On redéfinit une couleur pour le rond
//g.setColor(Color.red);
//On le dessine aux coordonnées souhaitées
//g.fillOval(posX, posY, 50, 50);
g.setColor(Color.blue);
g.fillOval(posX1, posY1, 50, 50);
//g.setColor(Color.red);
//g.fillOval(posX2, posY2, 50, 50);
int de = 0;
de = 1 + (int)(Math.random() * 6 );
g.setColor(Color.green);
g.fillOval(90+70*de, 70, 50, 50);
g.setColor(Color.red);
g.drawString("Résultat du dé",620,50);
if (de == 1 ){
System.out.println( "vous avez obtenu un 1");
try {
Image img = ImageIO.read(new File("dé1.PNG"));
g.drawImage(img, 650, 0, this);
//Pour une image de fond
//g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
} catch (IOException e) {
e.printStackTrace();
}}
if (de == 2 ){
System.out.println( "vous avez obtenu un 2");
try {
Image img = ImageIO.read(new File("dé2.PNG"));
g.drawImage(img, 650, 0, this);
//Pour une image de fond
//g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
} catch (IOException e) {
e.printStackTrace();
}}
if (de == 3 ){
System.out.println( "vous avez obtenu un 3");
try {
Image img = ImageIO.read(new File("dé3.PNG"));
g.drawImage(img, 650, 0, this);
//Pour une image de fond
//g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
} catch (IOException e) {
e.printStackTrace();
}}
if (de == 4 ){
System.out.println( "vous avez obtenu un 4");
try {
Image img = ImageIO.read(new File("dé4.PNG"));
g.drawImage(img, 650, 0, this);
//Pour une image de fond
//g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
} catch (IOException e) {
e.printStackTrace();
}}
if (de == 5 ){
System.out.println( "vous avez obtenu un 5");
try {
Image img = ImageIO.read(new File("dé5.PNG"));
g.drawImage(img, 650, 0, this);
//Pour une image de fond
//g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
} catch (IOException e) {
e.printStackTrace();
}}
if (de == 6 ){
System.out.println( "vous avez obtenu un 6");
try {
Image img = ImageIO.read(new File("dé6.PNG"));
g.drawImage(img, 650, 0, this);
//Pour une image de fond
//g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
} catch (IOException e) {
e.printStackTrace();
}}
}
public int getPosX1() {
return posX1;
}
public void setPosX1(int posX1) {
this.posX1 = posX1;
}
public int getPosY1() {
return posY1;
}
public void setPosY1(int posY1) {
this.posY1 = posY1;
}
public int getPosX2() {
return posX2;
}
public void setPosX2(int posX2) {
this.posX2 = posX2;
}
public int getPosY2() {
return posY2;
}
public void setPosY2(int posY2) {
this.posY2 = posY2;
}
public void avancement1 (int x, int y, int de){
while (de>0){
if (x==160 && y==520){
de = 0;
}
if (y==520){
x=x-70;
}
if (x==720 && y==445 || x==720 && y==370){
y=y+75;
}
if (y==370){
x=x+70;
}
if (x==90 && y==295 || x==90 && y==220){
y=y+75;
}
if (y==220){
x=x-70;
}
if (x==720 && y==145 || x==720 && y==70){
y=y+75;
}
if (y==70){
x=x+70;
}
// case Oups
if (x==440 && y==520 || x==230 && y==70){
x=x+70;
}
if (x==440 && y==370 ||x==650 && y==220){
x=x-70;
}
//case Stop
if (x==440 && y==520 || x==230 && y==70 || x==440 && y==520 || x==230 && y==70){
de=0;
}
de=de-1;
}
setPosX1(x);
setPosY1(y);
repaint();
}
} |
Partager