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 boolean FULL_SCREEN = false;
|
||||
|
||||
public static final float SCORE_SIZE = 30f;
|
||||
}
|
||||
|
@@ -1,7 +1,12 @@
|
||||
package fr.monkhanny.dorfromantik.enums;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontFormatException;
|
||||
|
||||
public enum Fonts {
|
||||
TITLE, BUTTON;
|
||||
TITLE, BUTTON, SCORE;
|
||||
|
||||
public String getFontPath() {
|
||||
switch (this) {
|
||||
@@ -9,8 +14,29 @@ public enum Fonts {
|
||||
return "./ressources/fonts/Contage-Black.ttf";
|
||||
case BUTTON:
|
||||
return "./ressources/fonts/Contage-Regular.ttf";
|
||||
case SCORE:
|
||||
return "./ressources/fonts/Contage-Bold.ttf";
|
||||
default:
|
||||
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;
|
||||
|
||||
import fr.monkhanny.dorfromantik.listeners.GameResizeListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameZoomListener;
|
||||
import fr.monkhanny.dorfromantik.listeners.GameArrowKeyListener;
|
||||
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.Options;
|
||||
import fr.monkhanny.dorfromantik.enums.Biome;
|
||||
import fr.monkhanny.dorfromantik.enums.Fonts;
|
||||
import fr.monkhanny.dorfromantik.enums.TileOrientation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -19,13 +19,13 @@ import javax.swing.JFrame;
|
||||
import java.awt.Point;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Font;
|
||||
|
||||
// TEMPORAIRE :
|
||||
import java.awt.event.MouseMotionAdapter; // Import pour MouseMotionAdapter
|
||||
import java.awt.AlphaComposite;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.awt.Point;
|
||||
|
||||
|
||||
/**
|
||||
@@ -44,6 +44,8 @@ public class Board extends JPanel{
|
||||
private Tile nextTile;
|
||||
private Map<Biome, BiomeGroup> biomeGroups;
|
||||
private Point mousePosition;
|
||||
private ScoreManager scoreManager;
|
||||
private int currentScore;
|
||||
|
||||
// Constructeur avec seed
|
||||
public Board(JFrame gameFrame, long seed) {
|
||||
@@ -54,6 +56,8 @@ public class Board extends JPanel{
|
||||
this.random = new Random(seed);
|
||||
this.game = new Game(seed);
|
||||
|
||||
this.scoreManager = new ScoreManager(biomeGroups);
|
||||
|
||||
for (Biome biome : Biome.values()) {
|
||||
biomeGroups.put(biome, new BiomeGroup());
|
||||
}
|
||||
@@ -61,9 +65,6 @@ public class Board extends JPanel{
|
||||
// Placer une tuile centrale au démarrage
|
||||
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
|
||||
gameFrame.addMouseWheelListener(new GameZoomListener(this));
|
||||
|
||||
@@ -191,18 +192,10 @@ public class Board extends JPanel{
|
||||
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) {
|
||||
tiles.add(tile);
|
||||
updatePockets(tile);
|
||||
displayCurrentScore();
|
||||
calculateCurrentScore();
|
||||
}
|
||||
|
||||
private void updatePockets(Tile newTile) {
|
||||
@@ -253,13 +246,13 @@ public class Board extends JPanel{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Affiche le score actuel
|
||||
private void displayCurrentScore() {
|
||||
int totalScore = 0;
|
||||
for (BiomeGroup group : biomeGroups.values()) {
|
||||
totalScore += group.calculateTotalScore();
|
||||
}
|
||||
System.out.println("Score actuel : " + totalScore);
|
||||
private void calculateCurrentScore() {
|
||||
scoreManager.updateScore(); // Met à jour le score
|
||||
currentScore = scoreManager.getCurrentScore(); // Récupère le score actuel
|
||||
}
|
||||
|
||||
public int getCurrentScore() {
|
||||
return currentScore;
|
||||
}
|
||||
|
||||
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é
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// 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.)
|
||||
g2d.translate(offsetX / zoomFactor, offsetY / zoomFactor); // Re-appliquer le décalage
|
||||
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,21 +140,19 @@ public class Tile extends Cell {
|
||||
}
|
||||
|
||||
public boolean isAdjacentTo(Tile otherTile) {
|
||||
// Get the radius of the tiles
|
||||
int tileRadius = this.getRadius();
|
||||
// Obtenir le rayon de la tuile
|
||||
int tileRadius = this.getRadius();
|
||||
|
||||
// Compute the distance between the center of this tile and the other tile
|
||||
int deltaX = this.getX() - otherTile.getX();
|
||||
int deltaY = this.getY() - otherTile.getY();
|
||||
|
||||
// Calculate the Euclidean distance between the two tiles
|
||||
double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
|
||||
// In a hexagonal grid, two tiles are adjacent if their distance is equal to the diameter (2 * radius)
|
||||
return distance <= (2 * tileRadius);
|
||||
}
|
||||
// Compute the distance between the center of this tile and the other tile
|
||||
int deltaX = this.getX() - otherTile.getX();
|
||||
int deltaY = this.getY() - otherTile.getY();
|
||||
|
||||
// Calculate the Euclidean distance between the two tiles
|
||||
double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
|
||||
// In a hexagonal grid, two tiles are adjacent if their distance is equal to the diameter (2 * radius)
|
||||
return distance <= (2 * tileRadius);
|
||||
}
|
||||
|
||||
private TileOrientation determineSide(int x, int y) {
|
||||
int radius = this.getRadius();
|
||||
|
@@ -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