Skip to content

Commit

Permalink
Renamed things in French; fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelgamix committed May 8, 2017
1 parent b852da1 commit b14bd72
Show file tree
Hide file tree
Showing 20 changed files with 708 additions and 616 deletions.
87 changes: 49 additions & 38 deletions src/diaballik/Diaballik.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package diaballik;

import diaballik.controller.ActionsController;
import diaballik.controller.AffichageController;
import diaballik.controller.TerrainController;
import diaballik.controleur.ActionsControleur;
import diaballik.controleur.AffichageControleur;
import diaballik.controleur.TerrainControleur;
import diaballik.model.ConfigurationPartie;
import diaballik.model.Jeu;
import diaballik.model.Joueur;
import diaballik.model.Terrain;
import diaballik.view.CaseView;
import diaballik.view.Dialogs;
import diaballik.vue.CaseVue;
import diaballik.vue.Dialogs;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
Expand All @@ -28,14 +29,17 @@
public class Diaballik extends Application {
public Stage stage;

public final static String CSS_MENU_FILE = "DiaballikMenu.css";
public final static String CSS_JEU_FILE = "DiaballikJeu.css";
public final static String CSS_DIALOG_FILE = "DiaballikDialogs.css";
private final static String CSS_MENU = "DiaballikMenu.css";
private final static String CSS_JEU = "DiaballikJeu.css";
public final static String CSS_DIALOG = "DiaballikDialogs.css";

public final static String SAVES_DIRECTORY = "saves";
public final static String DOSSIER_SAUVEGARDES = "saves";
public final static String DOSSIER_TERRAINS = "defaultTerrains";

private final KeyCombination ctrlS = new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN); // save
private final KeyCombination ctrlZ = new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN); // rollback
public final static String NOM_JEU = "Diaballik";

private final KeyCombination ctrlS = new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN); // sauvegarde
private final KeyCombination ctrlZ = new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN); // actionAnnuler

private Scene sceneJeu;
private Scene sceneMenu;
Expand All @@ -50,69 +54,68 @@ public void showSceneMenu() {
stage.setScene(sceneMenu);
}

public void newGame() {
Optional<ConfigurationPartie> cp = Dialogs.showNewGameDialog();
private void nouveauJeu() {
Optional<ConfigurationPartie> cp = Dialogs.montrerDialogNouvellePartie();
if (cp.isPresent()) {
initSceneJeu(cp.get());
showSceneJeu();
}
}

public void newGame(String path, boolean isSave) {
private void nouveauJeu(String path, boolean isSave) {
ConfigurationPartie cp = new ConfigurationPartie(path, isSave);
initSceneJeu(cp);
showSceneJeu();
}

public void endGame(Joueur gagnant, int victoireType) {
Dialogs.showEndGame(gagnant, victoireType);
public void finJeu(Joueur gagnant, int victoireType) {
Dialogs.montrerFinJeu(gagnant, victoireType);

showSceneMenu();
}

public void exit() {
public void terminer() {
Platform.exit();
}

private void initSceneJeu(ConfigurationPartie cp) {
jeu = new Jeu(cp, this);

TerrainController terrainController = new TerrainController(this);
ActionsController actionsController = new ActionsController(this);
AffichageController affichageController = new AffichageController(this);
TerrainControleur terrainControleur = new TerrainControleur(this);
ActionsControleur actionsControleur = new ActionsControleur(this);
AffichageControleur affichageControleur = new AffichageControleur(this);
BorderPane root = new BorderPane();

root.setCenter(terrainController.getTerrainView());
root.setRight(actionsController.getActionsView());
root.setTop(affichageController.getAffichageView());
root.setCenter(terrainControleur.getTerrainVue());
root.setRight(actionsControleur.getActionsVue());
root.setTop(affichageControleur.getAffichageVue());

sceneJeu = new Scene(root, CaseView.LARGEUR * Terrain.LARGEUR + 225, CaseView.HAUTEUR * Terrain.HAUTEUR + 75);
sceneJeu = new Scene(root, CaseVue.LARGEUR * Terrain.LARGEUR + 225, CaseVue.HAUTEUR * Terrain.HAUTEUR + 75);
sceneJeu.setOnKeyPressed(k -> {
if (ctrlS.match(k)) {
actionsController.saveGame(SAVES_DIRECTORY);
actionsControleur.actionSauvegarderJeu(DOSSIER_SAUVEGARDES);
} else if (ctrlZ.match(k)) {
actionsController.rollback();
actionsControleur.actionAnnuler();
}
});
sceneJeu.getStylesheets().add(getClass().getResource(CSS_JEU_FILE).toExternalForm());
sceneJeu.getStylesheets().add(getClass().getResource(CSS_JEU).toExternalForm());
}
private void initSceneMenu() {
BorderPane root = new BorderPane();
VBox vBox = new VBox(10);
vBox.setAlignment(Pos.CENTER);

// TODO: séparer menuScene dans une autre classe

Label titre = new Label("Diaballik");
Label titre = new Label(NOM_JEU);
titre.setPadding(new Insets(0, 0, 25, 0));

Button newGame = new Button("Nouvelle partie");
newGame.setOnAction(e -> newGame());
newGame.setOnAction(e -> nouveauJeu());

Button loadGame = new Button("Charger une partie");
loadGame.setOnAction(e -> {
Optional<String> ofilename = Dialogs.showLoadName(SAVES_DIRECTORY);
ofilename.ifPresent(s -> newGame(SAVES_DIRECTORY + "/" + s, true));
Optional<String> ofilename = Dialogs.montrerDialogChoisirFichier(DOSSIER_SAUVEGARDES);
if (ofilename != null)
ofilename.ifPresent(s -> nouveauJeu(DOSSIER_SAUVEGARDES + "/" + s, true));

// Méthode avec Filechooser
// Plus souple mais complexifie le choix pour l'utilisateur
Expand All @@ -121,18 +124,18 @@ private void initSceneMenu() {
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Diaballik sauvegarde", "*.txt"));
File file = fileChooser.showOpenDialog(stage);
if (file != null) {
newGame(file.getAbsolutePath(), true);
nouveauJeu(file.getAbsolutePath(), true);
}*/
});

Button regles = new Button("Règles");
regles.setOnAction(e -> getHostServices().showDocument("http://inf362.forge.imag.fr/Projet/Regles/diaballik/"));

Button credits = new Button("Crédits");
credits.setOnAction(e -> Dialogs.showCredits());
credits.setOnAction(e -> Dialogs.montrerCredits());

Button quitter = new Button("Quitter");
quitter.setOnAction(e -> exit());
quitter.setOnAction(e -> terminer());

vBox.getChildren().add(titre);
vBox.getChildren().add(newGame);
Expand All @@ -146,7 +149,7 @@ private void initSceneMenu() {
Platform.runLater(root::requestFocus);

sceneMenu = new Scene(root, 600, 400);
sceneMenu.getStylesheets().add(getClass().getResource(CSS_MENU_FILE).toExternalForm());
sceneMenu.getStylesheets().add(getClass().getResource(CSS_MENU).toExternalForm());
}

@Override
Expand All @@ -155,7 +158,7 @@ public void start(Stage primaryStage) throws Exception {

initSceneMenu();

stage.setTitle("Diaballik");
stage.setTitle(NOM_JEU);
stage.setResizable(false);
stage.setScene(sceneMenu);
stage.show();
Expand All @@ -172,4 +175,12 @@ public Jeu getJeu() {
public Scene getSceneJeu() {
return sceneJeu;
}

public void setCurseurSelection(Scene scene) {
scene.setCursor(Cursor.HAND);
}

public void setCurseurNormal(Scene scene) {
scene.setCursor(Cursor.DEFAULT);
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
package diaballik.controller;
package diaballik.controleur;

import diaballik.Diaballik;
import diaballik.model.Jeu;
import diaballik.view.ActionsView;
import diaballik.view.Dialogs;
import diaballik.vue.ActionsVue;
import diaballik.vue.Dialogs;
import javafx.stage.FileChooser;

import java.io.File;

public class ActionsController {
public class ActionsControleur {
private final Jeu jeu;
private final ActionsView actionsView;
private final ActionsVue actionsVue;
private final Diaballik diaballik;

public ActionsController(Diaballik diaballik) {
public ActionsControleur(Diaballik diaballik) {
this.diaballik = diaballik;
this.jeu = diaballik.getJeu();
this.actionsView = new ActionsView(this);
this.actionsVue = new ActionsVue(this);
}

public Jeu getJeu() {
return jeu;
}

public ActionsView getActionsView() {
return actionsView;
public ActionsVue getActionsVue() {
return actionsVue;
}

public void menu() {
if (Dialogs.confirmByDialog("Vous allez quitter le jeu. La partie sera perdue. Voulez-vous continuer?")) {
public void actionMenu() {
if (Dialogs.dialogConfirmation("Vous allez quitter le jeu. La partie sera perdue. Voulez-vous continuer?")) {
diaballik.showSceneMenu();
}
}

public void saveGame(String directory) {
public void actionSauvegarderJeu(String directory) {
String filename;
final FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(new File(directory));
Expand All @@ -45,16 +45,16 @@ public void saveGame(String directory) {
if (!filename.endsWith(".txt"))
filename += ".txt";

System.out.println("Save to " + filename);
this.jeu.save(filename);
System.out.println("Sauvegarde vers " + filename);
this.jeu.sauvegarde(filename);
}
}

public void antijeu() {
public void actionAntijeu() {
System.out.println("Antijeu : " + jeu.antijeu());
}

public void rollback() {
jeu.rollback();
public void actionAnnuler() {
jeu.annuler();
}
}
26 changes: 26 additions & 0 deletions src/diaballik/controleur/AffichageControleur.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package diaballik.controleur;

import diaballik.Diaballik;
import diaballik.model.Jeu;
import diaballik.vue.AffichageVue;

public class AffichageControleur {
private final Diaballik diaballik;

private final Jeu jeu;
private final AffichageVue affichageVue;

public AffichageControleur(Diaballik diaballik) {
this.diaballik = diaballik;
this.jeu = diaballik.getJeu();
this.affichageVue = new AffichageVue(this);
}

public Jeu getJeu() {
return jeu;
}

public AffichageVue getAffichageVue() {
return affichageVue;
}
}
Loading

0 comments on commit b14bd72

Please sign in to comment.