Skip to content

Commit

Permalink
EFFET WORKS
Browse files Browse the repository at this point in the history
On peut jouer une manche :))
  • Loading branch information
florianess committed Jan 6, 2018
1 parent db14bd9 commit b87d40c
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 66 deletions.
Binary file added LO02/cartes/0_carreau.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added LO02/cartes/0_coeur.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added LO02/cartes/0_pique.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added LO02/cartes/0_trefle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions LO02/src/controleur/ControleurCouleurs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package controleur;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

import effet.EffetContre;
import joueurs.Joueur;
import main.Manche;
import vue.InterfaceManche;

public class ControleurCouleurs {

public ControleurCouleurs(Manche manche, Joueur moi, JButton[] couleurs,JFrame frame,InterfaceManche inter) {
JLabel choisir = new JLabel("Choisir la nouvelle couleur");
choisir.setFont(new Font("Tahoma", Font.PLAIN, 20));
choisir.setBounds(125, 325, 300, 25);
frame.getContentPane().add(choisir);
frame.repaint();
for (int i = 0;i<4;i++) {
JLabel chois = choisir;
int ind = i;
couleurs[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int i=0; i<4;i++) {
frame.getContentPane().remove(couleurs[i]);
}
frame.getContentPane().remove(chois);
frame.repaint();
EffetContre effet = (EffetContre) moi.getlEffet();
effet.setnCouleur(couleurs[ind].getText());
effet.setAttente(false);
inter.setAttente(false);
}
});
}
}

}
9 changes: 3 additions & 6 deletions LO02/src/controleur/ControleurPartie.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class ControleurPartie {

public ControleurPartie(HashMap<String, JCheckBox> IAs, HashMap<String, JRadioButton> diffs
,JButton lancer,JRadioButton positif,JRadioButton negatif, JTextField textField, Partie maPartie, JFrame frame) {
,JButton lancer,JRadioButton positif,JRadioButton negatif, JTextField textField, JFrame frame) {


positif.addActionListener(new ActionListener() {
Expand All @@ -42,7 +42,6 @@ public void actionPerformed(ActionEvent e) {
int ind = i;
IAs.get("IA"+i).addActionListener(new ActionListener() {
public final void actionPerformed(ActionEvent e) {
System.out.println("PRESS");
diffs.get("IA"+ ind +"f").setSelected(IAs.get("IA"+ind).isSelected());
}
}
Expand All @@ -66,9 +65,7 @@ public final void actionPerformed(ActionEvent e) {


lancer.addActionListener(new ActionListener() {
Partie laPartie = maPartie;
public void actionPerformed(ActionEvent e) {
System.out.println("BIM");
ArrayList<Joueur> joueurs = new ArrayList<Joueur>();
byte modeComptage;
if (positif.isSelected()) {
Expand All @@ -87,8 +84,8 @@ public void actionPerformed(ActionEvent e) {
}
int i = joueurs.size();
joueurs.add(new JoueurPhysique(textField.getText(), (byte) i));
laPartie.updateP(modeComptage, joueurs);
Manche manche = laPartie.nouvelleManche();
Partie.getInstance().updateP(modeComptage, joueurs);
Manche manche = Partie.getInstance().nouvelleManche();
frame.getContentPane().removeAll();
frame.repaint();
new InterfaceVariante(frame,manche);
Expand Down
52 changes: 41 additions & 11 deletions LO02/src/effet/EffetContre.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,28 @@

public class EffetContre implements Effet {
// il reste toujours a regler l'erreur quand on ne choisi la bonne couleur (choixCouleur > 3

private String nCouleur;
private boolean attente;

public String getnCouleur() {
return nCouleur;
}

public void setnCouleur(String nCouleur) {
this.nCouleur = nCouleur;
}

public boolean isAttente() {
return attente;
}

public void setAttente(boolean attente) {
this.attente = attente;
}

public void lancer(Joueur leJoueur, Manche laManche) {
String nouvCouleur;
/* String nouvCouleur;
ArrayList<String> couleur = new ArrayList<String>();
couleur.add("Carreau");
couleur.add("Coeur");
Expand All @@ -27,21 +47,31 @@ public void lancer(Joueur leJoueur, Manche laManche) {
System.out.println("Cette Couleur n'existe pas , choisis en une autre");
choixCouleur = sc.nextInt();
}
nouvCouleur = couleur.get(choixCouleur);
nouvCouleur = couleur.get(choixCouleur); */
if (leJoueur instanceof JoueurPhysique) {
setAttente(true);
while (attente) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else {
//if (Partie.getInstance())
int rnd = (int) (4 * Math.random());
nouvCouleur = couleur.get(rnd);
ArrayList<String> couleur = new ArrayList<String>();
couleur.add("Carreau");
couleur.add("Coeur");
couleur.add("Pique");
couleur.add("Trefle");
nCouleur = couleur.get(rnd);
}



Carte nouvCarteVisible = laManche.getLeTas().getCarteVisible();
System.out.println("CARTE AVANT CHANGEMENT " + nouvCarteVisible);

laManche.getLeTas().addCartesDessous(laManche.getLeTas().getCarteVisible());
nouvCarteVisible.setCouleur(nouvCouleur);
laManche.getLeTas().setCarteVisible(nouvCarteVisible);
System.out.println("La nouvelle couleur est " + nouvCouleur + ".");
laManche.getLeTas().setCarteVisible(new Carte("0", nCouleur));
System.out.println("La nouvelle couleur est " + nCouleur + ".");
leJoueur.getSesCartes().remove(leJoueur.getCarteChoisi());

}
Expand Down
4 changes: 2 additions & 2 deletions LO02/src/jeu/Carte.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public Carte(String valeur, String couleur, int points) {


public Carte() {
this.valeur = null;
this.couleur = null;
this.valeur = "0";
this.couleur = "0";
}
public Carte(String string) {
// TODO Auto-generated constructor stub
Expand Down
3 changes: 3 additions & 0 deletions LO02/src/jeu/Tas.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public void afficherCarteVisible() {

public void setCarteVisible(Carte carteVisible) {
this.carteVisible = carteVisible;
setChanged();
notifyObservers();

}

public boolean carteVisibleEffetAttaque(Variante var) {
Expand Down
21 changes: 16 additions & 5 deletions LO02/src/joueurs/Joueur.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public abstract class Joueur extends Observable {
protected int numCarte;
private boolean effetActif = false;
protected Manche laManche;
private Effet lEffet;

public Joueur(String nom, byte id) {
super();
Expand Down Expand Up @@ -106,6 +107,14 @@ public void setSesCartes(ArrayList<Carte> sesCartes) {
this.sesCartes = sesCartes;
}

public Effet getlEffet() {
return lEffet;
}

public void setlEffet(Effet lEffet) {
this.lEffet = lEffet;
}

public boolean comparerCarte() {
if (carteChoisi.getValeur() == laManche.getLeTas().getCarteVisible().getValeur()
|| carteChoisi.getCouleur() == laManche.getLeTas().getCarteVisible().getCouleur()
Expand Down Expand Up @@ -137,10 +146,12 @@ public void compterSesPoints() {

public abstract void afficherCartesG();

public void appliquerEffet(Tas leTas, Paquet lePaquet, Manche laManche) {
Effet lEffet = laManche.getVarianteManche().getValeurEffetDefense().get(carteChoisi.getValeur());
public void appliquerEffet(Manche laManche) {
lEffet = laManche.getVarianteManche().getValeurEffetDefense().get(carteChoisi.getValeur());
setEffetActif(false);
setCarteChoisi(new Carte());
System.out.println(lEffet);
System.out.println("effet actif??? " + isEffetActif());
lEffet.lancer(this,laManche);
}

Expand All @@ -153,7 +164,7 @@ public void subirEffet(Tas leTas, Paquet lePaquet, Manche laManche) {
this.poserCarte();
}
}
Effet lEffet = laManche.getVarianteManche().getValeurEffetAttaque().get(leTas.getCarteVisible().getValeur());
lEffet = laManche.getVarianteManche().getValeurEffetAttaque().get(leTas.getCarteVisible().getValeur());
lEffet.lancer(this,laManche);
}

Expand Down Expand Up @@ -181,8 +192,8 @@ private HashSet<String> valeursCartes() {
return vals;
}

public boolean uneCarteEstChoisi(Tas leTas) {
if (this.carteChoisi.equals(leTas.getCarteVisible())) {
public boolean uneCarteEstChoisi() {
if (this.carteChoisi.equals(laManche.getLeTas().getCarteVisible())) {
return true;
} else {
return false;
Expand Down
8 changes: 4 additions & 4 deletions LO02/src/joueurs/JoueurPhysique.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void setAttenteVue(boolean attenteVue) {

public JoueurPhysique(String nom, byte id) {
super(nom, id);
// TODO Auto-generated constructor stub
setCarteChoisi(new Carte());
}

public void afficherCartes() {
Expand All @@ -37,17 +37,17 @@ public void afficherCartesG() {

public void choisirUneCarte(Manche laManche) {
super.choisirUneCarte(laManche);
setChanged();
notifyObservers();
while (attenteVue) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
// TODO Auto-generated caxtch block
e.printStackTrace();
}
System.out.println("attenteChoix");
}
setChanged();
notifyObservers();
this.setAttenteVue(true);
}

Expand Down
72 changes: 56 additions & 16 deletions LO02/src/main/Manche.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import joueurs.*;
import variante.*;

public class Manche extends Observable{
public class Manche extends Observable implements Runnable{

private byte sens = 1, rnd;
private Joueur joueurEnCours;
Expand All @@ -20,6 +20,7 @@ public class Manche extends Observable{
private Paquet lePaquet;
private Tas leTas;
private HashMap<String, Variante> lesVariantes;
private boolean attente = false;

public byte getSens() {
return sens;
Expand Down Expand Up @@ -139,15 +140,15 @@ public void jouerTourG() {
joueurEnCours.trierCartes();
joueurEnCours.afficherCartesG();
joueurEnCours.choisirUneCarte(this);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(joueurEnCours.uneCarteEstChoisi()+" carte select + "+joueurEnCours.isEffetActif());
if (joueurEnCours.uneCarteEstChoisi() && joueurEnCours.isEffetActif()) {
joueurEnCours.appliquerEffet(this);
}
if (joueurEnCours.getSesCartes().size() > 1) {
this.changerJoueurEnCours();
} else if (Partie.getInstance().getModeComptage() == 0 && joueurEnCours.getSesCartes().size() == 0){
mancheFinie();
}
this.changerJoueurEnCours();
setChanged();
notifyObservers();
}

public void jouerTour() {
Expand All @@ -157,8 +158,8 @@ public void jouerTour() {
joueurEnCours.trierCartes();
joueurEnCours.afficherCartes();
joueurEnCours.choisirUneCarte(this);
if (joueurEnCours.uneCarteEstChoisi(leTas) && joueurEnCours.isEffetActif()) { //retour au if, le while bloquait le jeu au changement de couleur
joueurEnCours.appliquerEffet(leTas,lePaquet,this); // idée : déplacer ce if dans choisirCarte
if (joueurEnCours.uneCarteEstChoisi() && joueurEnCours.isEffetActif()) { //retour au if, le while bloquait le jeu au changement de couleur
joueurEnCours.appliquerEffet(this); // idée : déplacer ce if dans choisirCarte
}
if (joueurEnCours.getSesCartes().size() == 1) {
this.uneCarte();
Expand Down Expand Up @@ -223,9 +224,7 @@ private void mancheFinie() {
System.out.println(joueurEnCours.getNom() + " a gagné la manche!\n");
for (int i = 0; i < Partie.getInstance().getLesJoueurs().size(); i++) {
Partie.getInstance().getLesJoueurs().get(i).compterSesPoints();
}


}
}

if (nbManche != 1) {
Expand Down Expand Up @@ -286,13 +285,54 @@ public void uneCarte() {
}
}

public boolean isAttente() {
return attente;
}

public void setAttente(boolean attente) {
this.attente = attente;
}

public void changerJoueurEnCours() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (joueurEnCours.getId() == 0 && sens == -1) {
joueurEnCours = Partie.getInstance().getLesJoueurs().get(Partie.getInstance().getNbIA());
joueurEnCours = Partie.getInstance().getLesJoueurs().get(Partie.getInstance().getLesJoueurs().size()-1);
} else {
joueurEnCours = Partie.getInstance().getLesJoueurs()
joueurEnCours = Partie.getInstance().getLesJoueurs()
.get((joueurEnCours.getId() + sens) % (Partie.getInstance().getLesJoueurs().size()));
}
setChanged();
notifyObservers();
}

public void run() {
// TODO Auto-generated method stub
while (this.getJoueurEnCours().getSesCartes().size() != 0) {
if (lePaquet.getCartes().size() == 0) {
lePaquet.setCartes(leTas.getCartesDessous());
leTas.viderCartesDessous();
System.out.println("Le paquet a été changé et se mélange");
lePaquet.melanger();
}
if (leTas.isAvoirEffet()) {
leTas.setAvoirEffet(false);
joueurEnCours.subirEffet(leTas,lePaquet,this);
}
this.jouerTourG();
while(attente){
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

}
4 changes: 2 additions & 2 deletions LO02/src/variante/VarianteMinimale.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public VarianteMinimale() {
super();
this.nom = "Minimal";
this.valeurContre = "8";
//valeurEffetDefense.put("10",new EffetRejouer());
//valeurEffetDefense.put("8",new EffetContre());
valeurEffetDefense.put("10",new EffetRejouer());
valeurEffetDefense.put("8",new EffetContre());
}
}
Loading

0 comments on commit b87d40c

Please sign in to comment.