Modification du score
This commit is contained in:
@@ -57,4 +57,6 @@ public class Options {
|
|||||||
public static final int MAX_TILE_NUMBER = 50;
|
public static final int MAX_TILE_NUMBER = 50;
|
||||||
|
|
||||||
public static boolean FULL_SCREEN = false;
|
public static boolean FULL_SCREEN = false;
|
||||||
|
|
||||||
|
public static final float SCORE_SIZE = 30f;
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,12 @@
|
|||||||
package fr.monkhanny.dorfromantik.enums;
|
package fr.monkhanny.dorfromantik.enums;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.FontFormatException;
|
||||||
|
|
||||||
public enum Fonts {
|
public enum Fonts {
|
||||||
TITLE, BUTTON;
|
TITLE, BUTTON, SCORE;
|
||||||
|
|
||||||
public String getFontPath() {
|
public String getFontPath() {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
@@ -9,8 +14,29 @@ public enum Fonts {
|
|||||||
return "./ressources/fonts/Contage-Black.ttf";
|
return "./ressources/fonts/Contage-Black.ttf";
|
||||||
case BUTTON:
|
case BUTTON:
|
||||||
return "./ressources/fonts/Contage-Regular.ttf";
|
return "./ressources/fonts/Contage-Regular.ttf";
|
||||||
|
case SCORE:
|
||||||
|
return "./ressources/fonts/Contage-Bold.ttf";
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unexpected value: " + this);
|
throw new IllegalArgumentException("Unexpected value: " + this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Font getFont(float size) {
|
||||||
|
try {
|
||||||
|
switch (this) {
|
||||||
|
case TITLE:
|
||||||
|
return Font.createFont(Font.TRUETYPE_FONT, new File("./ressources/fonts/Contage-Black.ttf")).deriveFont(size);
|
||||||
|
case BUTTON:
|
||||||
|
return Font.createFont(Font.TRUETYPE_FONT, new File("./ressources/fonts/Contage-Regular.ttf")).deriveFont(size);
|
||||||
|
case SCORE:
|
||||||
|
return Font.createFont(Font.TRUETYPE_FONT, new File("./ressources/fonts/Contage-Bold.ttf")).deriveFont(size);
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unexpected value: " + this);
|
||||||
|
}
|
||||||
|
} catch (IOException | FontFormatException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
// Retourner une police de secours si le fichier est introuvable ou s'il y a une erreur
|
||||||
|
return new Font("Arial", Font.PLAIN, (int) size);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1,6 +1,5 @@
|
|||||||
package fr.monkhanny.dorfromantik.game;
|
package fr.monkhanny.dorfromantik.game;
|
||||||
|
|
||||||
import fr.monkhanny.dorfromantik.listeners.GameResizeListener;
|
|
||||||
import fr.monkhanny.dorfromantik.listeners.GameZoomListener;
|
import fr.monkhanny.dorfromantik.listeners.GameZoomListener;
|
||||||
import fr.monkhanny.dorfromantik.listeners.GameArrowKeyListener;
|
import fr.monkhanny.dorfromantik.listeners.GameArrowKeyListener;
|
||||||
import fr.monkhanny.dorfromantik.listeners.GameSpaceKeyListener;
|
import fr.monkhanny.dorfromantik.listeners.GameSpaceKeyListener;
|
||||||
@@ -8,6 +7,7 @@ import fr.monkhanny.dorfromantik.listeners.GameMouseClickListener;
|
|||||||
import fr.monkhanny.dorfromantik.listeners.GameMouseWheelListener;
|
import fr.monkhanny.dorfromantik.listeners.GameMouseWheelListener;
|
||||||
import fr.monkhanny.dorfromantik.Options;
|
import fr.monkhanny.dorfromantik.Options;
|
||||||
import fr.monkhanny.dorfromantik.enums.Biome;
|
import fr.monkhanny.dorfromantik.enums.Biome;
|
||||||
|
import fr.monkhanny.dorfromantik.enums.Fonts;
|
||||||
import fr.monkhanny.dorfromantik.enums.TileOrientation;
|
import fr.monkhanny.dorfromantik.enums.TileOrientation;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -19,13 +19,13 @@ import javax.swing.JFrame;
|
|||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Font;
|
||||||
|
|
||||||
// TEMPORAIRE :
|
// TEMPORAIRE :
|
||||||
import java.awt.event.MouseMotionAdapter; // Import pour MouseMotionAdapter
|
import java.awt.event.MouseMotionAdapter; // Import pour MouseMotionAdapter
|
||||||
import java.awt.AlphaComposite;
|
import java.awt.AlphaComposite;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.awt.Point;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,6 +44,8 @@ public class Board extends JPanel{
|
|||||||
private Tile nextTile;
|
private Tile nextTile;
|
||||||
private Map<Biome, BiomeGroup> biomeGroups;
|
private Map<Biome, BiomeGroup> biomeGroups;
|
||||||
private Point mousePosition;
|
private Point mousePosition;
|
||||||
|
private ScoreManager scoreManager;
|
||||||
|
private int currentScore;
|
||||||
|
|
||||||
// Constructeur avec seed
|
// Constructeur avec seed
|
||||||
public Board(JFrame gameFrame, long seed) {
|
public Board(JFrame gameFrame, long seed) {
|
||||||
@@ -54,6 +56,8 @@ public class Board extends JPanel{
|
|||||||
this.random = new Random(seed);
|
this.random = new Random(seed);
|
||||||
this.game = new Game(seed);
|
this.game = new Game(seed);
|
||||||
|
|
||||||
|
this.scoreManager = new ScoreManager(biomeGroups);
|
||||||
|
|
||||||
for (Biome biome : Biome.values()) {
|
for (Biome biome : Biome.values()) {
|
||||||
biomeGroups.put(biome, new BiomeGroup());
|
biomeGroups.put(biome, new BiomeGroup());
|
||||||
}
|
}
|
||||||
@@ -61,9 +65,6 @@ public class Board extends JPanel{
|
|||||||
// Placer une tuile centrale au démarrage
|
// Placer une tuile centrale au démarrage
|
||||||
initializeCentralTile();
|
initializeCentralTile();
|
||||||
|
|
||||||
// Ajouter un écouteur de redimensionnement pour redessiner les tuiles
|
|
||||||
gameFrame.addComponentListener(new GameResizeListener(this));
|
|
||||||
|
|
||||||
// Ajouter un écouteur de molette de souris pour gérer le zoom
|
// Ajouter un écouteur de molette de souris pour gérer le zoom
|
||||||
gameFrame.addMouseWheelListener(new GameZoomListener(this));
|
gameFrame.addMouseWheelListener(new GameZoomListener(this));
|
||||||
|
|
||||||
@@ -191,18 +192,10 @@ public class Board extends JPanel{
|
|||||||
initializeNextTile();
|
initializeNextTile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void repositionCentralTile() {
|
|
||||||
int centerX = gameFrame.getWidth() / 2;
|
|
||||||
int centerY = gameFrame.getHeight() / 2;
|
|
||||||
|
|
||||||
// Déplacer la tuile centrale vers le nouveau centre de la fenêtre
|
|
||||||
centralTile.setPosition(centerX, centerY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addTile(Tile tile) {
|
public void addTile(Tile tile) {
|
||||||
tiles.add(tile);
|
tiles.add(tile);
|
||||||
updatePockets(tile);
|
updatePockets(tile);
|
||||||
displayCurrentScore();
|
calculateCurrentScore();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePockets(Tile newTile) {
|
private void updatePockets(Tile newTile) {
|
||||||
@@ -253,13 +246,13 @@ public class Board extends JPanel{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Affiche le score actuel
|
private void calculateCurrentScore() {
|
||||||
private void displayCurrentScore() {
|
scoreManager.updateScore(); // Met à jour le score
|
||||||
int totalScore = 0;
|
currentScore = scoreManager.getCurrentScore(); // Récupère le score actuel
|
||||||
for (BiomeGroup group : biomeGroups.values()) {
|
|
||||||
totalScore += group.calculateTotalScore();
|
|
||||||
}
|
}
|
||||||
System.out.println("Score actuel : " + totalScore);
|
|
||||||
|
public int getCurrentScore() {
|
||||||
|
return currentScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Random getRandom() { return random; }
|
public Random getRandom() { return random; }
|
||||||
@@ -427,6 +420,17 @@ public class Board extends JPanel{
|
|||||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f)); // Rétablir l'opacité
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f)); // Rétablir l'opacité
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtenez la police SCORE avec une taille ajustée (par exemple, 30 points)
|
||||||
|
Font scoreFont = Fonts.SCORE.getFont(30f); // Vous pouvez ajuster la taille ici
|
||||||
|
g.setFont(scoreFont);
|
||||||
|
|
||||||
|
// Calculer la position du score (avec zoom et décalage)
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
int scoreX = (int) ((getWidth() / (2 * zoomFactor) - offsetX / zoomFactor) - 20);
|
||||||
|
int scoreY = (int) (40 / zoomFactor - offsetY / zoomFactor);
|
||||||
|
|
||||||
|
// Dessiner le texte du score
|
||||||
|
g.drawString("Score : " + currentScore, scoreX, scoreY);
|
||||||
|
|
||||||
if (nextTile != null) {
|
if (nextTile != null) {
|
||||||
// Calculer la position correcte de la nextTile (en tenant compte du zoom et des décalages)
|
// Calculer la position correcte de la nextTile (en tenant compte du zoom et des décalages)
|
||||||
@@ -443,6 +447,7 @@ public class Board extends JPanel{
|
|||||||
// Rétablir les transformations pour les autres éléments (tuiles existantes, etc.)
|
// Rétablir les transformations pour les autres éléments (tuiles existantes, etc.)
|
||||||
g2d.translate(offsetX / zoomFactor, offsetY / zoomFactor); // Re-appliquer le décalage
|
g2d.translate(offsetX / zoomFactor, offsetY / zoomFactor); // Re-appliquer le décalage
|
||||||
g2d.scale(zoomFactor, zoomFactor); // Re-appliquer le zoom
|
g2d.scale(zoomFactor, zoomFactor); // Re-appliquer le zoom
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
40
TestV2/src/fr/monkhanny/dorfromantik/game/ScoreManager.java
Normal file
40
TestV2/src/fr/monkhanny/dorfromantik/game/ScoreManager.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.game;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import fr.monkhanny.dorfromantik.enums.Biome;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classe responsable du calcul et de la gestion du score.
|
||||||
|
*/
|
||||||
|
public class ScoreManager {
|
||||||
|
private int currentScore = 0;
|
||||||
|
private Map<Biome, BiomeGroup> biomeGroups;
|
||||||
|
|
||||||
|
// Constructeur avec la référence aux groupes de biomes
|
||||||
|
public ScoreManager(Map<Biome, BiomeGroup> biomeGroups) {
|
||||||
|
this.biomeGroups = biomeGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour calculer le score en fonction des groupes de biomes
|
||||||
|
public void calculateScore() {
|
||||||
|
int totalScore = 0;
|
||||||
|
|
||||||
|
for (BiomeGroup group : biomeGroups.values()) {
|
||||||
|
totalScore += group.calculateTotalScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
currentScore = totalScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Récupérer le score actuel
|
||||||
|
public int getCurrentScore() {
|
||||||
|
return currentScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mettre à jour le score (si nécessaire)
|
||||||
|
public void updateScore() {
|
||||||
|
calculateScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -140,7 +140,7 @@ public class Tile extends Cell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAdjacentTo(Tile otherTile) {
|
public boolean isAdjacentTo(Tile otherTile) {
|
||||||
// Get the radius of the tiles
|
// Obtenir le rayon de la tuile
|
||||||
int tileRadius = this.getRadius();
|
int tileRadius = this.getRadius();
|
||||||
|
|
||||||
// Compute the distance between the center of this tile and the other tile
|
// Compute the distance between the center of this tile and the other tile
|
||||||
@@ -154,8 +154,6 @@ public class Tile extends Cell {
|
|||||||
return distance <= (2 * tileRadius);
|
return distance <= (2 * tileRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private TileOrientation determineSide(int x, int y) {
|
private TileOrientation determineSide(int x, int y) {
|
||||||
int radius = this.getRadius();
|
int radius = this.getRadius();
|
||||||
TileOrientation[] sides = TileOrientation.values();
|
TileOrientation[] sides = TileOrientation.values();
|
||||||
|
@@ -1,23 +0,0 @@
|
|||||||
package fr.monkhanny.dorfromantik.listeners;
|
|
||||||
|
|
||||||
import fr.monkhanny.dorfromantik.game.Board;
|
|
||||||
|
|
||||||
import java.awt.event.ComponentAdapter;
|
|
||||||
import java.awt.event.ComponentEvent;
|
|
||||||
|
|
||||||
public class GameResizeListener extends ComponentAdapter {
|
|
||||||
private Board board;
|
|
||||||
|
|
||||||
// Constructeur qui reçoit une instance de Board pour pouvoir accéder à ses méthodes
|
|
||||||
public GameResizeListener(Board board) {
|
|
||||||
this.board = board;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cette méthode est appelée lorsque la taille de la fenêtre change
|
|
||||||
@Override
|
|
||||||
public void componentResized(ComponentEvent e) {
|
|
||||||
// Réajuster la position de la tuile centrale lorsque la fenêtre est redimensionnée
|
|
||||||
board.repositionCentralTile();
|
|
||||||
board.repaint(); // Demander à Board de redessiner le panneau
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user