Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 196b2cc1 rédigé par Rayane TABTI's avatar Rayane TABTI
Parcourir les fichiers

300 (adding the save of the player with high score)

parent 2434787b
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -10,11 +10,11 @@
</component>
<component name="ChangeListManager">
<list default="true" id="5da3cc68-103b-4b76-99ba-87efacd066e5" name="Changes" comment="Add the boss weapon that handle multiple phase of the boss, with multiple type of weapon behavior.&#10;Doesn't work because of null pointer return.">
<change afterPath="$PROJECT_DIR$/src/main/java/com/example/poo/textData/highScorrer" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/poo/textData/highScore" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/poo/textData/highScore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/poo/textData/money.txt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/poo/textData/money.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/poo/textData/saveShips.txt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/poo/textData/saveShips.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/poo/utils/Clock.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/poo/utils/Clock.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/poo/utils/ViewManager.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/poo/utils/ViewManager.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
......@@ -229,6 +229,15 @@
<option featureType="com.intellij.configurationType" implementationName="LATEX_RUN_CONFIGURATION" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
<option name="RECENT_FILTERS">
<map>
<entry key="Branch">
......@@ -249,15 +258,6 @@
</entry>
</map>
</option>
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Separate every file in a clear package so it's easier to find it and correct some encapsulation problem" />
......
360
\ No newline at end of file
835
\ No newline at end of file
LE Z LE DINGO ULTIME SIUUUUUUUUU
\ No newline at end of file
3
\ No newline at end of file
32
\ No newline at end of file
playerBlueShip.png
playerRedShip.png
......@@ -13,9 +13,10 @@ import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
......@@ -26,12 +27,6 @@ import javafx.util.Duration;
import java.io.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import com.example.poo.utils.Clock;
import java.nio.file.FileSystems;
import java.nio.file.Path;
public class ViewManager
......@@ -66,6 +61,7 @@ public class ViewManager
private Text ownedMoney,newHighScore;
private String playerShip = "playerGreenShip.png";
private String playerName;
private final String shipsSaveFile = "src/main/java/com/example/poo/textData/saveShips.txt";
/**
......@@ -107,7 +103,7 @@ public class ViewManager
}
}
public int readingFiles(String filePath) {
public int readingIntValuesFromFiles(String filePath) {
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath))) {
String line = bufferedReader.readLine();
return (line != null) ? Integer.parseInt(line) : 0;
......@@ -117,6 +113,15 @@ public class ViewManager
}
}
public String readingStringValuesFromFiles(String filePath) {
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath))) {
String line = bufferedReader.readLine();
return (line != null) ? line : "NO HIGH SCORRER";
} catch (IOException e) {
System.err.println("Error reading from the file: " + e.getMessage());
return "YA UNE ERREUR";
}
}
private void updateScorePeriodically() {
......@@ -420,16 +425,18 @@ public class ViewManager
private void highScore()
{
int highScore = readingFiles("src/main/java/com/example/poo/textData/highScore");
int highScore = readingIntValuesFromFiles("src/main/java/com/example/poo/textData/highScore");
if (Global.score > highScore)
{
writingFiles("src/main/java/com/example/poo/textData/highScore", Integer.toString(Global.score),false);
writingFiles("src/main/java/com/example/poo/textData/highScorrer",playerName,false);
newHighScore = new Text("SIUUU NEW HIGH SCORE : "+Global.score);
newHighScore.setFill(Color.RED);
newHighScore.setFont(Font.loadFont("file:src/main/resources/fonts/ThaleahFat.ttf",50));
newHighScore.setX(Global.widgetWidth/2 - 210);
newHighScore.setX(Global.widgetWidth/2 - 235);
newHighScore.setY(Global.widgetHeight/2+ 80);
root.getChildren().add(newHighScore);
}
}
......@@ -543,7 +550,6 @@ public class ViewManager
private void deathMenu()
{
isRunning = false;
highScore();
// since the YOU LOSE text hasn't an image, we don't put it in the try catch bloc
......@@ -682,6 +688,7 @@ public class ViewManager
loadEffect.setX(220);
loadEffect.setY(500);
root.getChildren().addAll(company,loadEffect);
this.mainStage.setScene(loadingScene);
this.mainStage.setResizable(false);
......@@ -715,8 +722,37 @@ public class ViewManager
Global.log.write("Error loading Menu Logo's image: " + e.getMessage());
}
Global.money = readingFiles("src/main/java/com/example/poo/textData/money.txt");
Global.money = readingIntValuesFromFiles("src/main/java/com/example/poo/textData/money.txt");
Text highScorrer = new Text("HIGH SCORE OWNER : "+readingStringValuesFromFiles("src/main/java/com/example/poo/textData/highScorrer"));
highScorrer.setX(menuWidth/2 - 230);
highScorrer.setY(menuHeight/2 - 70);
highScorrer.setFont(Font.loadFont("file:src/main/resources/fonts/ThaleahFat.ttf",26));
highScorrer.setFill(Color.WHITE);
Text namePlaceHolder = new Text("ENTER YOUR NAME");
TextField enterPlayerName = new TextField();
namePlaceHolder.setX(menuWidth/2 - 143);
namePlaceHolder.setY(menuWidth/2 - 20);
namePlaceHolder.setFont(Font.loadFont("file:src/main/resources/fonts/ThaleahFat.ttf",40));
namePlaceHolder.setFill(Color.WHITE);
enterPlayerName.setLayoutX(menuWidth/2 - 100);
enterPlayerName.setLayoutY(menuHeight/2);
enterPlayerName.setFont(Font.loadFont("file:src/main/resources/fonts/ThaleahFat.ttf",25));
enterPlayerName.setPrefWidth(200);
enterPlayerName.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.ENTER) {
playerName = enterPlayerName.getText();
System.out.println(playerName );
enterPlayerName.clear();
}
});
root.getChildren().addAll(highScorrer,enterPlayerName,namePlaceHolder);
displayOwnedMoney();
mainMenu();
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter