Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider ceffb4a4 rédigé par Jamal ATTOU's avatar Jamal ATTOU
Parcourir les fichiers

Jamal : Gestion tire network

parent 52b2142e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
package controleurs;
import com.mashape.unirest.http.exceptions.UnirestException;
import info1.network.Network;
import info1.ships.BadCoordException;
import info1.ships.Coord;
import info1.ships.ICoord;
import info1.ships.JPanelCoords;
import vues.MenuCreationFlotte;
import vues.MenuJeu;
......@@ -14,9 +19,32 @@ public class ListenerMouseJouer implements MouseListener {
public ListenerMouseJouer(MenuJeu fenetre) { this.fenetre4 = fenetre; }
@Override
public void mouseClicked(MouseEvent e) {
/* switch (Network.playOneTurn(fenetre4.getGame(),)){
try {
ICoord lacordo = new Coord(((JPanelCoords)e.getSource()).getCoord());
int networkrez = Network.playOneTurn("http://37.187.38.219/api/v0", fenetre4.getGame(), fenetre4.getPlayerVues(),lacordo);
switch (networkrez){
case -10:
fenetre4.montour(false);
break;
case 0:
fenetre4.result("Raté !");
break;
case 1:
fenetre4.result("Touché !");
fenetre4.colorlacase(lacordo);
break;
case 10:
fenetre4.result("Touché coulé !");
break;
case 100:
fenetre4.result("C'est gagné");
}
} catch (BadCoordException | UnirestException badCoordException) {
badCoordException.printStackTrace();
}
}*/
}
......
......@@ -45,7 +45,7 @@ public class MenuJeu extends JFrame {
private Game magame;
private ImagePanel img;
public MenuJeu(String titre, NavyFleet flotte){
public MenuJeu(String titre, NavyFleet flotte) {
super(titre);
......@@ -65,26 +65,25 @@ public class MenuJeu extends JFrame {
plateau.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
String[] tab = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
for (int i = 0; i < 11; i++) {
for(int j=0; j<11; j++ )
{
if (i==0 && j!=0) {
String test = tab[j-1 ];
for (int j = 0; j < 11; j++) {
if (i == 0 && j != 0) {
String test = tab[j - 1];
lacase = new JLabel(test, lacase.CENTER);
lacase.setBorder(BorderFactory.createLineBorder(Color.BLACK));
plateau.add(lacase);
} else if (j==0 && i!=0) {
} else if (j == 0 && i != 0) {
int test = i;
lacase = new JLabel(String.valueOf(test), lacase.CENTER);
lacase.setBorder(BorderFactory.createLineBorder(Color.BLACK));
plateau.add(lacase);
} else if (i == 0 && j==0) {
} else if (i == 0 && j == 0) {
JPanel lacell = new JPanel();
lacell.setBorder(BorderFactory.createLineBorder(Color.BLACK));
plateau.add(lacell);
} else {
JPanelCoords cell = new JPanelCoords(j,i);
JPanelCoords cell = new JPanelCoords(j, i);
cell.setBackground(Color.white);
cell.setBorder(BorderFactory.createLineBorder(Color.BLACK));
plateau.add(cell);
......@@ -107,26 +106,25 @@ public class MenuJeu extends JFrame {
plateau.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
String[] tab = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
for (int i = 0; i < 11; i++) {
for(int j=0; j<11; j++ )
{
if (i==0 && j!=0) {
String test = tab[j-1 ];
for (int j = 0; j < 11; j++) {
if (i == 0 && j != 0) {
String test = tab[j - 1];
lacase = new JLabel(test, lacase.CENTER);
lacase.setBorder(BorderFactory.createLineBorder(Color.BLACK));
plateau.add(lacase);
} else if (j==0 && i!=0) {
} else if (j == 0 && i != 0) {
int test = i;
lacase = new JLabel(String.valueOf(test), lacase.CENTER);
lacase.setBorder(BorderFactory.createLineBorder(Color.BLACK));
plateau.add(lacase);
} else if (i == 0 && j==0) {
} else if (i == 0 && j == 0) {
JPanel lacell = new JPanel();
lacell.setBorder(BorderFactory.createLineBorder(Color.BLACK));
plateau.add(lacell);
} else {
JPanelCoords cell = new JPanelCoords(j,i);
JPanelCoords cell = new JPanelCoords(j, i);
cell.setBackground(Color.white);
cell.setBorder(BorderFactory.createLineBorder(Color.BLACK));
plateau.add(cell);
......@@ -136,15 +134,15 @@ public class MenuJeu extends JFrame {
}
}
ListeCordonnees = new ArrayList<String>();
ListeCordonnees = new ArrayList<String>();
System.out.println();
for (int i = 0; i < flotte.getListe().size(); i++) {
List<ICoord> listecoordbateau = flotte.getListe().get(i).getCoords();
for (int j = 0; j < listecoordbateau.size(); j++) {
String unecoordonnee = listecoordbateau.get(j).getX() + String.valueOf(listecoordbateau.get(j).getY());
ListeCordonnees.add(unecoordonnee);
for(JPanelCoords cell : quadrillage2){
if(unecoordonnee.equals(cell.getCoord())){
for (JPanelCoords cell : quadrillage2) {
if (unecoordonnee.equals(cell.getCoord())) {
cell.setBackground(Color.red);
}
}
......@@ -156,8 +154,7 @@ public class MenuJeu extends JFrame {
}
public JPanel creerinterfacejeu(NavyFleet flotte){
public JPanel creerinterfacejeu(NavyFleet flotte) {
//interface jeu
File f = new File("img/ship.jpg");
......@@ -166,124 +163,123 @@ public class MenuJeu extends JFrame {
fenetrejeu = new JPanel(new BorderLayout());
fenetrejeu.setBackground(new Color(0,0,0,0));
lesplateaux = new JPanel(new GridLayout(1,2));
lesplateaux.setBackground(new Color(0,0,0,0));
fenetrejeu.setBackground(new Color(0, 0, 0, 0));
lesplateaux = new JPanel(new GridLayout(1, 2));
lesplateaux.setBackground(new Color(0, 0, 0, 0));
plateau = InitialisePlateauJoueur(flotte);
plateauadverse = InitialisePlateauAdverse();
joueur = new JPanel(new BorderLayout());
joueur.setBackground(new Color(0,0,0,0));
toi = new JLabel("Player 1",JLabel.CENTER);
joueur.setBackground(new Color(0, 0, 0, 0));
toi = new JLabel("Player 1", JLabel.CENTER);
itemjoueur = new JPanel(new BorderLayout());
itemjoueur.setBackground(new Color(0,0,0,0));
itemjoueur.setBackground(new Color(0, 0, 0, 0));
//itemjoueur.setPreferredSize(new Dimension(350, 100));
viejoueur = new JPanel(new GridLayout(5,1));
viejoueur.setBackground(new Color(0,0,0,0));
viejoueur = new JPanel(new GridLayout(5, 1));
viejoueur.setBackground(new Color(0, 0, 0, 0));
//viejoueur.setBorder(BorderFactory.createTitledBorder("Vie du Joueur"));
//viejoueur.setPreferredSize(new Dimension(200,75));
itemadversaire = new JPanel(new BorderLayout());
itemadversaire.setBackground(new Color(0,0,0,0));
itemadversaire.setBackground(new Color(0, 0, 0, 0));
//itemadversaire.setPreferredSize(new Dimension(350, 100));
vieadversaire = new JPanel(new GridLayout(5,1));
vieadversaire.setBackground(new Color(0,0,0,0));
vieadversaire = new JPanel(new GridLayout(5, 1));
vieadversaire.setBackground(new Color(0, 0, 0, 0));
//vieadversaire.setBorder(BorderFactory.createTitledBorder("Vie de l'adversaire"));
//vieadversaire.setPreferredSize(new Dimension(200,75));
if(etat){
if (etat) {
GetStringBateauFrance();
GetIntBateauFrance();
}else {
} else {
GetStringBateauBelgique();
GetIntBateauBelgique();
}
bouttonmaflotte = new ArrayList<JButton>();
for(int i=0;i<tabstring.length;i++){
for (int i = 0; i < tabstring.length; i++) {
thecase = new JPanel(new BorderLayout());
thecase.setBackground(new Color(0,0,0,0));
thecase.setBackground(new Color(0, 0, 0, 0));
JButton txt = new JButton(tabstring[i]);
//txt.setBackground(new Color(0,0,0,0));
bouttonmaflotte.add(txt);
thecase.add(txt,BorderLayout.WEST);
thecase.add(txt, BorderLayout.WEST);
JLabel coeur = new JLabel(String.valueOf(tabint[i]));
thecase.add(coeur,BorderLayout.EAST);
thecase.add(coeur, BorderLayout.EAST);
viejoueur.add(thecase);
}
bouttonflotteadverse = new ArrayList<JButton>();
for(int j=0;j<tabstring.length;j++){
for (int j = 0; j < tabstring.length; j++) {
thecaseadverse = new JPanel(new BorderLayout());
thecaseadverse.setBackground(new Color(0,0,0,0));
thecaseadverse.setBackground(new Color(0, 0, 0, 0));
JButton txtadverse = new JButton(tabstring[j]);
//txtadverse.setBackground(new Color(0,0,0,0));
bouttonflotteadverse.add(txtadverse);
thecaseadverse.add(txtadverse,BorderLayout.WEST);
thecaseadverse.add(txtadverse, BorderLayout.WEST);
JLabel coeuradverse = new JLabel(String.valueOf(tabint[j]));
thecaseadverse.add(coeuradverse,BorderLayout.EAST);
thecaseadverse.add(coeuradverse, BorderLayout.EAST);
vieadversaire.add(thecaseadverse);
}
adversaire = new JPanel(new BorderLayout());
adversaire.setBackground(new Color(0,0,0,0));
other = new JLabel("Player 2",JLabel.CENTER);
adversaire.setBackground(new Color(0, 0, 0, 0));
other = new JLabel("Player 2", JLabel.CENTER);
joueur.add(toi,BorderLayout.SOUTH);
joueur.add(plateau,BorderLayout.CENTER);
adversaire.add(other,BorderLayout.SOUTH);
adversaire.add(plateauadverse,BorderLayout.CENTER);
joueur.add(toi, BorderLayout.SOUTH);
joueur.add(plateau, BorderLayout.CENTER);
adversaire.add(other, BorderLayout.SOUTH);
adversaire.add(plateauadverse, BorderLayout.CENTER);
lesplateaux.add(joueur);
lesplateaux.add(adversaire);
fenetrejeu.add(lesplateaux, BorderLayout.CENTER);
itemjoueur.add(viejoueur,BorderLayout.WEST);
itemadversaire.add(vieadversaire,BorderLayout.WEST);
joueur.add(itemjoueur,BorderLayout.NORTH);
adversaire.add(itemadversaire,BorderLayout.NORTH);
itemjoueur.add(viejoueur, BorderLayout.WEST);
itemadversaire.add(vieadversaire, BorderLayout.WEST);
joueur.add(itemjoueur, BorderLayout.NORTH);
adversaire.add(itemadversaire, BorderLayout.NORTH);
fenetrejeu.setPreferredSize(new Dimension(900,690));
fenetrejeu.setPreferredSize(new Dimension(900, 690));
img.add(fenetrejeu);
return img;
}
public boolean EtatFlotte(boolean etat){
return this.etat=etat;
public boolean EtatFlotte(boolean etat) {
return this.etat = etat;
}
public void setPlayerVues(Player leplayer){
this.player= leplayer;
public void setPlayerVues(Player leplayer) {
this.player = leplayer;
}
public Player getPlayerVues(){
public Player getPlayerVues() {
return this.player;
}
public String[] GetStringBateauFrance(){
public String[] GetStringBateauFrance() {
return tabstring = new String[]{"Porte-Avion", "Cuirassé", "Croiseur", "Torpilleur", "Sous-marin"};
}
public String[] GetStringBateauBelgique(){
return tabstring = new String[]{"Cuirassé","Croiseur","Torpilleur","Sous-marin"};
public String[] GetStringBateauBelgique() {
return tabstring = new String[]{"Cuirassé", "Croiseur", "Torpilleur", "Sous-marin"};
}
public int[] GetIntBateauFrance(){
return tabint = new int[]{1, 1, 2,2,1,0};
public int[] GetIntBateauFrance() {
return tabint = new int[]{1, 1, 2, 2, 1, 0};
}
public int[] GetIntBateauBelgique(){
return tabint = new int[]{1,2,3,4,0,0};
public int[] GetIntBateauBelgique() {
return tabint = new int[]{1, 2, 3, 4, 0, 0};
}
......@@ -301,17 +297,40 @@ public class MenuJeu extends JFrame {
p.setBackground(Color.white);
}
public void setGame(Game lagame){
this.magame =lagame;
public void setGame(Game lagame) {
this.magame = lagame;
}
public Game getGame(){
public Game getGame() {
return magame;
}
public void montour(boolean etat) {
if (!etat) {
JOptionPane optionPane = new JOptionPane("C'est pas ton tour", JOptionPane.ERROR_MESSAGE);
JDialog dialog = optionPane.createDialog("Message d'erreur");
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
}
}
public void result(String message) {
JOptionPane optionPane = new JOptionPane(message, JOptionPane.ERROR_MESSAGE);
JDialog dialog = optionPane.createDialog("Information");
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
}
public void colorlacase(ICoord coordo) {
for (JPanelCoords cell : quadrillage2) {
if (coordo.equals(cell.getCoord())) {
cell.setBackground(Color.red);
}
}
}
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter