Commit 09604764 authored by Tristan MAISONNEUVE's avatar Tristan MAISONNEUVE
Browse files

Fennetre Jeux modif

parent 4d87c39c
......@@ -10,10 +10,12 @@ import java.awt.event.ActionListener;
public class CreationB {
String[] co = new String[2];
Coord[] cord1 = new Coord[2];
int[] pays = new int[5];
public CreationB(String str, String str2) {
public CreationB(String str, String str2,int[] pays) {
this.co[0] = str;
this.co[1] = str2;
this.pays[0]=pays[0];this.pays[1]=pays[1];this.pays[2]=pays[2];this.pays[3]=pays[3];this.pays[4]=pays[4];
}
public Ship TestCreation() throws CoordsBadShipException, BadCoordException {
......@@ -47,39 +49,59 @@ public class CreationB {
}
switch (taille) {
case 1:
try {
Submarine s = new Submarine("s", co[0]);
return s;
} catch (BadCoordException | CoordsBadShipException badCoordException) {
badCoordException.printStackTrace();
if (pays[0]!=0) {
pays[0]--;
try {
Submarine s = new Submarine("s", co[0]);
return s;
} catch (BadCoordException | CoordsBadShipException badCoordException) {badCoordException.printStackTrace();}
} else {
JOptionPane.showMessageDialog(null, "Vous n'avez plus de Sous-marins disponibles");
return null;
}
case 2:
try {
Destroyer d = new Destroyer("d", co[0], co[1]);
return d;
} catch (BadCoordException | CoordsBadShipException badCoordException) {
badCoordException.printStackTrace();
if (pays[1]!=0) {
pays[1]--;
try {
Destroyer d = new Destroyer("d", co[0], co[1]);
return d;
} catch (BadCoordException | CoordsBadShipException badCoordException) {badCoordException.printStackTrace();}
} else {
JOptionPane.showMessageDialog(null, "Vous n'avez plus de Torpilleurs disponibles");
return null;
}
case 3:
try {
Cruiser c = new Cruiser("c", co[0], co[1]);
return c;
} catch (BadCoordException | CoordsBadShipException badCoordException) {
badCoordException.printStackTrace();
if (pays[2]!=0) {
pays[2]--;
try {
Cruiser c = new Cruiser("c", co[0], co[1]);
return c;
} catch (BadCoordException | CoordsBadShipException badCoordException) {badCoordException.printStackTrace();}
} else {
JOptionPane.showMessageDialog(null, "Vous n'avez plus de Croiseurs disponibles");
return null;
}
case 4:
try {
Battleship b = new Battleship("b", co[0], co[1]);
return b;
} catch (BadCoordException | CoordsBadShipException badCoordException) {
badCoordException.printStackTrace();
if (pays[3]!=0) {
pays[3]--;
try {
Battleship b = new Battleship("b", co[0], co[1]);
return b;
} catch (BadCoordException | CoordsBadShipException badCoordException) {badCoordException.printStackTrace();}
} else {
JOptionPane.showMessageDialog(null, "Vous n'avez plus de Cuirassés disponibles");
return null;
}
case 5:
try {
AircraftCarrier a = new AircraftCarrier("a", co[0], co[1]);
return a;
} catch (BadCoordException | CoordsBadShipException badCoordException) {
badCoordException.printStackTrace();
if (pays[4]!=0) {
pays[4]--;
try {
AircraftCarrier a = new AircraftCarrier("a", co[0], co[1]);
return a;
} catch (BadCoordException | CoordsBadShipException badCoordException) {badCoordException.printStackTrace();}
} else {
JOptionPane.showMessageDialog(null, "Vous n'avez plus de Porte-Avions disponibles");
return null;
}
case -1:
JOptionPane.showMessageDialog(null, "Merci de choisir une bonne taille de bateau, pas de diagonale, la taille doit être comprise entre 1 et 5");
......
......@@ -32,7 +32,9 @@ public class FenetreConnexion extends JFrame {
private JButton belgique;
private JTextArea textePays;
NavyFleet flotte = new NavyFleet();
private int[] pays = new int[5];
public NavyFleet flotte = new NavyFleet();
public FenetreConnexion(String titre){
super(titre);
......@@ -82,6 +84,7 @@ public class FenetreConnexion extends JFrame {
}
final Bouttons boutton = new Bouttons(new JButton(), lettre + String.valueOf(chiffre));
boutton.getButton().setBackground(Color.WHITE);
boutton.getButton().setEnabled(false);
bouttons[o] = boutton;
o++;
......@@ -94,7 +97,7 @@ public class FenetreConnexion extends JFrame {
boutton.getButton().setBackground(Color.LIGHT_GRAY);
} else {
co[1] = boutton.getString();
CreationB c = new CreationB(co[0],co[1]);
final CreationB c = new CreationB(co[0],co[1],pays);
try {if(c.TestCreation()!=null){
if(flotte.add(c.TestCreation())==0){
System.out.println(flotte.getShips());
......@@ -167,7 +170,6 @@ public class FenetreConnexion extends JFrame {
textePays = new JTextArea("La flotte de votre pays",800,20);
textePays.setEditable(false);
textePays.add(new ScrollPane());
est.add(textePays);
......@@ -183,16 +185,20 @@ public class FenetreConnexion extends JFrame {
fJeux.setPreferredSize(new Dimension(700, 700));
fJeux.pack();
fJeux.setVisible(true);
}
});
france.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
france.setEnabled(false);
belgique.setEnabled(true);
textePays.setText("Bateau de la france\nVous avez :\n1 porte-avions\n1 cuirassé\n2 croiseurs\n2 Torpilleur\n 1 Sous-marins");
pays[0] = 1; pays[1] = 2; pays[2] = 2; pays[3] = 1; pays[4] = 1;
for(int i=0;i<100;i++){
bouttons[i].getButton().setBackground(Color.WHITE);
bouttons[i].getButton().setEnabled(true);
}
flotte = new NavyFleet();
}
});
......@@ -202,6 +208,12 @@ public class FenetreConnexion extends JFrame {
france.setEnabled(true);
belgique.setEnabled(false);
textePays.setText("Bateau de la france\nVous avez :\n1 cuirassé\n2 croiseurs\n3 Torpilleur\n 4 Sous-marins");
pays[0] = 4; pays[1] = 3; pays[2] = 2; pays[3] = 1; pays[4] = 0;
for(int i=0;i<100;i++){
bouttons[i].getButton().setBackground(Color.WHITE);
bouttons[i].getButton().setEnabled(true);
}
flotte = new NavyFleet();
}
});
......@@ -214,7 +226,7 @@ public class FenetreConnexion extends JFrame {
public String getPseudo(){ return pseudo.getText(); }
// public Integer getGameID(){ return gameId; }
public NavyFleet getFlotte(){ return flotte;}
public Boolean getCreerpartie() { return true; }
// Les setters
......
package vue;
import info1.ships.BadCoordException;
import info1.ships.CoordsBadShipException;
import info1.ships.ICoord;
import modele.info1.ships.Bouttons;
import modele.info1.ships.Coord;
import modele.info1.ships.CreationB;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
public class FenetreJeux extends JFrame {
private JTextField pseudo;
......@@ -40,20 +48,40 @@ public class FenetreJeux extends JFrame {
grille.add(labellettre);
}
int o = 0;
int j=0;
for (int i =0; i<(11*10); i++){
String[] nombres={"1","2","3","4","5","6","7","8","9","10"};
final JButton label = new JButton(" ");
if(i%11==0) {
final JLabel labelchiffres = new JLabel(nombres[j],SwingConstants.CENTER);
int chiffre = 1;
char lettre = 'A';
final String[] co = new String[2];
Bouttons[] bouttons = new Bouttons[100];
for (int i = 0; i < (11 * 10); i++) {
String[] nombres = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
if (i % 11 == 0) {
final JLabel labelchiffres = new JLabel(nombres[j], SwingConstants.CENTER);
labelchiffres.setBorder(BorderFactory.createLineBorder(Color.BLACK));
grille.add(labelchiffres);
j++;
} else {
if (i % 11 == 1) {
lettre = 'A';
if (i != 1)
chiffre++;
}
final Bouttons boutton = new Bouttons(new JButton(), lettre + String.valueOf(chiffre));
boutton.getButton().setBackground(Color.WHITE);
bouttons[o] = boutton;
o++;
boutton.getButton().setBorder(BorderFactory.createLineBorder(Color.BLACK));
boutton.getButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}});
grille.add(boutton.getButton());
}
else{
label.setBorder(BorderFactory.createLineBorder(Color.BLACK));
grille.add(label);
}
lettre++;
}
principal.add(grille,BorderLayout.CENTER);
......@@ -80,10 +108,5 @@ public class FenetreJeux extends JFrame {
JPanel vide2 = new JPanel(new FlowLayout());
principal.add(vide,BorderLayout.EAST);
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment