Probleme réseau javascool

Fermé
xCirdan Messages postés 14 Date d'inscription jeudi 19 mars 2015 Statut Membre Dernière intervention 6 mai 2015 - 4 mai 2015 à 18:48
xCirdan Messages postés 14 Date d'inscription jeudi 19 mars 2015 Statut Membre Dernière intervention 6 mai 2015 - 6 mai 2015 à 12:00
Bonjour.
Avec un ami nous travaillons sur une bataille navale comme projet en ISN. L ayant fini, nous cherchons a la mettre en réseau pour faire un mode multijoueur. Seulement, lorsque je lance le mode multi et arrivé au moment ou les deux joueurs doivent communuiquer, l'un des deux plantent completement en devenant tout noir. (je p récise que pour l'instant, c est sur le meme pc mais avec deux javascool d'ouvert que j'ai testé, au cas ou ca ait une importance.) Si vous pouviez nous aider, merci.

Voici le code.(seul la fonction multi et tout ce qui a dedans est importante):


import javax.swing. *;
import java.awt.event. *;
import java.awt. *;
import java.awt.GridLayout;
import static org.javascool.proglets.txtCode.Functions.*;

JButton bouton1, bouton2,bouton3;

JFrame Menu;

class GestionClic1 implements ActionListener {// Conséquence du clique sur le bouton 1
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bouton1) {
Menu.dispose();
solo();
}
}
}
class GestionClic2 implements ActionListener {// Conséquence du clique sur le bouton 2
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bouton2) {
Menu.dispose();
multi();
}
}
}
class GestionClic3 implements ActionListener { // Conséquence du clique sur le bouton 3
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bouton3) {
Menu.dispose();
}
}
}

void PlacementJ1(int A[] []){
try{
JFrame Pos = new JFrame("Vos positions");
JButton T [] [] = new JButton[10][10];
for (int i = 0; i < 10; i ++) {
for (int j =0; j <10; j ++) {
int k=j+1;
if (i ==0) {
(T[i][j]) = new JButton("A" + k);
Pos.add(T[i][j]);
} else if (i ==1) {
(T[i][j]) = new JButton("B" + k);
Pos.add(T[i][j]);
} else if (i ==2) {
(T[i][j]) = new JButton("C" + k);
Pos.add(T[i][j]);
} else if (i ==3) {
(T[i][j]) = new JButton("D" + k);
Pos.add(T[i][j]);
} else if (i ==4) {
(T[i][j]) = new JButton("E" + k);
Pos.add(T[i][j]);
} else if (i ==5) {
(T[i][j]) = new JButton("F" + k);
Pos.add(T[i][j]);
} else if (i ==6) {
(T[i][j]) = new JButton("G" + k);
Pos.add(T[i][j]);
} else if (i ==7) {
(T[i][j]) = new JButton("H" + k);
Pos.add(T[i][j]);
} else if (i ==8) {
(T[i][j]) = new JButton("I" + k);
Pos.add(T[i][j]);
} else if (i ==9) {
(T[i][j]) = new JButton("J" + k);
Pos.add(T[i][j]);

}
T[i][j].setEnabled(false);
}
}
Pos.setVisible(true);
Pos.setLocation(400,200);
GridLayout GL = new GridLayout();
GL.setColumns(10);
GL.setRows(10);
Pos.setLayout(GL);
Pos.setSize(600, 600);
int tampon=0,i,j,ii,jj;
String S="a1";
JLayeredPane frame = getPane();
JOptionPane.showMessageDialog(frame,"Pour entre la position du bateau, rentrer en premier les coordonnées de la cases en haut à gauche, puis de celle en bas à droite");
JOptionPane.showMessageDialog(frame,"Bateau de 5 cases");

while (tampon ==0){
S = JOptionPane.showInputDialog(frame,"Coordonnée de la case en haut à gauche :","Java's Cool read",JOptionPane.QUESTION_MESSAGE);
i=Convertisseur(S)/10;
j=Convertisseur(S)%10;
S = JOptionPane.showInputDialog(frame,"Coordonnée de la case en bas à droite :","Java's Cool read",JOptionPane.QUESTION_MESSAGE);
ii=Convertisseur(S)/10;
jj=Convertisseur(S)%10;
if (i==ii && j==jj-4 && A[i][j]==0 && A[i][j+1]==0 && A[i][j+2]==0 && A[i][j+3]==0 && A[i][j+4]==0){
while (j<=jj){
A[i][j]=1;
T[i][j].setBackground(Color.BLUE);
j++;
tampon++;
}
}else if(i==ii-4 && j==jj && A[i][j]==0 && A[i+1][j]==0 && A[i+2][j]==0 && A[i+3][j]==0 && A[i+4][j]==0){
while (i<=ii){
A[i][j]=1;
T[i][j].setBackground(Color.BLUE);
i++;
tampon++;
}
}
}
tampon=0;
JOptionPane.showMessageDialog(frame,"Bateau de 4 cases");
while (tampon ==0){
S = JOptionPane.showInputDialog(frame,"Coordonnée de la case en haut à gauche :","Java's Cool read",JOptionPane.QUESTION_MESSAGE);
i=Convertisseur(S)/10;
j=Convertisseur(S)%10;
S = JOptionPane.showInputDialog(frame,"Coordonnée de la case en bas à droite :","Java's Cool read",JOptionPane.QUESTION_MESSAGE);
ii=Convertisseur(S)/10;
jj=Convertisseur(S)%10;
if (i==ii && j==jj-3 && A[i][j]==0 && A[i][j+1]==0 && A[i][j+2]==0 && A[i][j+3]==0){
while (j<=jj){
A[i][j]=1;
T[i][j].setBackground(Color.BLUE);
j++;
tampon++;
}
}else if(i==ii-3 && j==jj && A[i][j]==0 && A[i+1][j]==0 && A[i+2][j]==0 && A[i+3][j]==0){
while (i<=ii){
A[i][j]=1;
T[i][j].setBackground(Color.BLUE);
i++;
tampon++;
}
}
}
tampon=0;
JOptionPane.showMessageDialog(frame,"Bateau de 3 cases");
while (tampon ==0){
S = JOptionPane.showInputDialog(frame,"Coordonnée de la case en haut à gauche :","Java's Cool read",JOptionPane.QUESTION_MESSAGE);
i=Convertisseur(S)/10;
j=Convertisseur(S)%10;
S = JOptionPane.showInputDialog(frame,"Coordonnée de la case en bas à droite :","Java's Cool read",JOptionPane.QUESTION_MESSAGE);
ii=Convertisseur(S)/10;
jj=Convertisseur(S)%10;
if (i==ii && j==jj-2 && A[i][j]==0 && A[i][j+1]==0 && A[i][j+2]==0){
while (j<=jj){
A[i][j]=1;
T[i][j].setBackground(Color.BLUE);
j++;
tampon++;
}
}else if(i==ii-2 && j==jj && A[i][j]==0 && A[i+1][j]==0 && A[i+2][j]==0){
while (i<=ii){
A[i][j]=1;
T[i][j].setBackground(Color.BLUE);
i++;
tampon++;
}
}
}
tampon=0;
JOptionPane.showMessageDialog(frame,"Bateau de 3 cases");
while (tampon ==0){
S = JOptionPane.showInputDialog(frame,"Coordonnée de la case en haut à gauche :","Java's Cool read",JOptionPane.QUESTION_MESSAGE);
i=Convertisseur(S)/10;
j=Convertisseur(S)%10;
S = JOptionPane.showInputDialog(frame,"Coordonnée de la case en bas à droite :","Java's Cool read",JOptionPane.QUESTION_MESSAGE);
ii=Convertisseur(S)/10;
jj=Convertisseur(S)%10;
if (i==ii && j==jj-2 && A[i][j]==0 && A[i][j+1]==0 && A[i][j+2]==0){
while (j<=jj){
A[i][j]=1;
T[i][j].setBackground(Color.BLUE);
j++;
tampon++;
}
}else if(i==ii-2 && j==jj && A[i][j]==0 && A[i+1][j]==0 && A[i+2][j]==0){
while (i<=ii){
A[i][j]=1;
T[i][j].setBackground(Color.BLUE);
i++;
tampon++;
}
}
}
tampon=0;
JOptionPane.showMessageDialog(frame,"Bateau de 2 cases");
while (tampon ==0){
S = JOptionPane.showInputDialog(frame,"Coordonnée de la case en haut à gauche :","Java's Cool read",JOptionPane.QUESTION_MESSAGE);
i=Convertisseur(S)/10;
j=Convertisseur(S)%10;
S = JOptionPane.showInputDialog(frame,"Coordonnée de la case en bas à droite :","Java's Cool read",JOptionPane.QUESTION_MESSAGE);
ii=Convertisseur(S)/10;
jj=Convertisseur(S)%10;
if (i==ii && j==jj-1 && A[i][j+1]==0 ){
while (j<=jj){
A[i][j]=1;
T[i][j].setBackground(Color.BLUE);
j++;
tampon++;
}
}else if(i==ii-1 && j==jj && A[i+1][j]==0){
while (i<=ii){
A[i][j]=1;
T[i][j].setBackground(Color.BLUE);
i++;
tampon++;
}
}
}
Pos.dispose();
}
catch (Exception e) {
e.printStackTrace(System.out);
}
}

int Convertisseur (String C){
int k=0;
if (C.equals("a1") || C.equals("A1")){
k=0;
}else if (C.equals("a2") || C.equals("A2")){
k=1;
}else if (C.equals("a3") || C.equals("A3")){
k=2;
}else if (C.equals("a4") || C.equals("A4")){
k=3;
}else if (C.equals("a5") || C.equals("A5")){
k=4;
}else if (C.equals("a6") || C.equals("A6")){
k=5;
}else if (C.equals("a7") || C.equals("A7")){
k=6;
}else if (C.equals("a8") || C.equals("A8")){
k=7;
}else if (C.equals("a9") || C.equals("A9")){
k=8;
}else if (C.equals("a10") || C.equals("A10")){
k=9;
}else if (C.equals("b1") || C.equals("B1")){
k=10;
}else if (C.equals("b2") || C.equals("B2")){
k=11;
}else if (C.equals("b3") || C.equals("B3")){
k=12;
}else if (C.equals("b4") || C.equals("B4")){
k=13;
}else if (C.equals("b5") || C.equals("B5")){
k=14;
}else if (C.equals("b6") || C.equals("B6")){
k=15;
}else if (C.equals("b7") || C.equals("B7")){
k=16;
}else if (C.equals("b8") || C.equals("B8")){
k=17;
}else if (C.equals("b9") || C.equals("B9")){
k=18;
}else if (C.equals("b10") || C.equals("B10")){
k=19;
}else if (C.equals("c1") || C.equals("C1")){
k=20;
}else if (C.equals("c2") || C.equals("C2")){
k=21;
}else if (C.equals("c3") || C.equals("C3")){
k=22;
}else if (C.equals("c4") || C.equals("C4")){
k=23;
}else if (C.equals("c5") || C.equals("C5")){
k=24;
}else if (C.equals("c6") || C.equals("C6")){
k=25;
}else if (C.equals("c7") || C.equals("C7")){
k=26;
}else if (C.equals("c8") || C.equals("C8")){
k=27;
}else if (C.equals("c9") || C.equals("C9")){
k=28;
}else if (C.equals("c10") || C.equals("C10")){
k=29;
}else if (C.equals("d1") || C.equals("D1")){
k=30;
}else if (C.equals("d2") || C.equals("D2")){
k=31;
}else if (C.equals("d3") || C.equals("D3")){
k=32;
}else if (C.equals("d4") || C.equals("D4")){
k=33;
}else if (C.equals("d5") || C.equals("D5")){
k=34;
}else if (C.equals("d6") || C.equals("D6")){
k=35;
}else if (C.equals("d7") || C.equals("D7")){
k=36;
}else if (C.equals("d8") || C.equals("D8")){
k=37;
}else if (C.equals("d9") || C.equals("D9")){
k=38;
}else if (C.equals("d10") || C.equals("D10")){
k=39;
}else if (C.equals("e1") || C.equals("E1")){
k=40;
}else if (C.equals("e2") || C.equals("E2")){
k=41;
}else if (C.equals("e3") || C.equals("E3")){
k=42;
}else if (C.equals("e4") || C.equals("E4")){
k=43;
}else if (C.equals("e5") || C.equals("E5")){
k=44;
}else if (C.equals("e6") || C.equals("E6")){
k=45;
}else if (C.equals("e7") || C.equals("E7")){
k=46;
}else if (C.equals("e8") || C.equals("E8")){
k=47;
}else if (C.equals("e9") || C.equals("E9")){
k=48;
}else if (C.equals("e10") || C.equals("E10")){
k=49;
}else if (C.equals("f1") || C.equals("F1")){
k=50;
}else if (C.equals("f2") || C.equals("F2")){
k=51;
}else if (C.equals("f3") || C.equals("F3")){
k=52;
}else if (C.equals("f4") || C.equals("F4")){
k=53;
}else if (C.equals("f5") || C.equals("F5")){
k=54;
}else if (C.equals("f6") || C.equals("F6")){
k=55;
}else if (C.equals("f7") || C.equals("F7")){
k=56;
}else if (C.equals("f8") || C.equals("F8")){
k=57;
}else if (C.equals("f9") || C.equals("F9")){
k=58;
}else if (C.equals("f10") || C.equals("F10")){
k=59;
}else if (C.equals("g1") || C.equals("G1")){
k=60;
}else if (C.equals("g2") || C.equals("G2")){
k=61;
}else if (C.equals("g3") || C.equals("G3")){
k=62;
}else if (C.equals("g4") || C.equals("G4")){
k=63;
}else if (C.equals("g5") || C.equals("G5")){
k=64;
}else if (C.equals("g6") || C.equals("G6")){
k=65;
}else if (C.equals("g7") || C.equals("G7")){
k=66;
}else if (C.equals("g8") || C.equals("G8")){
k=67;
}else if (C.equals("g9") || C.equals("G9")){
k=68;
}else if (C.equals("g10") || C.equals("G10")){
k=69;
}else if (C.equals("h1") || C.equals("H1")){
k=70;
}else if (C.equals("h2") || C.equals("H2")){
k=71;
}else if (C.equals("h3") || C.equals("H3")){
k=72;
}else if (C.equals("h4") || C.equals("H4")){
k=73;
}else if (C.equals("h5") || C.equals("H5")){
k=74;
}else if (C.equals("h6") || C.equals("H6")){
k=75;
}else if (C.equals("h7") || C.equals("H7")){
k=76;
}else if (C.equals("h8") || C.equals("H8")){
k=77;
}else if (C.equals("h9") || C.equals("H9")){
k=78;
}else if (C.equals("h10") || C.equals("H10")){
k=79;
}else if (C.equals("i1") || C.equals("I1")){
k=80;
}else if (C.equals("i2") || C.equals("I2")){
k=81;
}else if (C.equals("i3") || C.equals("I3")){
k=82;
}else if (C.equals("i4") || C.equals("I4")){
k=83;
}else if (C.equals("i5") || C.equals("I5")){
k=84;
}else if (C.equals("i6") || C.equals("I6")){
k=85;
}else if (C.equals("i7") || C.equals("I7")){
k=86;
}else if (C.equals("i8") || C.equals("I8")){
k=87;
}else if (C.equals("i9") || C.equals("I9")){
k=88;
}else if (C.equals("i10") || C.equals("I10")){
k=89;
}else if (C.equals("j1") || C.equals("J1")){
k=90;
}else if (C.equals("j2") || C.equals("J2")){
k=91;
}else if (C.equals("j3") || C.equals("J3")){
k=92;
}else if (C.equals("j4") || C.equals("J4")){
k=93;
}else if (C.equals("j5") || C.equals("J5")){
k=94;
}else if (C.equals("j6") || C.equals("J6")){
k=95;
}else if (C.equals("j7") || C.equals("J7")){
k=96;
}else if (C.equals("j8") || C.equals("J8")){
k=97;
}else if (C.equals("j9") || C.equals("J9")){
k=98;
}else if (C.equals("j10") || C.equals("J10")){
k=99;
}
return k;
}

void PlacementIA(int P[][]){
int tampon =0;
int i,j,k;
while (tampon ==0) {
i = random(0, 10);
j = random(0, 6);
k=j+4;
if (P[i][j] ==0 && P[i][j +1] ==0 && P[i][j +2] ==0 && P[i][j +3] ==0 && P[i][j +4] ==0) {
while (j <=k) {
P[i][j] =1;
tampon ++;
j ++;
}
}
}
tampon =0;
while (tampon ==0) {
i = random(0, 7);
j = random(0, 10);
k=i+3;
if (P[i][j] ==0 && P[i +1][j] ==0 && P[i +2][j] ==0 && P[i +3][j] ==0) {
while (i <= k) {
P[i][j] =1;
tampon ++;
i ++;
}
}
}
tampon =0;
while (tampon ==0) {
i = random(0, 8);
j = random(0, 10);
k=i+2;
if (P[i][j] ==0 && P[i +1][j] ==0 && P[i +2][j] ==0) {
while (i <= k) {
P[i][j] =1;
tampon ++;
i ++;
}
}
}
tampon =0;
while (tampon ==0) {
i = random(0, 10);
j = random(0, 8);
k=j+2;
if (P[i][j] ==0 && P[i][j +1] ==0 && P[i][j +2] ==0) {
while (j <= k) {
P[i][j] =1;
tampon ++;
j ++;
}
}
}
tampon =0;
while (tampon ==0) {
i = random(0, 9);
j = random(0, 10);
k=i+1;
if (P[i][j] ==0 && P[i +1][j] ==0) {
while (i <=k) {
P[i][j] =1;
tampon ++;
i ++;
}
}
}
}

void Tir(int PJ1 [][], int PIA[][]){
JFrame Pos = new JFrame("Vos positions");
JFrame Vis = new JFrame("Votre vision");
JButton P [] [] = new JButton[10][10];
JButton V [] [] = new JButton[10][10];
for (int i = 0; i < 10; i ++) {
for (int j =0; j <10; j ++) {
int k=j+1;
if (i ==0) {
(P[i][j]) = new JButton("A" + k);
(V[i][j]) = new JButton("A" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==1) {
(P[i][j]) = new JButton("B" + k);
(V[i][j]) = new JButton("B" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==2) {
(P[i][j]) = new JButton("C" + k);
(V[i][j]) = new JButton("C" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==3) {
(P[i][j]) = new JButton("D" + k);
(V[i][j]) = new JButton("D" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==4) {
(P[i][j]) = new JButton("E" + k);
(V[i][j]) = new JButton("E" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==5) {
(P[i][j]) = new JButton("F" + k);
(V[i][j]) = new JButton("F" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==6) {
(P[i][j]) = new JButton("G" + k);
(V[i][j]) = new JButton("G" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==7) {
(P[i][j]) = new JButton("H" + k);
(V[i][j]) = new JButton("H" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==8) {
(P[i][j]) = new JButton("I" + k);
(V[i][j]) = new JButton("I" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==9) {
(P[i][j]) = new JButton("J" + k);
(V[i][j]) = new JButton("J" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);

}
P[i][j].setEnabled(false);
V[i][j].setEnabled(false);
if (PJ1[i][j]==1){
P[i][j].setBackground(Color.BLUE);
}
}
}
Pos.setVisible(true);
Pos.setLocation(400,200);
Vis.setLocation(1050,200);
GridLayout GL = new GridLayout();
GL.setColumns(10);
GL.setRows(10);
Pos.setLayout(GL);
Pos.setSize(600, 600);
Vis.setVisible(true);
GL.setColumns(10);
GL.setRows(10);
Vis.setLayout(GL);
Vis.setSize(600, 600);
int VieJ1=17;
int VieIA=17;
int i,j,tampon;
int touche=0;
int ii=0;
int jj=0;
int calcul=1;
int I=0;
int J=0;
int secur=0;
int h=0;
int v=0;
String S="a",SS="1";
JLayeredPane frame2 = getPane();
while (VieJ1!=0 && VieIA!=0){
S = JOptionPane.showInputDialog(frame2,"Coordonnée de la case ciblée :","Java's Cool read",JOptionPane.QUESTION_MESSAGE);
i=Convertisseur(S)/10;
j=Convertisseur(S)%10;
if (PIA [i][j]==0){
V[i][j].setBackground(Color.GREEN);
}else if (PIA[i][j]==1){
V[i][j].setBackground(Color.RED);
VieIA--;
PIA[i][j]=2;
}else if (PIA[i][j]==2){

}
tampon=0;
while (tampon==0){
calcul=1;
secur=0;
if (touche==0){
ii=random(0,10);
jj=random(0,10);
if (PJ1[ii][jj]==0){
P[ii][jj].setBackground(Color.GREEN);
tampon++;
PJ1[ii][jj]=2;
}else if (PJ1[ii][jj]==1){
P[ii][jj].setBackground(Color.RED);
VieJ1--;
tampon++;
PJ1[ii][jj]=2;
touche=1;
I=ii;
J=jj;
}else if (PJ1[ii][jj]==2){

}
}else if (touche ==1){
ii++;
if (ii==-1 || ii==10 || jj==-1 || jj==10){
calcul=0;
ii--;
touche++;
}
if (calcul==1){
if (PJ1[ii][jj]==0){
P[ii][jj].setBackground(Color.GREEN);
tampon++;
PJ1[ii][jj]=2;
touche++;;
ii--;
}else if (PJ1[ii][jj]==1){
P[ii][jj].setBackground(Color.RED);
VieJ1--;
tampon++;
PJ1[ii][jj]=2;
touche=10;
v=1;
}else if (PJ1[ii][jj]==2){
touche++;
ii--;
}
}
}else if (touche ==2){
jj++;
if (ii==-1 || ii==10 || jj==-1 || jj==10){
calcul=0;
jj--;
touche++;
}
if (calcul==1){
if (PJ1[ii][jj]==0){
P[ii][jj].setBackground(Color.GREEN);
tampon++;
PJ1[ii][jj]=2;
jj--;
}else if (PJ1[ii][jj]==1){
P[ii][jj].setBackground(Color.RED);
VieJ1--;
tampon++;
PJ1[ii][jj]=2;
touche=10;
h=1;
}else if (PJ1[ii][jj]==2){
touche++;
jj--;
}
}
}else if (touche ==3){
ii--;
if (ii==-1 || ii==10 || jj==-1 || jj==10){
calcul=0;
ii++;
touche++;
}
if (calcul==1){
if (PJ1[ii][jj]==0){
P[ii][jj].setBackground(Color.GREEN);
tampon++;
PJ1[ii][jj]=2;
ii++;
}else if (PJ1[ii][jj]==1){
P[ii][jj].setBackground(Color.RED);
VieJ1--;
tampon++;
PJ1[ii][jj]=2;
touche=10;
v=2;
}else if (PJ1[ii][jj]==2){
touche++;
ii++;
}
}
}else if (touche ==4){
jj--;
if (ii==-1 || ii==10 || jj==-1 || jj==10){
calcul=0;
jj++;
touche++;
}
if (calcul==1){
if (PJ1[ii][jj]==0){
P[ii][jj].setBackground(Color.GREEN);
tampon++;
PJ1[ii][jj]=2;
jj++;
}else if (PJ1[ii][jj]==1){
P[ii][jj].setBackground(Color.RED);
VieJ1--;
tampon++;
PJ1[ii][jj]=2;
touche=10;
h=2;
}else if (PJ1[ii][jj]==2){
touche++;
jj++;
}
}
}else if (touche==5){
touche=0;
}else if (touche==10){
if (v==1){
ii++;
if(ii==10){
ii=I;
v=2;
secur++;
}
if(secur==0){
if(PJ1[ii][jj]==0){
P[ii][jj].setBackground(Color.GREEN);
ii=I;
v=2;
tampon++;
PJ1[ii][jj]=2;
}else if (PJ1[ii][jj]==1){
P[ii][jj].setBackground(Color.RED);
VieJ1--;
tampon++;
PJ1[ii][jj]=2;
}else if(PJ1[ii][jj]==2){
ii=I;
v=2;
}
}
}else if (v==2){
ii--;
if(ii==-1){
v=0;
touche=0;
secur++;
}
if(secur==0){
if(PJ1[ii][jj]==0){
P[ii][jj].setBackground(Color.GREEN);
ii=I;
v=0;
touche=0;
tampon++;
PJ1[ii][jj]=2;
}else if (PJ1[ii][jj]==1){
P[ii][jj].setBackground(Color.RED);
VieJ1--;
tampon++;
PJ1[ii][jj]=2;
}else if(PJ1[ii][jj]==2){
ii=I;
v=0;
touche=0;
}
}
}else if(h==1){
jj++;
if(jj==10){
jj=I;
h=2;
secur++;
}
if (secur==0){
if(PJ1[ii][jj]==0){
P[ii][jj].setBackground(Color.GREEN);
jj=J;
h=2;
tampon++;
PJ1[ii][jj]=2;
}else if (PJ1[ii][jj]==1){
P[ii][jj].setBackground(Color.RED);
VieJ1--;
tampon++;
PJ1[ii][jj]=2;
}else if(PJ1[ii][jj]==2){
jj=J;
h=2;
}
}
}else if (h==2){
jj--;
if (jj==-1){
h=0;
touche=0;
secur++;
}if(secur==0){
if(PJ1[ii][jj]==0){
P[ii][jj].setBackground(Color.GREEN);
jj=J;
h=0;
touche=0;
tampon++;
PJ1[ii][jj]=2;
}else if (PJ1[ii][jj]==1){
P[ii][jj].setBackground(Color.RED);
VieJ1--;
tampon++;
PJ1[ii][jj]=2;
}else if(PJ1[ii][jj]==2){
jj=J;
h=0;
touche=0;
}
}
}
}
}
}
if (VieJ1==0){
JLayeredPane frame = getPane();
JOptionPane.showMessageDialog(frame,"Dommage pour vous, vous avez perdu");
}else if(VieIA==0){
JLayeredPane frame = getPane();
JOptionPane.showMessageDialog(frame,"Bien joué, vous sortez vainqueur de cet affrontement");
}
Pos.dispose();
Vis.dispose();
}

void solo() {
clear();
int PJ1 [] [];
PJ1 = new int [10][10];
PlacementJ1 (PJ1);
int PIA [][];
PIA = new int [10][10];
PlacementIA(PIA);
Tir(PJ1,PIA);
}

void TirMulti(int PJ1 [][]){
JFrame Pos = new JFrame("Vos positions");
JFrame Vis = new JFrame("Votre vision");
JButton P [] [] = new JButton[10][10];
JButton V [] [] = new JButton[10][10];
for (int i = 0; i < 10; i ++) {
for (int j =0; j <10; j ++) {
int k=j+1;
if (i ==0) {
(P[i][j]) = new JButton("A" + k);
(V[i][j]) = new JButton("A" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==1) {
(P[i][j]) = new JButton("B" + k);
(V[i][j]) = new JButton("B" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==2) {
(P[i][j]) = new JButton("C" + k);
(V[i][j]) = new JButton("C" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==3) {
(P[i][j]) = new JButton("D" + k);
(V[i][j]) = new JButton("D" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==4) {
(P[i][j]) = new JButton("E" + k);
(V[i][j]) = new JButton("E" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==5) {
(P[i][j]) = new JButton("F" + k);
(V[i][j]) = new JButton("F" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==6) {
(P[i][j]) = new JButton("G" + k);
(V[i][j]) = new JButton("G" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==7) {
(P[i][j]) = new JButton("H" + k);
(V[i][j]) = new JButton("H" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==8) {
(P[i][j]) = new JButton("I" + k);
(V[i][j]) = new JButton("I" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);
} else if (i ==9) {
(P[i][j]) = new JButton("J" + k);
(V[i][j]) = new JButton("J" + k);
Pos.add(P[i][j]);
Vis.add(V[i][j]);

}
P[i][j].setEnabled(false);
V[i][j].setEnabled(false);
if (PJ1[i][j]==1){
P[i][j].setBackground(Color.BLUE);
}
}
}
Pos.setVisible(true);
Pos.setLocation(400,200);
Vis.setLocation(1050,200);
GridLayout GL = new GridLayout();
GL.setColumns(10);
GL.setRows(10);
Pos.setLayout(GL);
Pos.setSize(600, 600);
Vis.setVisible(true);
GL.setColumns(10);
GL.setRows(10);
Vis.setLayout(GL);
Vis.setSize(600, 600);
int VieJ1=17;
int VieJ2=17;
int i=0;
int j=0;
String S="a1";
String R="Rien";
String SS="a1";
String RR="Rien";
JLayeredPane frame3 = getPane();
while(VieJ1!=0 || VieJ2!=0){
S = JOptionPane.showInputDialog(frame3,"Coordonnée de la case ciblée :","Java's Cool read",JOptionPane.QUESTION_MESSAGE);
i=Convertisseur(S)/10;
j=Convertisseur(S)%10;
sendMessageViaSocketServer(S);
R=getMessageViaSocketServer();
if(R.equals("Rate")){
V[i][j].setBackground(Color.GREEN);
}else if(R.equals("Touche")){
V[i][j].setBackground(Color.RED);
VieJ2--;
}else if (R.equals("Rien")){

}
SS=getMessageViaSocketServer();
i=Convertisseur(SS)/10;
j=Convertisseur(SS)%10;
if (PJ1[i][j]==0){
P[i][j].setBackground(Color.GREEN);
PJ1[i][j]=2;
RR="Rate";
}else if (PJ1[i][j]==1){
P[i][j].setBackground(Color.RED);
PJ1[i][j]=2;
RR="Touche";
VieJ1--;
}else if (PJ1[i][j]==2){
RR="Rien";
}
sendMessageViaSocketServer(RR);
}
if (VieJ1==0){
JLayeredPane frame = getPane();
JOptionPane.showMessageDialog(frame,"Dommage pour vous, vous avez perdu");
}else if(VieJ2==0){
JLayeredPane frame = getPane();
JOptionPane.showMessageDialog(frame,"Bien joué, vous sortez vainqueur de cet affrontement");
}
Pos.dispose();
Vis.dispose();
}

void multi(){
clear();
openSocketServer(6000);
int PJ1 [] [];
PJ1 = new int [10][10];
PlacementJ1 (PJ1);
TirMulti(PJ1);
closeSocketServer();
}
void main() {
Menu = new JFrame("Menu");
bouton1 = new JButton("Solo");
bouton2 = new JButton("Multi");
bouton3 = new JButton("Quitter");
GestionClic1 gc1 = new GestionClic1();
GestionClic2 gc2 = new GestionClic2();
GestionClic3 gc3 = new GestionClic3();
bouton1.addActionListener(gc1);
bouton2.addActionListener(gc2);
bouton3.addActionListener(gc3);
Menu.setLayout(new FlowLayout());
Menu.add(bouton1);
Menu.add(bouton2);
Menu.add(bouton3);
Menu.setSize(300, 100);
Menu.setVisible(true);
GridLayout GL = new GridLayout();
GL.setColumns(0);
GL.setRows(3);
Menu.setLayout(GL);
Menu.setLocationRelativeTo(null);
Menu.setSize(500, 500);

}

1 réponse

xCirdan Messages postés 14 Date d'inscription jeudi 19 mars 2015 Statut Membre Dernière intervention 6 mai 2015
6 mai 2015 à 12:00
up
0