Skip to content

Commit

Permalink
Correction of new tiles generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Reiji7 committed Dec 7, 2019
1 parent 1211631 commit 94ad2b9
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 210 deletions.
2 changes: 1 addition & 1 deletion src/application/Main_Terminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static void main(final String[] args) {
break;
case "l":
case "load":
System.out.print("Saisir le chemin de la sauvegarde : \t\t");
System.out.print("Saisir le chemin de la sauvegarde : \t");
g.load(sc.nextLine());
break;
default:
Expand Down
31 changes: 22 additions & 9 deletions src/model/Etat.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,68 +28,80 @@ public class Etat {
private int scoreMax;
private int scoreGrid;

public Etat() { //constructeurs
}
public Etat() {}
public Etat(Grids ensemble, String deplacement) {
this.ensemble = new Grids(ensemble);
this.deplacement = deplacement;
this.scoreMax = ensemble.best();
this.scoreGrid = ensemble.scoreTotalGrille();
}


public Etat(Etat ee) {
this.ensemble = new Grids(ee.getGrids());
this.deplacement = ee.getDeplacement();
this.scoreMax = ee.getScoreMax();
this.scoreGrid = ee.getScoreGrid();
}


/*public String toString() {
return "Ensemble grille : " + this.ensemble + " deplacmeent : " + this.deplacement + " score Max : " + this.scoreMax + " score Grid : " + this.scoreGrid;
}*/


//getteurs et setteurs
public Grids getGrids() {
return this.ensemble;
}


public String getDeplacement() {
return this.deplacement;
}


public int getScoreMax() {
return this.scoreMax;
}


private int getScoreGrid() {
return this.scoreGrid;
}


public void setEnsembleGrile(Grids ensemble) {
this.ensemble = ensemble;
}


public void setDeplacement(String dep) {
this.deplacement = dep;
}


public void setScoreMax(int _scoreMax) {
this.scoreMax = _scoreMax;
}


//méthodes
public boolean estbut(Probleme pb) { //teste si l'état est égal à l'état but du problème
return (pb.getGrids().best() == GOAL);
}


public boolean estegal(Etat e) {
return this.ensemble == e.getGrids() && this.deplacement.equals(e.getDeplacement());
}


/*public void affiche() {
System.out.println(this.ensemble + " " + this.deplacement + " " + this.scoreMax);
}*/


// applique une action a à l'état courant. Le probleme est passé en paramètre pour connaitre la contenance maximale de chaque cruche
public Etat AppliqueAction(Action a, Grids grids) {
Etat e;
Expand Down Expand Up @@ -145,43 +157,44 @@ public Etat AppliqueAction(Action a, Grids grids) {
return (e);
}


private boolean valide(String direction) {
boolean valide = false;
int indice = 0;
if (direction.equals("d")) {
while (!valide && indice < this.ensemble.getGrids().length) {
valide = this.ensemble.right2(this.ensemble.getGrids()[indice]);
valide = this.ensemble.right(this.ensemble.getGrids()[indice]);
indice++;
}
} else if (direction.equals("q")) {
while (!valide && indice < this.ensemble.getGrids().length) {
valide = this.ensemble.left2(this.ensemble.getGrids()[indice]);
valide = this.ensemble.left(this.ensemble.getGrids()[indice]);
indice++;
}
} else if (direction.equals("z")) {
while (!valide && indice < this.ensemble.getGrids().length) {
valide = this.ensemble.up2(this.ensemble.getGrids()[indice]);
valide = this.ensemble.up(this.ensemble.getGrids()[indice]);
indice++;
}
} else if (direction.equals("s")) {
while (!valide && indice < this.ensemble.getGrids().length) {
valide = this.ensemble.down2(this.ensemble.getGrids()[indice]);
valide = this.ensemble.down(this.ensemble.getGrids()[indice]);
indice++;
}
} else if (direction.equals("r")) {
this.ensemble.reorganization(this.ensemble.getGrids());
while (!valide && indice < this.ensemble.getGrids().length) {
valide = this.ensemble.down2(this.ensemble.getGrids()[indice]);
valide = this.ensemble.down(this.ensemble.getGrids()[indice]);
indice++;
}
} else {
this.ensemble.reorganization(this.ensemble.getGrids());
while (!valide && indice < this.ensemble.getGrids().length) {
valide = this.ensemble.up2(this.ensemble.getGrids()[indice]);
valide = this.ensemble.up(this.ensemble.getGrids()[indice]);
indice++;
}
}
return valide;
}

} // fin classe
}
18 changes: 10 additions & 8 deletions src/model/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
package model;
import java.io.Serializable;


@SuppressWarnings("serial")
public class Grid extends Movable implements Serializable{

/**
Expand Down Expand Up @@ -56,16 +58,16 @@ public boolean lose() {

Tile[] tampon = copy();

control[0] = left(true, this);
control[0] = left(this);
override(tampon);

control[1] = right(true, this);
control[1] = right(this);
override(tampon);

control[2] = up(true, this);
control[2] = up(this);
override(tampon);

control[3] = down(true, this);
control[3] = down(this);
override(tampon);

for (boolean b: control) {
Expand Down Expand Up @@ -137,16 +139,16 @@ public boolean move(int _d) {
switch (_d) {

case LEFT:
return left(false, this);
return left(this);

case RIGHT:
return right(false, this);
return right(this);

case UP:
return up(false, this);
return up(this);

case DOWN:
return down(false, this);
return down(this);

default:
System.out.println("Erreur de déplacement");
Expand Down
8 changes: 6 additions & 2 deletions src/model/Grids.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.Serializable;
import java.util.Calendar;

@SuppressWarnings("serial")
public class Grids extends Movable implements Serializable {

private Grid grids[];
Expand Down Expand Up @@ -122,7 +123,7 @@ public boolean move(int _d) {
if(_d == FRONT) {
Grid tamp[] = reorganization(this.grids);
verif[index] = tamp[index].move(DOWN);
//on remet la matrice dans le bon sens
//on remet la matrice dans le bon sens
setGrids(reorganization(reorganization(reorganization(tamp))));
}
else if(_d == BACK) {
Expand All @@ -138,20 +139,23 @@ else if(_d == BACK) {

for (boolean b : verif) {
if (b) {
newTile(getGrids());
victory();
lose();
this.affichage();
return true;
}
}

return false;
}


public Grid[] getGrids() {
return this.grids;

}


private void setGrids(Grid[] _gs) {
this.grids =_gs;
}
Expand Down
Loading

0 comments on commit 94ad2b9

Please sign in to comment.