Skip to content

Commit

Permalink
Fixed bug in affichageView; history now saves
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelgamix committed May 6, 2017
1 parent 8f661fc commit 2a995b9
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 23 deletions.
6 changes: 4 additions & 2 deletions src/diaballik/DiaballikJeu.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@
.couleurMarquage {
-fx-fill: linear-gradient(to bottom right, #ebeb00, #cdcd00);
-fx-background-color: linear-gradient(to bottom right, #ebeb00, #cdcd00);
-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.3), 10, 0, 0, 0);
}

.couleurAdversaire {
-fx-fill: linear-gradient(to bottom right, #5f5f5f, #414141);
}

.couleurSurvol {
-fx-fill: #8059ff;
-fx-background-color: #8059ff;
-fx-fill: linear-gradient(to bottom right, #7857eb, #6752cd);
-fx-background-color: linear-gradient(to bottom right, #7857eb, #6752cd);
-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.5), 20, 0, 0, 0);
}
33 changes: 21 additions & 12 deletions src/diaballik/controller/TerrainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,25 @@ public void mouseClicked(Point point) {
if (caseCliquee.getPion() != null && caseCliquee.getPion().getCouleur() == this.jeu.getJoueurActuel().getCouleur()) {
this.caseSelectionne = caseCliquee;
this.caseSelectionne.getPion().setSelectionne(true);
if (!caseCliquee.getPion().aLaBalle()) {
casesMarquees = jeu.getDeplacementsPossibles(caseCliquee.getPion());
for (Case c : casesMarquees) c.setMarque(true);
} else {
pionsMarques = jeu.getPassesPossibles(caseCliquee.getPion());
for (Pion p : pionsMarques) p.setMarque(true);
}
marquerAll(caseCliquee);
}
} else {
if (caseCliquee.getPion() != null) {
if (caseCliquee.getPion().getCouleur() == this.jeu.getJoueurActuel().getCouleur()) {
if (caseCliquee == this.caseSelectionne) {
this.caseSelectionne.getPion().setSelectionne(false);
finSelection();
return;
} else if (this.caseSelectionne.getPion().aLaBalle()) {
this.caseSelectionne.getPion().setSelectionne(false);
this.jeu.passe(this.caseSelectionne.getPion(), caseCliquee);
finSelection();
} else {
this.caseSelectionne.getPion().setSelectionne(false);
finSelection();
this.caseSelectionne = caseCliquee;
this.caseSelectionne.getPion().setSelectionne(true);
marquerAll(caseCliquee);
}

this.caseSelectionne.getPion().setSelectionne(false);
this.jeu.passe(this.caseSelectionne.getPion(), caseCliquee);
finSelection();
}
} else {
this.caseSelectionne.getPion().setSelectionne(false);
Expand All @@ -72,6 +71,16 @@ public void mouseClicked(Point point) {
}
}

private void marquerAll(Case caseCliquee) {
if (!caseCliquee.getPion().aLaBalle()) {
casesMarquees = jeu.getDeplacementsPossibles(caseCliquee.getPion());
for (Case c : casesMarquees) c.setMarque(true);
} else {
pionsMarques = jeu.getPassesPossibles(caseCliquee.getPion());
for (Pion p : pionsMarques) p.setMarque(true);
}
}

private void finSelection() {
this.caseSelectionne = null;
for (Case c : casesMarquees) c.setMarque(false);
Expand Down
48 changes: 40 additions & 8 deletions src/diaballik/model/Jeu.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ public Action(Pion pion, int action, Case caseAvant) {
this.caseAvant = caseAvant;
}

public Action(Jeu jeu, String s) {
String[] parts = s.split(":");
Point pointPion = new Point(parts[0]);
this.pion = jeu.getTerrain().getCaseAt(pointPion).getPion();
this.action = Integer.parseInt(parts[1]);
Point pointCaseAvant = new Point(parts[2]);
this.caseAvant = jeu.getTerrain().getCaseAt(pointCaseAvant);
}

public String getSaveString() {
StringBuilder sb = new StringBuilder();

sb.append(this.pion.getPosition().getPoint().getSaveString())
.append(":")
.append(action)
.append(":")
.append(this.caseAvant.getPoint().getSaveString());

return sb.toString();
}

public Pion getPion() {
return pion;
}
Expand Down Expand Up @@ -54,6 +75,10 @@ public String toString() {

public final static int NOMBRE_JOUEURS = 2;

public final static int CHANGED_INFOS = 1;
public final static int CHANGED_TOUR = 2;
public final static int CHANGED_ALL = 3;

public Jeu(ConfigurationPartie cp, Diaballik diaballik) {
this.diaballik = diaballik;

Expand All @@ -68,7 +93,7 @@ public Jeu(ConfigurationPartie cp, Diaballik diaballik) {

this.joueurActuel = this.getTour() - 1;

updateListeners();
updateListeners(CHANGED_ALL);
}

private void initArrivee() {
Expand Down Expand Up @@ -134,12 +159,18 @@ public void load(ConfigurationPartie cp) {

StringBuilder terrainString = new StringBuilder();
int y = 0;
while ((sCurrentLine = br.readLine()) != null && y < Terrain.HAUTEUR) {
while (y < Terrain.HAUTEUR && (sCurrentLine = br.readLine()) != null) {
terrainString.append(sCurrentLine).append("\n");
y++;
}

terrain = new Terrain(terrainString.toString());

Action a;
while ((sCurrentLine = br.readLine()) != null) { // on lit les configurations
a = new Action(this, sCurrentLine);
historique.add(a);
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
Expand All @@ -161,6 +192,7 @@ public void save(String path) {
bw.write(this.joueurs[0].getSaveString());
bw.write(this.joueurs[1].getSaveString());
bw.write(this.getTerrain().getSaveString());
for (Action a : historique) bw.write(a.getSaveString());
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -181,7 +213,7 @@ public void deplacement(Pion p, Case c) {
changerTour();
}

//updateListeners();
updateListeners(CHANGED_INFOS);
}
}

Expand Down Expand Up @@ -351,7 +383,7 @@ public void passe(Pion p, Case c) {
changerTour();
}

//updateListeners();
updateListeners(CHANGED_INFOS);
}
}

Expand Down Expand Up @@ -383,7 +415,7 @@ public void changerTour() {
this.tour++;
joueurActuel = (joueurActuel + 1 >= Jeu.NOMBRE_JOUEURS ? 0 : joueurActuel + 1);

updateListeners();
updateListeners(CHANGED_TOUR);
}

public Joueur getJoueurActuel() {
Expand All @@ -394,9 +426,9 @@ public ArrayList<Action> getHistorique() {
return historique;
}

private void updateListeners() {
private void updateListeners(Object o) {
this.setChanged();
this.notifyObservers();
this.notifyObservers(o);
}

public int getTour() {
Expand All @@ -423,7 +455,7 @@ public void rollback() {
System.err.println("Action non reconnue");
}

updateListeners();
updateListeners(CHANGED_ALL);
}

public boolean pionAllie(Pion pion) {
Expand Down
11 changes: 11 additions & 0 deletions src/diaballik/model/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ public Point(int x, int y) {
this.y = y;
}

public Point(String s) {
String parts[];
parts = s.split(";");
this.x = Integer.parseInt(parts[0]);
this.y = Integer.parseInt(parts[1]);
}

public String getSaveString() {
return this.getX() + ";" + this.getY();
}

public int getX() {
return x;
}
Expand Down
3 changes: 2 additions & 1 deletion src/diaballik/view/TerrainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public void update(Observable o, Object arg) {
for (PionView p : pions[Joueur.JOUEUR_VERT]) p.disable();
}

if (getTerrainController().diaballik.getSceneJeu() != null)
int changed_type = (arg != null ? (int)arg : 0);
if (getTerrainController().diaballik.getSceneJeu() != null && changed_type == Jeu.CHANGED_TOUR)
getTerrainController().diaballik.getSceneJeu().setCursor(Cursor.DEFAULT);
}
}

0 comments on commit 2a995b9

Please sign in to comment.