diff --git a/2TI_DEV_application.pdf b/2TI_DEV_application.pdf new file mode 100644 index 0000000..00bc525 Binary files /dev/null and b/2TI_DEV_application.pdf differ diff --git a/Observer/Observable.java b/Observer/Observable.java new file mode 100644 index 0000000..4d3e539 --- /dev/null +++ b/Observer/Observable.java @@ -0,0 +1,14 @@ +package com.abalone_jeu.Observer; + +import java.awt.Point; +import java.util.ArrayList; + +public interface Observable { + public ArrayList list=new ArrayList() ; + public void addObservateur(Observateur obs); + public void delObserver(); + public void NotifyObserver(boolean k,boolean a, Point b, int c); + public void NotifyObserver(boolean a,int id); + public void NotifyObserver(String a,String b,int a1,int b1); + +} diff --git a/Observer/Observateur.java b/Observer/Observateur.java new file mode 100644 index 0000000..d1ef740 --- /dev/null +++ b/Observer/Observateur.java @@ -0,0 +1,10 @@ +package com.abalone_jeu.Observer; + +import java.awt.Point; + +public interface Observateur { + + public void update(boolean k, boolean a, Point b, int c); + public void update(boolean v,int id); + public void update(String a,String b,int a1,int b1); +} diff --git a/Ressource/IA.png b/Ressource/IA.png new file mode 100644 index 0000000..568ff97 Binary files /dev/null and b/Ressource/IA.png differ diff --git a/Ressource/Trou2.png b/Ressource/Trou2.png new file mode 100644 index 0000000..da42a06 Binary files /dev/null and b/Ressource/Trou2.png differ diff --git a/Ressource/abalonearr.png b/Ressource/abalonearr.png new file mode 100644 index 0000000..f8d645e Binary files /dev/null and b/Ressource/abalonearr.png differ diff --git a/Ressource/boule_b.png b/Ressource/boule_b.png new file mode 100644 index 0000000..d9153f2 Binary files /dev/null and b/Ressource/boule_b.png differ diff --git a/Ressource/boule_n.png b/Ressource/boule_n.png new file mode 100644 index 0000000..a30f5e5 Binary files /dev/null and b/Ressource/boule_n.png differ diff --git a/Ressource/business_users_search.png b/Ressource/business_users_search.png new file mode 100644 index 0000000..96a3b1c Binary files /dev/null and b/Ressource/business_users_search.png differ diff --git a/Ressource/disc.png b/Ressource/disc.png new file mode 100644 index 0000000..f360114 Binary files /dev/null and b/Ressource/disc.png differ diff --git a/Ressource/help.png b/Ressource/help.png new file mode 100644 index 0000000..2cd2bd2 Binary files /dev/null and b/Ressource/help.png differ diff --git a/Ressource/info.png b/Ressource/info.png new file mode 100644 index 0000000..200c448 Binary files /dev/null and b/Ressource/info.png differ diff --git a/Ressource/joueur1.png b/Ressource/joueur1.png new file mode 100644 index 0000000..af80d04 Binary files /dev/null and b/Ressource/joueur1.png differ diff --git a/Ressource/joueur2.png b/Ressource/joueur2.png new file mode 100644 index 0000000..0d61513 Binary files /dev/null and b/Ressource/joueur2.png differ diff --git a/Ressource/k.png b/Ressource/k.png new file mode 100644 index 0000000..712d4e4 Binary files /dev/null and b/Ressource/k.png differ diff --git a/Ressource/loading_throbber_icon.png b/Ressource/loading_throbber_icon.png new file mode 100644 index 0000000..58e4599 Binary files /dev/null and b/Ressource/loading_throbber_icon.png differ diff --git a/Ressource/manette-jeu-jeux-forfait-icone-6110-16.png b/Ressource/manette-jeu-jeux-forfait-icone-6110-16.png new file mode 100644 index 0000000..97d6236 Binary files /dev/null and b/Ressource/manette-jeu-jeux-forfait-icone-6110-16.png differ diff --git a/Ressource/ok.png b/Ressource/ok.png new file mode 100644 index 0000000..d703247 Binary files /dev/null and b/Ressource/ok.png differ diff --git a/Ressource/pause.png b/Ressource/pause.png new file mode 100644 index 0000000..5e90409 Binary files /dev/null and b/Ressource/pause.png differ diff --git a/Ressource/play.png b/Ressource/play.png new file mode 100644 index 0000000..45e35c2 Binary files /dev/null and b/Ressource/play.png differ diff --git a/Ressource/user.png b/Ressource/user.png new file mode 100644 index 0000000..881f6ac Binary files /dev/null and b/Ressource/user.png differ diff --git a/Ressource/users.png b/Ressource/users.png new file mode 100644 index 0000000..b1eae4f Binary files /dev/null and b/Ressource/users.png differ diff --git a/Ressource/users_info.png b/Ressource/users_info.png new file mode 100644 index 0000000..03ac5e7 Binary files /dev/null and b/Ressource/users_info.png differ diff --git a/Ressource/winner-cup.gif b/Ressource/winner-cup.gif new file mode 100644 index 0000000..59dddf9 Binary files /dev/null and b/Ressource/winner-cup.gif differ diff --git a/com.abalone_jeu.Controleur/Controle.java b/com.abalone_jeu.Controleur/Controle.java new file mode 100644 index 0000000..a180584 --- /dev/null +++ b/com.abalone_jeu.Controleur/Controle.java @@ -0,0 +1,508 @@ +package com.abalone_jeu.Controleur; + +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; + +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; + +import com.abalone_jeu.IHM.View; +import com.abalone_jeu.Model.Boule; +import com.abalone_jeu.Model.Joueur; +import com.abalone_jeu.Model.Partie; +import com.abalone_jeu.Model.Trou; + +public class Controle implements KeyListener,MouseListener,ActionListener { + private static Partie a; + private boolean b=false; + private static View a1; + private static int []jou1=new int[2]; + private int [][] j1 = new int[14][2]; + private int [][] j2 = new int[14][2]; + //private int directionCLIC; + public void keyPressed(KeyEvent e) + { + + } + + @Override + public void keyReleased(KeyEvent arg0) { + + switch (arg0.getKeyChar()) + { + //laterale + case '4'://System.out.println("touche gauche"); + playCoups(4); + break; + + + case '6'://System.out.println("touche droite"); + playCoups(1); + break; + + + case '7'://System.out.println("touche haut gauche"); + playCoups(5); + break; + + + case '9'://System.out.println("touche haut droite"); + playCoups(0); + break; + + + case '1'://System.out.println("touche bas gauche"); + playCoups(3); + break; + + case '3'://System.out.println("touche bas droite"); + playCoups(2); + break; + + } + + } + + public void b1Selected(int direction) //lorsque 1e boule est selectionne + { + b=Joueur.deplacer(a.table.getPion().get(0),direction); + //deplacement a ete effectue + if(b==true) + { + //rendre toute les bouleJoueur2 inactif et changer de joueur + a.table.jouer(); + a.table.setNbSelect(0); + iAgame(); + //System.out.println("deplacement effectue"); + } + //sinon essayer une autre direction + } + + public void b2Selected(int direction) //lorsque 2 boule sont selectionne + { + if(Joueur.testFleche2(direction)) //deplacement lateral possible pour ces 2 pion + { + Joueur.deplacer(a.table.getPion().get(0),direction); + Joueur.deplacer(a.table.getPion().get(1),direction); + a.table.jouer(); + a.table.setNbSelect(0); + iAgame(); + //System.out.println("deplacement lateral possible pour ces 2 pion"); + } + } + + public void b3Selected(int direction) //lorsque 3 boule sont selectionne + { + if(Joueur.testFleche2(direction)) //deplacement lateral possible pour ces 3 pion + { + Joueur.deplacer(a.table.getPion().get(0),direction); + Joueur.deplacer(a.table.getPion().get(1),direction); + Joueur.deplacer(a.table.getPion().get(2),direction); + a.table.jouer(); + a.table.setNbSelect(0); + iAgame(); + //System.out.println("deplacement lateral possible pour ces 3 pion"); + } + } + + public void playCoups(int direction) //cette fonction permet d'effectue le deplacement pour chaq coup direction choisit par le joueur + { + if(a!=null && a.table.getNbSelect()==1) + { + b1Selected(direction); + + } + else if(a!=null && a.table.getNbSelect()==2) + { + b2Selected(direction); + } + else if(a!=null && a.table.getNbSelect()==3) + { + b3Selected(direction); + } + else + { + System.out.println("pas de boule selectionne"); + } + } + + public void iAgame() + { + if(a.table.getState()==false && a.j2.isIaJoueur() && a.table.getTour().equals(a.j2)) + { + a.j2.calculCoup(); + Joueur.deplacer(Joueur.bP,Joueur.bD); + b=false; + + Joueur.bD=-20; + Joueur.bP=null; + a.table.jouer(); + } + } + + @Override + public void keyTyped(KeyEvent arg0) { + + } + + @Override + public void mouseClicked(MouseEvent arg0) { + int c=a1.getEchiquier().getIDB(arg0.getSource()); + if((a!=null && a.table.getState()==false) && (a.table.getTour().equals(a.j1) && c>=14)&& arg0.getButton()==1) + { + a.j1.select(c); + } + else if((a!=null && a.table.getState()==false) &&(a.table.getTour().equals(a.j2) && a.j2.isIaJoueur()==false && c<14)&& arg0.getButton()==1) + { + a.j2.select(c); + } + else if(arg0.getButton()==3 && a!=null && a.table.getNbSelect()>=1) + { + a.table.setNbSelect(0); + + } + + } + + + + @Override + public void mouseEntered(MouseEvent arg0) { + // TODO Stub de la methode genere automatiquement + + } + + @Override + public void mouseExited(MouseEvent arg0) { + // TODO Stub de la methode genere automatiquement + + } + + @Override + public void mousePressed(MouseEvent arg0) { + // TODO Stub de la methode genere automatiquement + + } + + @Override + public void mouseReleased(MouseEvent arg0) { + // TODO Stub de la methode genere automatiquement + + } + + public static void nouvellePartie() + { + if(a==null) + { a=new Partie(); + a1.setTable(a.table); + a.table.setTour(a.j1); + a1.newGame(); + } + else + { + Trou.setNum(0); + Boule.setCpteur(0); + Joueur.setCpteur(0); + a=null; + a=new Partie(); + a1.setTable(a.table); + a.table.setTour(a.j1); + a.table.nouvellePartie(); + a1.newGame(); + } + } + + public void level(int i) + { + + a.j2.setIaJoueur(true); + a.j2.setNiveau(i); + a1.iaPlayer(); + + + } + @Override + public void actionPerformed(ActionEvent arg0) { + + switch(arg0.getActionCommand()) + { + + case"Niveau 1"://System.out.println("Niveau 1"); + nouvellePartie(); + level(1); + break; + + + case"Niveau 2"://System.out.println("Niveau 2"); + nouvellePartie(); + level(2); + + break; + + case"Niveau 3"://System.out.println("Niveau 2"); + nouvellePartie(); + level(3); + + break; + + case"Niveau 4"://System.out.println("Niveau 2"); + nouvellePartie(); + level(4); + + break; + + case"Niveau 5"://System.out.println("Niveau 2"); + nouvellePartie(); + level(5); + + break; + + case"Niveau 6"://System.out.println("Niveau 2"); + nouvellePartie(); + level(6); + + break; + + + case"Humain vs Humain"://System.out.println("Humain vs Humain"); + nouvellePartie(); + + + break; + + case"Sauvegarder la Partie"://System.out.println("Sauvegarder la Partie"); + + if(a!=null) + { + save(); + //System.out.println("sauvegarde terminee..."); + } + + break; + + + case"Charger une Partie"://System.out.println("Charger une Partie"); + nouvellePartie(); + load(); + + + //System.out.println("Chargement termine"); + break; + + case"Quitter"://System.out.println("Quitter"); + if(a!=null) + save(); + System.exit(0); + + break; + } + + + + } + + + public static void main(String[] args) + { + + try { + UIManager.setLookAndFeel("com.jtattoo.plaf.texture.TextureLookAndFeel"); + } catch (ClassNotFoundException | InstantiationException + | IllegalAccessException + | UnsupportedLookAndFeelException e1) { + e1.printStackTrace();}; + + EventQueue.invokeLater(new Runnable(){ + public void run() + { + View window = new View(); + a1=window; + window.getFrame().setVisible(true); + + + } + }); + + + } + + + public void save() + { + int i=0; + if(a.table.getTour().equals(a.j1)) + { + jou1[0]=5; + if(a.j2.isIaJoueur()) + jou1[1]=a.j2.getNiveau(); + else + jou1[1]=-1; + } + else + { + if(a.j2.isIaJoueur()) + { + jou1[1]=a.j2.getNiveau(); + } + else + { + jou1[1]=5; + } + jou1[0]=-1; + + } + + for(Boule [] c : a.table.BouleJoueur1()) + { + for(Boule d : c) + { + j1[i][0]=d.getIdBoule(); + j1[i][1]=d.getTrou().getIdTrou(); + i++; + } + } + i=0; + for(Boule [] c : a.table.bouleJoueur2()) + { + for(Boule d : c) + { + j2[i][0]=d.getIdBoule(); + j2[i][1]=d.getTrou().getIdTrou(); + i++; + } + } + write_Fichier(j1,j2,jou1,"fich.txt"); + } + + public void load() + { + + read_Fichier(j1, j2, jou1,"fich.txt"); + if(jou1[1]==-1 && jou1[0]==5) //ici ls 2 joueur st humain et ce le tour du joueur1 + { + a.table.setTour(a.j1); + + } + else if(jou1[1]==5 && jou1[0]==-1) //ici ls 2 joueur st humain et ce le tour du joueur2 + { + a.table.setTour(a.j2); + } + else if(jou1[0]==5 && jou1[1]!=-1) //ici ce le tour du joueur 1 et le joueur2 est la machine + { + a.table.setTour(a.j1); + a.j2.setIaJoueur(true); + level(jou1[1]); + } + else if(jou1[1]!=-1 && jou1[0]==-1) //ici ce le tour du joueur2 ki e machine + { + a.table.setTour(a.j2); + a.j2.setIaJoueur(true); + level(jou1[1]); + iAgame(); + } + else + System.out.println("\nprobleme de chargement"); + + + for(Boule [] v:a.table.BouleJoueur1()) + { + for(Boule d : v) + { + for(int i1=0; i1<14; i1++) + if(d.getIdBoule()==j1[i1][0]) + { + d.setTrou(a.table.getTrouByID(j1[i1][1])); + } + } + } + + for(Boule [] v:a.table.bouleJoueur2()) + { + for(Boule d : v) + { + for(int i1=0; i1<14; i1++) + if(d.getIdBoule()==j2[i1][0]) + { + d.setTrou(a.table.getTrouByID(j2[i1][1])); + } + } + } + + } + + + + public void write_Fichier(int [][] joueur_1, int [][] joueur_2, int [] j_1, String nomFichier){ + File f= null; //Pour la premiere ecriture si le fichier n'existe pas cette ligne permet de le creer sinon elle ecrit + //directement dans le fichier + + try + { + f= new File(nomFichier); + PrintWriter ecrire = new PrintWriter (new BufferedWriter (new FileWriter (f))); + ecrire.println(j_1[0]); + for(int i=0; i=0) + { + etat=tableTransition[etat][suivant]; + + if(vois.getBord()==true) + { + suivant=3; + } + else if(vois.getOccupied()==false) + { + suivant=2; + } + else if(vois.getOccupied()==true) + { + if(vois.getBoule().getColor()==trou.getBoule().getColor()) + { + suivant=0; + vois=vois.voisinage[direction]; + } + else + { + suivant=1; + vois=vois.voisinage[direction]; + } + } + + } + return etat; + + } + + + + + //retourne le voisin d'un trou selon la direction indiqué + public Trou getVoisin(Trou a,int direction) + { + return a.voisinage[direction]; + } + + + + + + + //Les fonction de déplacement + /** + * fonction de deplacement et de direction de boule x,y,z + * @param b + * @param direction + */ + public void deplacer_1(Boule b,int direction) + { + Trou temp1=getVoisin(b.getTrou(),direction); + b.setTrou(temp1); + } + + + public void deplacer_2(Boule b,int direction) + { + Trou temp=getVoisin(b.getTrou(),direction); + deplacer_1(temp.getBoule(),direction); + deplacer_1(b,direction); + } + + public void deplacer_3(Boule b,int direction) + { + Trou temp=getVoisin(b.getTrou(),direction); + deplacer_2(temp.getBoule(),direction); + deplacer_1(b,direction); + } + + public void pousser_2_1(Boule b,int direction) + { + Trou temp=getVoisin(b.getTrou(),direction); + deplacer_2(temp.getBoule(),direction); + deplacer_1(b,direction); + + } + public void pousser_3_1(Boule b,int direction) + { + Trou temp=getVoisin(b.getTrou(),direction); + deplacer_3(temp.getBoule(),direction); + deplacer_1(b,direction); + + + } + + public void pousser_3_2(Boule b,int direction) + { + Trou temp=getVoisin(b.getTrou(),direction); + pousser_3_1(temp.getBoule(),direction); + deplacer_1(b,direction); + } + + //précise a la boule manger qu'elle est sortie + //on previent la table de jeu qu'il y'a une boule qui est sortie ainsi la table vérifie ou en est la partie + /** + * cette fonction informe la table que la boule est sortie et precise à la boule qu'elle est sortie + * @param b + * @param direction + */ + public void manger_2_1(Boule b,int direction) + { + pousser_2_1(b,direction); + } + public void manger_3_1(Boule b,int direction) + { + pousser_3_1(b,direction); + + } + + public void manger_3_2(Boule b,int direction) + { + pousser_3_2(b,direction); + } + + public void Bloquer() + { + + } + + + + + +} diff --git a/com.abalone_jeu.Model/Hexagone.java b/com.abalone_jeu.Model/Hexagone.java new file mode 100644 index 0000000..4f32bdb --- /dev/null +++ b/com.abalone_jeu.Model/Hexagone.java @@ -0,0 +1,538 @@ +package com.abalone_jeu.Model; + +import java.awt.Point; +import java.util.ArrayList; + +import com.abalone_jeu.Observer.Observable; +import com.abalone_jeu.Observer.Observateur; + + +public class Hexagone implements Observable { + private Joueur tour; + protected int nbSelect=0; + protected ArrayList pion=new ArrayList(); + + private Joueur [] joueurs=new Joueur[2]; //les 2 joueurs + private Boule [][] bouleJoueur1=new Boule[3][]; + private Boule [][] bouleJoueur2=new Boule[3][]; + private boolean partieEnd=false; //c.a.d si la partie est fini ou pas + private Trou[][] toute=new Trou[11][]; //11 ligne 19 colonne + public Coups regle; //les règle du jeu + private Point [][] T = + { + {null,null,null,null,null,null}, + {null,new Point(95, 54),new Point(130, 54),new Point(165, 54),new Point(200, 54),new Point(235, 54),null}, + {null,new Point(77, 88),new Point(112, 88),new Point(147, 88), new Point(182, 88),new Point(217, 88), new Point(252, 88),null}, + {null,new Point(59, 122),new Point(95, 122),new Point(130, 122),new Point(165, 122),new Point(200, 122),new Point(235, 122), new Point(270, 122),null}, + {null,new Point(41, 156),new Point(77, 156), new Point(112, 156),new Point(147, 156), new Point(182, 156),new Point(217, 156),new Point(252, 156),new Point(287, 156),null}, + {null,new Point(25, 190),new Point(60, 190),new Point(95, 190),new Point(130, 190),new Point(165, 190),new Point(200, 190), new Point(235, 190),new Point(270, 190),new Point(305, 190),null}, + {null,new Point(41, 224),new Point(77, 224), new Point(112, 224),new Point(147, 224),new Point(182, 224),new Point(217, 224),new Point(252, 224),new Point(287, 224),null}, + {null,new Point(60, 258),new Point(95, 258),new Point(130, 258),new Point(165, 258),new Point(200, 258),new Point(235, 258),new Point(270, 258),null}, + {null,new Point(77, 290),new Point(112, 290),new Point(147, 290),new Point(182, 290),new Point(217, 290),new Point(252, 290),null}, + {null,new Point(95, 325),new Point(130, 325),new Point(165, 325),new Point(200, 325),new Point(235, 325),null}, + {null,null,null,null,null,null} + }; + + +/** + * cette methode definie les regles au debut d'une partie + * @param r + */ + public Hexagone(Coups r) + { + + regle=r; + init(); + + } + /** + * cette methode initiale les differents acteurs d'une nouvelle partie donc les trou, poids, les boules des joueurs + */ + public void init() + { + initTrou(); + initPoids(); + initVoisinage(); + //afficher(); + initBoulej1j2(); + initBoule(); + } + /** + * elle initiale une partie sur la table + */ + public void nouvellePartie() + { + for(Boule [] a:bouleJoueur1) + for(Boule d:a) + d.setTrou(d.getTrou()); + for(Boule [] a:bouleJoueur2) + for(Boule d:a) + d.setTrou(d.getTrou()); + } + + public int getNbSelect() + { + return nbSelect; + } + + + public void setNbSelect(int nbSelect) { + this.nbSelect = nbSelect; + if(nbSelect==0) + { + for(Boule v:pion) + { + this.NotifyObserver(false, v.getIdBoule()); //deselectionne les boules + } + pion.removeAll(pion); + } + } + public Joueur getJoueurAt(int i) + { + return joueurs[i]; + } + public Trou getTrouAt(int i,int j) + { + return toute[i][j]; + } + public void initBoulej1j2() + { + bouleJoueur1[0]=new Boule[5]; + bouleJoueur1[1]=new Boule[6]; + bouleJoueur1[2]=new Boule[3]; + bouleJoueur2[0]=new Boule[5]; + bouleJoueur2[1]=new Boule[6]; + bouleJoueur2[2]=new Boule[3]; + } + + //creer les trou + /** + * cette methode creee les differents trous + */ + public void initTrou() + { + toute[0]=new Trou[6]; + toute[1]=new Trou[7]; + toute[2]=new Trou[8]; + toute[3]=new Trou[9]; + toute[4]=new Trou[10]; + toute[5]=new Trou[11]; + toute[6]=new Trou[10]; + toute[7]=new Trou[9]; + toute[8]=new Trou[8]; + toute[9]=new Trou[7]; + toute[10]=new Trou[6]; + for(int i=0;i0) + return a; + else + return (-a); + } + + @Override + public void addObservateur(Observateur obs) { + list.add(obs); + + } + + + @Override + public void delObserver() { + + list.removeAll(list); + } + + public void jouer() + { + if(tour.equals(joueurs[0])) + { + tour=joueurs[1]; + NotifyObserver("pause","play",joueurs[0].getNBout(),joueurs[1].getNBout()); + } + else + { + tour=joueurs[0]; + NotifyObserver("play","pause",joueurs[0].getNBout(),joueurs[1].getNBout()); + } + } + /** + * creer un tableau de boule pour j1 + * @return bouleJouer1 + */ + public Boule [][] BouleJoueur1() { + return bouleJoueur1; + } + public void setBouleJoueur1(Boule [][] bouleJoueur1) { + this.bouleJoueur1 = bouleJoueur1; + } + /** + *creer un tableau de boule pour j2 + * @return bouleJouer2 + */ + public Boule [][] bouleJoueur2() { + return bouleJoueur2; + } + public void setBouleJoueur2(Boule [][] bouleJoueur2) { + this.bouleJoueur2 = bouleJoueur2; + } + @Override + public void NotifyObserver(boolean l, boolean a, Point b, int c) + { + for(Observateur a1:list) + { + a1.update(l,a,b,c); + } + + } + @Override + public void NotifyObserver(boolean a,int id) { + + for(Observateur a1:list) + { + a1.update(a,id); + } + } + + public Boule getBouleByID(int id) + { + for(Boule [] t:bouleJoueur1) + { + for(Boule a:t) + if(a.getIdBoule()==id) + return a; + + } + for(Boule [] t:bouleJoueur2) + { + for(Boule a:t) + if(a.getIdBoule()==id) + return a; + + } + + + return null; + + } + + public Trou getTrouByID(int id) + { + for(Trou [] t:toute) + { + for(Trou a:t) + if(a.getIdTrou()==id) + return a; + + } + return null; + } + + public ArrayList getPion() { + return pion; + } + + + + @Override + public void NotifyObserver(String a,String b,int a1,int b1) { + for(Observateur a11:list) + { + a11.update(a,b,a1,b1); + } + + } + + +} + + + diff --git a/com.abalone_jeu.Model/Joueur.java b/com.abalone_jeu.Model/Joueur.java new file mode 100644 index 0000000..7a39094 --- /dev/null +++ b/com.abalone_jeu.Model/Joueur.java @@ -0,0 +1,562 @@ +package com.abalone_jeu.Model; + +import java.awt.Color; +import java.awt.Point; +import java.util.ArrayList; +import java.util.Random; + +public class Joueur { + private static int cpteur=0; + private int idJoueur; + private Color couleur; + private int nBout=0; //nombre de boule du joueur stant deja sorti + private Boule [][] mesBoules=new Boule[3][]; + private boolean iaJoueur; //savoir si c'est l'ordi ou pas + private int niveau=1; //si c'est l'ordi,quel est son niveau de difficulte + private static Hexagone tableDjeu; + private Joueur adversaire; + private int poidJoueur; //somme ds poidsds trou ou st place boule,permet d savoir kel joueur a l'avantag + public static Boule bP=null; //best pion a deplacer + public static int bD=-20; //best deplacement + private int bTD=-20; //best type de deplacement + private int fP=-20; //profondeur coups en fleche + private int dF=-20; //direction ds voisin pr le deplacement en fleche + + + + public Boule locate(int id) + { + for(int i=0;i0 && tableDjeu.nbSelect<3) ) + { + if(tableDjeu.pion.contains(locate(id))) + { + //System.out.println("ote"); + tableDjeu.pion.remove(locate(id)); + tableDjeu.nbSelect--; + tableDjeu.NotifyObserver(false, id); + return true; + } + else + { + //on ajoute et on verifie l'alignement + tableDjeu.pion.add(locate(id)); + tableDjeu.nbSelect++; + if(!alignement()) + { + tableDjeu.pion.remove(locate(id)); + tableDjeu.nbSelect--; + //System.out.println("les boules ne sont pas aligne ou ne sont pas du meme joueur"); + return false; + } + else + { + tableDjeu.NotifyObserver(true, id); + + //System.out.println("les boules st alignes"); + return true; + } + + } + + + } + else if(tableDjeu.nbSelect==3) + { + if(tableDjeu.pion.contains(locate(id))) + { + //System.out.println("ote"); + tableDjeu.pion.remove(locate(id)); + tableDjeu.nbSelect--; + tableDjeu.NotifyObserver(false, id); + return true; + } + else + { + //System.out.println("nombre max de boule atteint"); + return false; + + } + } + return false; + + } + + public Joueur getAdversaire() { + return adversaire; + } + + + + public void setAdversaire(Joueur adversaire) { + this.adversaire = adversaire; + } + + + public Joueur(Color couleur,boolean ia,Hexagone b,Boule [][] a) + { + iaJoueur=ia; + idJoueur=cpteur; + cpteur++; + setTableDjeu(b); + this.couleur=couleur; + mesBoules=a; + initBouleAttribute(); + } + + + + public int getIdJoueur() { + return idJoueur; + } + + + public void initBouleAttribute() + { + for(int i=0;i coups=new ArrayList(); + ArrayList depCordonee=new ArrayList(); + for(int i=0;imeilleurEval) + { + meilleurEval=evalCoups; + coups=new ArrayList(); + depCordonee=new ArrayList(); + coups.add(depart.getBoule()); + depCordonee.add(new Point(direction,tD)); + + + } + else if(evalCoups==meilleurEval) + { + coups.add(depart.getBoule()); + depCordonee.add(new Point(direction,tD)); + + } + + + + } + Random rnd = new Random(); + int n=rnd.nextInt(coups.size()); + System.out.println(n); + bP= coups.get(n); + bTD=depCordonee.get(n).y; + bD=depCordonee.get(n).x; + if(bTD==-1) + { + int pF=-20; + + for(int df=0;df<6 && df!=bD;df++) + { + pF=tableDjeu.testFleche(bP.getTrou(), bD, df); + if(pF!=-20) + { + if(pF==2) + { + fP=2; + dF=df; + return; + + } + else + { + + fP=3; + dF=df; + return; + + } + } + } + + } + } + + public int minValue(Joueur j1,int alpha,int beta,int profondeur) + { + if(profondeur==0) + return tableDjeu.fctEval(j1); + + for(int i=0;i=beta) + { + return alpha; + } + + + } + } + + + return beta; + } + + + + public int maxValue(Joueur j1,int alpha,int beta,int profondeur) + { + if(profondeur==0) + return tableDjeu.fctEval(j1); + + for(int i=0;i=beta) + { + return beta; + } + + + + } + } + + return alpha; + } + + + +public void calculCoup() +{ + int n=(this.niveau); + meilleurCoups(n); + if(fP!=-20 && bTD==-1) + { + Trou s=bP.getTrou().voisinage[dF]; + if(fP==2) + { + tableDjeu.joue(s.getBoule(),bD,bTD); + fP=-20; + } + else if(fP==3) + { + + tableDjeu.joue(s.getBoule(),bD,bTD); + tableDjeu.joue(s.voisinage[dF].getBoule(),bD,bTD); + fP=-20; + } + + } + + +} + +public Boule getBouleAt(int i,int j) +{ + return mesBoules[i][j]; +} +public boolean isIaJoueur() { + return iaJoueur; +} + + + +public int getNiveau() { + return niveau; +} + + + +public void setNiveau(int niveau) { + this.niveau = niveau; +} + + + +public void setIaJoueur(boolean iaJoueur) { + this.iaJoueur = iaJoueur; +} + +public Hexagone getTable() +{ + return tableDjeu; +} + + + + +public boolean alignement() +{ + boolean result=false; + int direction=-1; + for(int j=0;j<6;j++)//la 2em boule doit etr dan l'un des voisin,de mm proprietair k la boule selectione et de mm couleur + { + if((tableDjeu.pion.get(1).getTrou().equals(tableDjeu.pion.get((0)).getTrou().voisinage[j])) && (tableDjeu.pion.get(1).getColor()==tableDjeu.pion.get((0)).getColor())) + { + result=true; + direction=j; + + } + } + if(result==true && tableDjeu.nbSelect==3) //si le 1er test est vrai on verifie que la 3eme est voisin de la 2em dan la mm direction ou voisin de la 1ere boule dan la direction oppose + { + result=false; + if(direction==0 || direction==1 || direction==2) + { + if((tableDjeu.pion.get(2).getTrou().equals(tableDjeu.pion.get((1)).getTrou().voisinage[direction])) && (tableDjeu.pion.get(2).getColor()==tableDjeu.pion.get((1)).getColor()) + || (tableDjeu.pion.get(2).getTrou().equals(tableDjeu.pion.get((0)).getTrou().voisinage[(direction+3)])) && (tableDjeu.pion.get(2).getColor()==tableDjeu.pion.get((0)).getColor())) + result=true; + } + else + { + if((tableDjeu.pion.get(2).getTrou().equals(tableDjeu.pion.get((1)).getTrou().voisinage[direction])) && (tableDjeu.pion.get(2).getColor()==tableDjeu.pion.get((1)).getColor()) + || (tableDjeu.pion.get(2).getTrou().equals(tableDjeu.pion.get((0)).getTrou().voisinage[abs(direction-3)])) && (tableDjeu.pion.get(2).getColor()==tableDjeu.pion.get((0)).getColor())) + result=true; + } + + } + return result; + + } + +public static boolean testFleche2(int dir) +{ + for(Boule a:tableDjeu.pion) + { + if(tableDjeu.regle.getDeplacement(a.getTrou(), dir)!=-1) + return false; + } + return true; +} + + + +public int abs(int i) { + if(i<0) + return -i; + else + return i; +} + +//qui realise le deplacement si celui ci est possible. +public static boolean deplacer(Boule b,int direction) +{ + boolean done=true; + switch(tableDjeu.regle.getDeplacement(b.getTrou(),direction)) + { + case -1:/*System.out.println("je joue la boule "+b.getIdBoule()+" se trouvant dans le trou "+b.getTrou().getIdTrou()+" en deplacer_1")*/;tableDjeu.regle.deplacer_1(b,direction);break; + case -2:/*System.out.println("je joue la boule "+b.getIdBoule()+" se trouvant dans le trou "+b.getTrou().getIdTrou()+" en deplacer_2")*/;tableDjeu.regle.deplacer_2(b,direction);break; + case -3:/*System.out.println("je joue la boule "+b.getIdBoule()+" se trouvant dans le trou "+b.getTrou().getIdTrou()+" en deplacer_3")*/;tableDjeu.regle.deplacer_3(b,direction);break; + case -4:/*System.out.println("je joue la boule "+b.getIdBoule()+" se trouvant dans le trou "+b.getTrou().getIdTrou()+" en pousser_2_1")*/;tableDjeu.regle.pousser_2_1(b,direction);break; + case -5:/*System.out.println("je joue la boule "+b.getIdBoule()+" se trouvant dans le trou "+b.getTrou().getIdTrou()+" en pousser_3_1")*/;tableDjeu.regle.pousser_3_1(b,direction);break; + case -6:/*System.out.println("je joue la boule "+b.getIdBoule()+" se trouvant dans le trou "+b.getTrou().getIdTrou()+" en pousser_3_2")*/;tableDjeu.regle.pousser_3_2(b,direction);break; + case -7:/*System.out.println("je joue la boule "+b.getIdBoule()+" se trouvant dans le trou "+b.getTrou().getIdTrou()+" en manger_2_1")*/;tableDjeu.regle.manger_2_1(b,direction);break; + case -8:/*System.out.println("je joue la boule "+b.getIdBoule()+" se trouvant dans le trou "+b.getTrou().getIdTrou()+" en manger_3_1")*/;tableDjeu.regle.manger_3_1(b,direction);break; + case -9:/*System.out.println("je joue la boule "+b.getIdBoule()+" se trouvant dans le trou "+b.getTrou().getIdTrou()+" en manger_3_2")*/;tableDjeu.regle.manger_3_2(b,direction);break; + case -20:tableDjeu.regle.Bloquer();/*System.out.println("bloquer")*/;done=false;break; + default: tableDjeu.regle.Bloquer();/*System.out.println("bloquer")*/;done=false;break; + } + + return done; +} + + + + +public void setTableDjeu(Hexagone table) { + tableDjeu = table; +} + +} + + diff --git a/com.abalone_jeu.Model/Partie.java b/com.abalone_jeu.Model/Partie.java new file mode 100644 index 0000000..9c8fda6 --- /dev/null +++ b/com.abalone_jeu.Model/Partie.java @@ -0,0 +1,26 @@ +package com.abalone_jeu.Model; + +import java.awt.Color; + +public class Partie { + public Hexagone table; + public Joueur j1; + public Joueur j2; + + /** + * cette methode creer une nouvelle partie voir tableau de duel + */ + public Partie() + { + table=new Hexagone(new Coups()); + j1=new Joueur(Color.BLUE,false,table,table.BouleJoueur1()); + j2=new Joueur(Color.PINK,false,table,table.bouleJoueur2()); + j1.setAdversaire(j2); + j2.setAdversaire(j1); + Joueur [] j=new Joueur[2]; + j[0]=j1; + j[1]=j2; + table.setJoueurs(j); + } + +} diff --git a/com.abalone_jeu.Model/Trou.java b/com.abalone_jeu.Model/Trou.java new file mode 100644 index 0000000..042374e --- /dev/null +++ b/com.abalone_jeu.Model/Trou.java @@ -0,0 +1,110 @@ +package com.abalone_jeu.Model; + +import java.awt.Point; + +public class Trou{ + private static int num=0; + private int idTrou; + private boolean occupied; + private Boule boule; + public Trou[] voisinage=new Trou[6]; //6 directions permises pour le deplacement d'un pion + private int poid; //Un poids qui permettra d'evaluer un coup par rapport e un autre + private boolean bord; //pour savoir s'il s'agit d'une cellule bord de l'hexagone + private Point PositionTrou; //coordonnee du trou + + public Trou(boolean a) + { + super(); + bord=a; + + } + /** + * verifie si le trou est occupé + */ + public Trou() + { + idTrou=num; + num++; + occupied=false; + } + public Boule getBoule() + { + return boule; + } + public void setBoule(Boule b) + { + if(b!=null) + { + this.setOccupied(true); + } + if(bord==false) + boule=b; + + } + + public boolean getOccupied() //but:savoir si le trou est occupe ou pas + { + return occupied; + } + public void setOccupied(boolean a) //but:changer le statu du trou avec ue valeur + { + occupied=a; + } + + + public void setVoisinage(Trou[] voisinage) + { + this.voisinage = voisinage; + } + public boolean getBord() { //on veut savoir si le trou est un bord ou pas + return bord; + } + public void setBord(boolean bord) { + this.bord = bord; + } + public int getPoid() { + return poid; + } + public void setPoid(int poid) { + this.poid = poid; + } + public static int getNum() { + return num; + } + public static void setNum(int num) { + Trou.num = num; + } + public int getIdTrou() { + return idTrou; + } + public void setIdTrou(int idTrou) { + this.idTrou = idTrou; + } + /** + * @return le positionTrou + */ + public Point getPositionTrou() { + return PositionTrou; + } + /** + * @param positionTrou le positionTrou e definir + */ + public void setPositionTrou(Point positionTrou) { + PositionTrou = positionTrou; + } + public Trou[] getVoisinage() { + return voisinage; + } + + + public Point getPosition() { + return PositionTrou; + } + + public void setPosition(Point position) { + PositionTrou = position; + } + + + +} diff --git a/uml/com.abalone.jeu.vpp b/uml/com.abalone.jeu.vpp new file mode 100644 index 0000000..eccbee3 Binary files /dev/null and b/uml/com.abalone.jeu.vpp differ diff --git a/uml/com.abalone.jeu.vpp.bak_000f b/uml/com.abalone.jeu.vpp.bak_000f new file mode 100644 index 0000000..6dfa959 Binary files /dev/null and b/uml/com.abalone.jeu.vpp.bak_000f differ diff --git a/uml/com.abalone.jeu.vpp.bak_001d b/uml/com.abalone.jeu.vpp.bak_001d new file mode 100644 index 0000000..9ba2cd4 Binary files /dev/null and b/uml/com.abalone.jeu.vpp.bak_001d differ diff --git a/uml/com.abalone.jeu.vpp.bak_002d b/uml/com.abalone.jeu.vpp.bak_002d new file mode 100644 index 0000000..5d5e4e5 Binary files /dev/null and b/uml/com.abalone.jeu.vpp.bak_002d differ diff --git a/uml/com.abalone.jeu.vpp.bak_003d b/uml/com.abalone.jeu.vpp.bak_003d new file mode 100644 index 0000000..6c76f85 Binary files /dev/null and b/uml/com.abalone.jeu.vpp.bak_003d differ diff --git a/uml/uml1.JPG b/uml/uml1.JPG new file mode 100644 index 0000000..7ceeefa Binary files /dev/null and b/uml/uml1.JPG differ diff --git a/uml2.JPG b/uml/uml2.JPG similarity index 100% rename from uml2.JPG rename to uml/uml2.JPG diff --git a/uml/uml3.JPG b/uml/uml3.JPG new file mode 100644 index 0000000..319897c Binary files /dev/null and b/uml/uml3.JPG differ diff --git a/uml/uml4.JPG b/uml/uml4.JPG new file mode 100644 index 0000000..f58129e Binary files /dev/null and b/uml/uml4.JPG differ diff --git a/uml/uml5.JPG b/uml/uml5.JPG new file mode 100644 index 0000000..de1d7cc Binary files /dev/null and b/uml/uml5.JPG differ