|
|
|
@ -3,23 +3,28 @@ package controller;
|
|
|
|
|
import com.jfoenix.controls.JFXButton;
|
|
|
|
|
import javafx.animation.KeyFrame;
|
|
|
|
|
import javafx.animation.Timeline;
|
|
|
|
|
import javafx.event.ActionEvent;
|
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
|
import javafx.fxml.FXMLLoader;
|
|
|
|
|
import javafx.fxml.Initializable;
|
|
|
|
|
import javafx.scene.Scene;
|
|
|
|
|
import javafx.scene.image.Image;
|
|
|
|
|
import javafx.scene.image.ImageView;
|
|
|
|
|
import javafx.scene.image.WritableImage;
|
|
|
|
|
import javafx.scene.layout.AnchorPane;
|
|
|
|
|
import javafx.scene.layout.GridPane;
|
|
|
|
|
import javafx.scene.paint.Color;
|
|
|
|
|
import javafx.scene.text.Text;
|
|
|
|
|
import javafx.stage.Stage;
|
|
|
|
|
import javafx.util.Duration;
|
|
|
|
|
import model.*;
|
|
|
|
|
import model.Case;
|
|
|
|
|
import model.GameLoop;
|
|
|
|
|
import model.GameTime;
|
|
|
|
|
import model.Map;
|
|
|
|
|
import model.ResultatTxt;
|
|
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
@ -49,6 +54,8 @@ public class GamePlayController implements Initializable {
|
|
|
|
|
private Text resultat4;
|
|
|
|
|
private Text resultat5;
|
|
|
|
|
private int nbTour = 0;
|
|
|
|
|
private int numCase = 0;
|
|
|
|
|
int l;
|
|
|
|
|
|
|
|
|
|
public int difficulty;
|
|
|
|
|
public int perso;
|
|
|
|
@ -119,7 +126,7 @@ public class GamePlayController implements Initializable {
|
|
|
|
|
resultat5.setFill(Color.WHITE);
|
|
|
|
|
resultat5.setStyle("-fx-font: 20 arial; ");
|
|
|
|
|
button = new JFXButton("");
|
|
|
|
|
levelRoot.getChildren().addAll(text,textTimer,textEnd,button, resultat1, resultat2, resultat3, resultat4, resultat5);
|
|
|
|
|
levelRoot.getChildren().addAll(text,textTimer,textEnd,button,resultat1,resultat2,resultat3,resultat4);
|
|
|
|
|
gameTime = new GameTime(textTimer);
|
|
|
|
|
gameTime.start();
|
|
|
|
|
PersoMouv = false;
|
|
|
|
@ -155,7 +162,6 @@ public class GamePlayController implements Initializable {
|
|
|
|
|
if(caseActuelle != null){
|
|
|
|
|
//animation déplacement vers la droite
|
|
|
|
|
if (caseActuelle.getCoordX() > caseAncienne.getCoordX()) {
|
|
|
|
|
System.out.println(pathPerso + "7.png");
|
|
|
|
|
Image imagePerso7 = new Image(Objects.requireNonNull(getClass().getClassLoader().getResource(pathPerso + "7.png")).toExternalForm());
|
|
|
|
|
Image imagePerso8 = new Image(Objects.requireNonNull(getClass().getClassLoader().getResource(pathPerso + "8.png")).toExternalForm());
|
|
|
|
|
Image imagePerso9 = new Image(Objects.requireNonNull(getClass().getClassLoader().getResource(pathPerso + "9.png")).toExternalForm());
|
|
|
|
@ -195,9 +201,9 @@ public class GamePlayController implements Initializable {
|
|
|
|
|
}
|
|
|
|
|
//animation déplacement vers la gauche
|
|
|
|
|
if (caseActuelle.getCoordX() < caseAncienne.getCoordX()) {
|
|
|
|
|
Image imagePerso4 = new Image(getClass().getClassLoader().getResource(pathPerso + "4.png").toExternalForm());
|
|
|
|
|
Image imagePerso5 = new Image(getClass().getClassLoader().getResource(pathPerso + "5.png").toExternalForm());
|
|
|
|
|
Image imagePerso6 = new Image(getClass().getClassLoader().getResource(pathPerso + "6.png").toExternalForm());
|
|
|
|
|
Image imagePerso4 = new Image(Objects.requireNonNull(getClass().getClassLoader().getResource(pathPerso + "4.png")).toExternalForm());
|
|
|
|
|
Image imagePerso5 = new Image(Objects.requireNonNull(getClass().getClassLoader().getResource(pathPerso + "5.png")).toExternalForm());
|
|
|
|
|
Image imagePerso6 = new Image(Objects.requireNonNull(getClass().getClassLoader().getResource(pathPerso + "6.png")).toExternalForm());
|
|
|
|
|
timeline.getKeyFrames().add(new KeyFrame(Duration.millis(time1), event -> {
|
|
|
|
|
persoImageView.setImage(imagePerso5);
|
|
|
|
|
persoImageView.setLayoutX(persoImageView.getLayoutX() - avancementCase);
|
|
|
|
@ -234,9 +240,9 @@ public class GamePlayController implements Initializable {
|
|
|
|
|
}
|
|
|
|
|
//animation déplacement vers le haut
|
|
|
|
|
if (caseActuelle.getCoordY() < caseAncienne.getCoordY()) {
|
|
|
|
|
Image imagePerso10 = new Image(getClass().getClassLoader().getResource(pathPerso + "10.png").toExternalForm());
|
|
|
|
|
Image imagePerso11 = new Image(getClass().getClassLoader().getResource(pathPerso + "11.png").toExternalForm());
|
|
|
|
|
Image imagePerso12 = new Image(getClass().getClassLoader().getResource(pathPerso + "12.png").toExternalForm());
|
|
|
|
|
Image imagePerso10 = new Image(Objects.requireNonNull(getClass().getClassLoader().getResource(pathPerso + "10.png")).toExternalForm());
|
|
|
|
|
Image imagePerso11 = new Image(Objects.requireNonNull(getClass().getClassLoader().getResource(pathPerso + "11.png")).toExternalForm());
|
|
|
|
|
Image imagePerso12 = new Image(Objects.requireNonNull(getClass().getClassLoader().getResource(pathPerso + "12.png")).toExternalForm());
|
|
|
|
|
timeline.getKeyFrames().add(new KeyFrame(Duration.millis(time1), event -> {
|
|
|
|
|
persoImageView.setImage(imagePerso11);
|
|
|
|
|
persoImageView.setLayoutY(persoImageView.getLayoutY() - avancementCase);
|
|
|
|
@ -273,9 +279,9 @@ public class GamePlayController implements Initializable {
|
|
|
|
|
}
|
|
|
|
|
//animation déplacement vers le bas
|
|
|
|
|
if (caseActuelle.getCoordY() > caseAncienne.getCoordY()) {
|
|
|
|
|
Image imagePerso1 = new Image(getClass().getClassLoader().getResource(pathPerso + "1.png").toExternalForm());
|
|
|
|
|
Image imagePerso2 = new Image(getClass().getClassLoader().getResource(pathPerso + "2.png").toExternalForm());
|
|
|
|
|
Image imagePerso3 = new Image(getClass().getClassLoader().getResource(pathPerso + "3.png").toExternalForm());
|
|
|
|
|
Image imagePerso1 = new Image(Objects.requireNonNull(getClass().getClassLoader().getResource(pathPerso + "1.png")).toExternalForm());
|
|
|
|
|
Image imagePerso2 = new Image(Objects.requireNonNull(getClass().getClassLoader().getResource(pathPerso + "2.png")).toExternalForm());
|
|
|
|
|
Image imagePerso3 = new Image(Objects.requireNonNull(getClass().getClassLoader().getResource(pathPerso + "3.png")).toExternalForm());
|
|
|
|
|
timeline.getKeyFrames().add(new KeyFrame(Duration.millis(time1), event -> {
|
|
|
|
|
persoImageView.setImage(imagePerso2);
|
|
|
|
|
persoImageView.setLayoutY(persoImageView.getLayoutY() + avancementCase);
|
|
|
|
@ -330,10 +336,10 @@ public class GamePlayController implements Initializable {
|
|
|
|
|
button.setLayoutY(752);
|
|
|
|
|
button.setPrefHeight(30);
|
|
|
|
|
button.setPrefWidth(119);
|
|
|
|
|
button.setText("Retour au début");
|
|
|
|
|
button.setOnAction(event -> {
|
|
|
|
|
AnchorPane pane = null;
|
|
|
|
|
try {
|
|
|
|
|
pane = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/MainPage.fxml")));
|
|
|
|
|
AnchorPane pane = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/MainPage.fxml")));
|
|
|
|
|
Stage a = new Stage();
|
|
|
|
|
a.setTitle("The Adventurer");
|
|
|
|
|
a.setScene(new Scene(pane, 900, 600));
|
|
|
|
@ -341,40 +347,25 @@ public class GamePlayController implements Initializable {
|
|
|
|
|
a.show();
|
|
|
|
|
Stage stage = (Stage) levelRoot.getScene().getWindow();
|
|
|
|
|
stage.close();
|
|
|
|
|
|
|
|
|
|
levelRoot.getChildren().setAll(pane);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
levelRoot.getChildren().setAll(pane);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void lancerDe() {
|
|
|
|
|
//Case actual = persoController.getActualCase();
|
|
|
|
|
if(PersoMouv == false) {
|
|
|
|
|
Case actuel = persoController.getActualCase();;
|
|
|
|
|
|
|
|
|
|
if(!PersoMouv) {
|
|
|
|
|
animationDe();
|
|
|
|
|
nbTour++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//verification(actual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void verification(Case actual) {
|
|
|
|
|
Map map = mapController.getMap();
|
|
|
|
|
ArrayList<Case> array = map.getMap();
|
|
|
|
|
actual = mapController.getCase(actual, diceNumber);
|
|
|
|
|
for (Case c : array) {
|
|
|
|
|
if (actual.getCoordX() == c.getCoordX() && actual.getCoordY() == c.getCoordY() && c.isBonus()) {
|
|
|
|
|
System.out.println("BONUS");
|
|
|
|
|
System.out.println("X perso : " + actual.getCoordX() + " Y perso : " + actual.getCoordY() + " X perso : " + c.getCoordX() + " Y perso : " + c.getCoordY() + " Bonus : " + c.isBonus());
|
|
|
|
|
}
|
|
|
|
|
if (actual.getCoordX() == c.getCoordX() && actual.getCoordY() == c.getCoordY() && c.isMalus()) {
|
|
|
|
|
System.out.println("MALUS");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void animationDe() {
|
|
|
|
|
personnage = new Thread("personnage") {
|
|
|
|
@ -389,14 +380,75 @@ public class GamePlayController implements Initializable {
|
|
|
|
|
String path = "image/dé/d" + diceNumber + ".png";
|
|
|
|
|
timeline.getKeyFrames().add(new KeyFrame(Duration.millis(50 * i), event -> de.setImage(new Image(path))));
|
|
|
|
|
}
|
|
|
|
|
Map map = mapController.getMap();
|
|
|
|
|
Case c = map.getMap().get(numCase+diceNumber);
|
|
|
|
|
|
|
|
|
|
if(c.isBonus()){
|
|
|
|
|
Bonus bonus = Bonus.randomGet();
|
|
|
|
|
switch (Objects.requireNonNull(bonus)){
|
|
|
|
|
case MOVE_FORWARD_1:
|
|
|
|
|
System.out.println("AJOUT DE 1");
|
|
|
|
|
diceNumber+=1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MOVE_FORWARD_3:
|
|
|
|
|
System.out.println("AJOUT DE 3");
|
|
|
|
|
diceNumber+=3;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MOVE_FORWARD_5:
|
|
|
|
|
System.out.println("AJOUT DE 5");
|
|
|
|
|
diceNumber+=5;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MOVE_FORWARD_8:
|
|
|
|
|
System.out.println("AJOUT DE 8");
|
|
|
|
|
diceNumber+=8;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(c.isMalus()){
|
|
|
|
|
Malus malus = Malus.randomGet();
|
|
|
|
|
switch (Objects.requireNonNull(malus)){
|
|
|
|
|
case MOVE_BACKWARD_1:
|
|
|
|
|
System.out.println("SUPRESSION DE 1");
|
|
|
|
|
diceNumber-=1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MOVE_BACKWARD_3:
|
|
|
|
|
System.out.println("SUPRESSION DE 3");
|
|
|
|
|
if(diceNumber > 3){
|
|
|
|
|
diceNumber-=3;
|
|
|
|
|
} else {
|
|
|
|
|
diceNumber=0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MOVE_BACKWARD_5:
|
|
|
|
|
System.out.println("SUPRESSION DE 5");
|
|
|
|
|
if(diceNumber > 5){
|
|
|
|
|
diceNumber-=5;
|
|
|
|
|
} else {
|
|
|
|
|
diceNumber=0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LAST_POSITION:
|
|
|
|
|
System.out.println("SUPRESSION DE DICE");
|
|
|
|
|
diceNumber=0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
numCase+=diceNumber;
|
|
|
|
|
|
|
|
|
|
timeline.play();
|
|
|
|
|
try {
|
|
|
|
|
personnage.sleep(700);
|
|
|
|
|
System.out.println("Lancement affichage resulsta");
|
|
|
|
|
affichageResultat();
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < diceNumber; i++) {
|
|
|
|
|
try {
|
|
|
|
|
PersoMouv = true;
|
|
|
|
@ -406,13 +458,14 @@ public class GamePlayController implements Initializable {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.out.println(persoController.getActualCase().getCoordX() + " " + persoController.getActualCase().getCoordY());
|
|
|
|
|
System.out.println(numCase);
|
|
|
|
|
PersoMouv = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
personnage.start();
|
|
|
|
|
}
|
|
|
|
|
public void affichageResultat(){
|
|
|
|
|
System.out.println("affichageResultat()");
|
|
|
|
|
String ancienResultat1;
|
|
|
|
|
String ancienResultat2;
|
|
|
|
|
String ancienResultat3;
|
|
|
|
@ -458,6 +511,7 @@ public class GamePlayController implements Initializable {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void saveScore(){
|
|
|
|
|
//difficulty
|
|
|
|
|
int resultat = gameTime.getTime();
|
|
|
|
|