Skip to content
Snippets Groups Projects
Commit fd56bf10 authored by BARBI HUGO's avatar BARBI HUGO
Browse files

Merge branch 'master' of git.unistra.fr:hbarbi/puissance4_java into master

parents 2fa0a304 b0c57bc9
No related merge requests found
Showing
with 14097 additions and 1078 deletions
...@@ -111,13 +111,8 @@ ...@@ -111,13 +111,8 @@
<workItem from="1608731061374" duration="31000" /> <workItem from="1608731061374" duration="31000" />
<workItem from="1608731694939" duration="868000" /> <workItem from="1608731694939" duration="868000" />
<workItem from="1608895891323" duration="2003000" /> <workItem from="1608895891323" duration="2003000" />
<workItem from="1609167632217" duration="67000" /> <workItem from="1609780831959" duration="27000" />
<workItem from="1609168011546" duration="326000" /> <workItem from="1609840719604" duration="193000" />
<workItem from="1609589478284" duration="631000" />
<workItem from="1609590983615" duration="2498000" />
<workItem from="1609771727333" duration="1454000" />
<workItem from="1609775093675" duration="86000" />
<workItem from="1609776700337" duration="472000" />
</task> </task>
<servers /> <servers />
</component> </component>
...@@ -136,4 +131,15 @@ ...@@ -136,4 +131,15 @@
</option> </option>
<option name="oldMeFiltersMigrated" value="true" /> <option name="oldMeFiltersMigrated" value="true" />
</component> </component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/puissance4/model/Grille.java</url>
<line>31</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project> </project>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -16,7 +16,7 @@ public class Main ...@@ -16,7 +16,7 @@ public class Main
game.addJoueur(new Joueur("Kakashi Hatake", new Pion(Color.RED))); game.addJoueur(new Joueur("Kakashi Hatake", new Pion(Color.RED)));
game.addJoueur(new Joueur("Obito Uchiha", new Pion(Color.YELLOW))); game.addJoueur(new Joueur("Obito Uchiha", new Pion(Color.YELLOW)));
game.JoueurSuivant(); game.startGame();
new VueJoueur(game); new VueJoueur(game);
} }
} }
...@@ -93,10 +93,8 @@ public class Puissance4Controleur ...@@ -93,10 +93,8 @@ public class Puissance4Controleur
if(testWinner()) if(testWinner())
{ {
setWinner(getJoueurCourant()); setWinner(getJoueurCourant());
this.getGrilleCourant().viderGrille();
} }
joueurSuivant();
return res; return res;
} }
......
...@@ -8,6 +8,8 @@ import java.awt.*; ...@@ -8,6 +8,8 @@ import java.awt.*;
public class VueJoueur extends JFrame { public class VueJoueur extends JFrame {
private Puissance4Controleur game; private Puissance4Controleur game;
private JLabel jlJoueur;
private JLabel jlGagnant;
public VueJoueur(Puissance4Controleur game){ public VueJoueur(Puissance4Controleur game){
this.game=game; this.game=game;
...@@ -16,6 +18,28 @@ public class VueJoueur extends JFrame { ...@@ -16,6 +18,28 @@ public class VueJoueur extends JFrame {
this.setSize( 1000, 800); this.setSize( 1000, 800);
JPanel vue= new JPanel(new BorderLayout()); JPanel vue= new JPanel(new BorderLayout());
//Affichage des infos en haut de la grille (gagnant, tour du joueur) + boutton recommancer
JPanel info = new JPanel(new GridLayout(1,3));
jlGagnant = new JLabel("Aucun gagnant");
jlJoueur = new JLabel("Tour du joueur : "+this.game.getJoueurCourant().getNom());
JButton recommancer = new JButton("Recommancer");
recommancer.setCursor(Cursor.getPredefinedCursor(12));
//Ajout dans le jpanel info + changement de couleur en fonction du joueur courant
info.add(jlGagnant);
info.add(jlJoueur);
info.add(recommancer);
info.setBackground(Color.BLACK);
jlGagnant.setForeground(Color.WHITE);
jlJoueur.setForeground(this.game.getJoueurCourant().getColor().getCouleur());
//Evenement du bouton recommancer
recommancer.addActionListener(e -> {
this.game.getGrilleCourant().viderGrille();
this.majGrille();
});
//Récupération ligne & colonne //Récupération ligne & colonne
int nbLigne = this.game.getGrilleCourant().getNblignes(); int nbLigne = this.game.getGrilleCourant().getNblignes();
int nbColonne = this.game.getGrilleCourant().getNbColonnes(); int nbColonne = this.game.getGrilleCourant().getNbColonnes();
...@@ -41,14 +65,15 @@ public class VueJoueur extends JFrame { ...@@ -41,14 +65,15 @@ public class VueJoueur extends JFrame {
for(int i = 0; i < nbColonne; i++) for(int i = 0; i < nbColonne; i++)
{ {
int col = i; int col = i;
JButton buttonPLay = new JButton("Jouer colonne :"+(col+1)); JButton buttonPLay = new JButton("Jouer colonne :"+(col+1));
buttonPLay.addActionListener(e -> this.play(col)); buttonPLay.addActionListener(e -> this.play(col));
grille.add(buttonPLay); grille.add(buttonPLay);
buttonPLay.setCursor(Cursor.getPredefinedCursor(12));
} }
//Ajout dans la grille //Ajout dans la grille
vue.add(grille, BorderLayout.CENTER); vue.add(grille, BorderLayout.CENTER);
vue.add(info, BorderLayout.NORTH);
//Affichage de la vue //Affichage de la vue
this.setContentPane(vue); this.setContentPane(vue);
...@@ -60,21 +85,51 @@ public class VueJoueur extends JFrame { ...@@ -60,21 +85,51 @@ public class VueJoueur extends JFrame {
{ {
if(this.game.peutJouer(colonne)) { if(this.game.peutJouer(colonne)) {
if (this.game.getWinner()!=null){ if (this.game.getWinner()!=null){
this.majGrille();
String colorWinner="Jaune"; String colorWinner="Jaune";
if (this.game.getWinner().getColor().getCouleur()==Color.RED){ if (this.game.getWinner().getColor().getCouleur()==Color.RED){
colorWinner="Rouge"; colorWinner="Rouge";
} }
//Affichage du gagant
this.jlGagnant.setText(this.game.getWinner().getNom()+" A GAGNÉ LA PARTIE !");
this.jlGagnant.setForeground(this.game.getJoueurCourant().getColor().getCouleur());
JOptionPane.showMessageDialog(this, JOptionPane.showMessageDialog(this,
this.game.getWinner().getNom()+" ("+colorWinner+") A GAGNE LA PARTIE !"); this.game.getWinner().getNom()+" ("+colorWinner+") A GAGNÉ LA PARTIE !");
this.game.setWinner(null); this.game.setWinner(null);
this.game.getGrilleCourant().viderGrille();
} }
this.game.joueurSuivant();
this.majGrille(); this.majGrille();
} }
else { else {
System.out.println("Colonne rempli !"); System.out.println("Colonne rempli !");
} }
//Test si la grille est pleine
if(!this.game.getGrilleCourant().getCases()[0][this.game.getGrilleCourant().getNblignes()-1].estVide()){
if(!this.game.getGrilleCourant().getCases()[1][this.game.getGrilleCourant().getNblignes()-1].estVide()){
if(!this.game.getGrilleCourant().getCases()[2][this.game.getGrilleCourant().getNblignes()-1].estVide()){
if(!this.game.getGrilleCourant().getCases()[3][this.game.getGrilleCourant().getNblignes()-1].estVide()){
if(!this.game.getGrilleCourant().getCases()[4][this.game.getGrilleCourant().getNblignes()-1].estVide()){
if(!this.game.getGrilleCourant().getCases()[5][this.game.getGrilleCourant().getNblignes()-1].estVide()){
if(!this.game.getGrilleCourant().getCases()[6][this.game.getGrilleCourant().getNblignes()-1].estVide()){
this.game.joueurSuivant();
this.game.getGrilleCourant().viderGrille();
JOptionPane.showMessageDialog(this, "EGALITÉ ! Nouvelle partie.");
this.majGrille();
}
}
}
}
}
}
}
this.jlJoueur.setText("Tour du joueur : "+this.game.getJoueurCourant().getNom());
this.jlJoueur.setForeground(this.game.getJoueurCourant().getColor().getCouleur());
} }
public void majGrille() public void majGrille()
......
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