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
|
if(Info.GetInfo() != ""){
String str = Info.GetInfo();
if(str == "Torpilleur"){
final Bateau torpilleur = new Bateau(z, 2, 2);
Info.SetInfo("");
System.out.println("Information sur torpilleur");
torpilleur.afficheBateau();
count++;
}
// .............................
}
// SI Je créé le bateau ici, pas de soucis, enfin le seul c'est que je peux pas le mettre la ^^.
if(count == 4 ){
panel2.setVisible(false);
panel3.setVisible(false);
//----------------------- INITIALISATION DES BATEAUX ADVERSES -----------------//
final Bateau torpilleuradv = new Bateau(r, 2, 2);
torpilleuradv.afficheBateau();
//...............................
//--------------------------------- FIN DE L'INI-----------------------------//
final JPanel panel4 = new JPanel(new FlowLayout());
JLabel Mess = new JLabel ("Cliquez sur une case pour essayer de toucher un navire adverse");
panel4.add(Mess);
content.add(panel4, BorderLayout.NORTH);
final JPanel panel5 = new JPanel(new FlowLayout());
int i, j; int k = 0;
panel5.setLayout(new GridLayout(10, 10)) ;
for(i=0; i<10; i++){
for(j=0; j<10; j++){
k++;
final int w = k;
btn = new JButton (""+w+"");
panel5.add(btn);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
JButton bout = (JButton) e.getSource();
String Cont = bout.getText();
int teste = (Integer.parseInt(Cont));
Point test = new Point(teste);
Clique click = new Clique(test);
bout.setEnabled(false);
/*ICI CA FONCTIONNE */ if(torpilleuradv.estDansBat(click.getClique())){
System.out.println("touché !");
JOptionPane.showMessageDialog(null, "Vous avez touché un navire de l'ordinateur") ;
bout.setText("XXX");
if(torpilleuradv.getPv()==0){
nb_bateau++;
System.out.println("coulé !");
JOptionPane.showMessageDialog(null, "Vous avez coulé un navire de l'ordinateur") ;
if(nb_bateau==4){
JOptionPane.showMessageDialog(null, "Vous avez gagné "+ pseudo) ;
System.exit(0);
}
}
}
//......................................
else{
bout.setText("");
}
//SCRIPT DE L'IA
//int[] mem; SERVIRA A STOCKER LES DIFFERENTS ESSAIS
int tir = (int)(100*Math.random());
Point tire = new Point(tir);
Clique tirer = new Clique(tire);
/*FONCTIONNE PAS*/ else if(torpilleur.estDansBat(tirer.getClique())){
System.out.println("touché !");
JOptionPane.showMessageDialog(null, "Un de vos navire a été touché par l'ordinateur") ;
bout.setText("XXX");
if(torpilleur.getPv()==0){
nb_bat++;
System.out.println("coulé !");
JOptionPane.showMessageDialog(null, "Un de vos navire a été coulé par l'ordinateur") ;
if(nb_bat==4){
JOptionPane.showMessageDialog(null, "Vous avez perdu "+ pseudo) ;
System.exit(0);
}
}
}// Fin du else if
}//fin de action performed
}//fin de l'actionlistener
);
}//fin de la boucle for
}//fin de l'autre boucle for |