From 7efc59c86294bb301976a4c2db724ca194683d50 Mon Sep 17 00:00:00 2001 From: Khalid CHENOUNA Date: Sat, 16 Nov 2024 13:49:24 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20d'un=20d=C3=A9but=20de=20jeu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/fr/monkhanny/dorfromantik/Main.java | 5 +- .../controller/GameModeController.java | 36 +- .../controller/MainMenuButtonController.java | 12 +- .../fr/monkhanny/dorfromantik/game/Board.java | 60 ++++ .../fr/monkhanny/dorfromantik/game/Cell.java | 95 +++++ .../fr/monkhanny/dorfromantik/game/Game.java | 27 ++ .../fr/monkhanny/dorfromantik/game/Tile.java | 334 ++++++++++++++++++ .../gui/GameModeSelectionPanel.java | 11 +- 8 files changed, 559 insertions(+), 21 deletions(-) create mode 100644 TestV2/src/fr/monkhanny/dorfromantik/game/Board.java create mode 100644 TestV2/src/fr/monkhanny/dorfromantik/game/Cell.java create mode 100644 TestV2/src/fr/monkhanny/dorfromantik/game/Game.java create mode 100644 TestV2/src/fr/monkhanny/dorfromantik/game/Tile.java diff --git a/TestV2/src/fr/monkhanny/dorfromantik/Main.java b/TestV2/src/fr/monkhanny/dorfromantik/Main.java index 4ecb435..72ca2f7 100644 --- a/TestV2/src/fr/monkhanny/dorfromantik/Main.java +++ b/TestV2/src/fr/monkhanny/dorfromantik/Main.java @@ -44,7 +44,7 @@ public class Main { MusicPlayer.playMusic(); MainMenu mainMenu = new MainMenu(); MainMenuResizeController MainMenuResizeController = new MainMenuResizeController(mainMenu); - MainMenuButtonController MainMenuButtonController = new MainMenuButtonController(mainMenu,settingsFrame,howToPlayFrame,gameModeFrame); + MainMenuButtonController MainMenuButtonController = new MainMenuButtonController(mainMenu,settingsFrame,howToPlayFrame,gameModeFrame,gameFrame); // Fenêtre des paramètres @@ -61,10 +61,11 @@ public class Main { // Fenêtre du choix des modes de jeu CloseWindowListener gameModeWindowListener = new CloseWindowListener(mainMenu, gameModeFrame); - GameModeController gameModeController = new GameModeController(); + GameModeController gameModeController = new GameModeController(gameFrame,mainMenu); GameModeSelectionPanel gameModeSelectionPanel = new GameModeSelectionPanel(gameModeController); gameModeFrame.addWindowListener(gameModeWindowListener); gameModeController.setGameModeSelectionPanel(gameModeSelectionPanel); gameModeFrame.add(gameModeSelectionPanel); + } } diff --git a/TestV2/src/fr/monkhanny/dorfromantik/controller/GameModeController.java b/TestV2/src/fr/monkhanny/dorfromantik/controller/GameModeController.java index 35cc7b9..c38d807 100644 --- a/TestV2/src/fr/monkhanny/dorfromantik/controller/GameModeController.java +++ b/TestV2/src/fr/monkhanny/dorfromantik/controller/GameModeController.java @@ -1,16 +1,23 @@ package fr.monkhanny.dorfromantik.controller; import fr.monkhanny.dorfromantik.gui.GameModeSelectionPanel; +import fr.monkhanny.dorfromantik.game.Board; +import fr.monkhanny.dorfromantik.gui.MainMenu; + import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.JFrame; public class GameModeController implements ActionListener { private GameModeSelectionPanel gameModeSelectionPanel; + private JFrame gameFrame; + private MainMenu mainMenu; // Constructeur sans le panneau - public GameModeController() { - // Initialisation sans le panneau + public GameModeController(JFrame gameFrame, MainMenu mainMenu) { + this.gameFrame = gameFrame; + this.mainMenu = mainMenu; } // Méthode pour associer le panneau @@ -24,34 +31,29 @@ public class GameModeController implements ActionListener { switch (command) { case "Mode 1": - startGame("Mode 1", null); + startGame("Mode 1", 123456789L); break; case "Mode 2": - startGame("Mode 2", null); + startGame("Mode 2", 987654321L); break; case "Mode 3": - startGame("Mode 3", null); + startGame("Mode 3", 678912345L); break; case "Mode 4": - startGame("Mode 4", null); + startGame("Mode 4", 103072005L); break; case "Démarrer": - String seed = gameModeSelectionPanel.getSeed(); - if (!seed.isEmpty()) { - startGame("Custom Mode", seed); - } + long seed = gameModeSelectionPanel.getLongSeed(); + startGame("Custom Mode", seed); break; default: System.out.println("Commande inconnue: " + command); } } - private void startGame(String mode, String seed) { - System.out.println("Démarrer le jeu en mode: " + mode); - if (seed != null) { - System.out.println("Seed personnalisée: " + seed); - } - - // Implémenter la logique pour démarrer le jeu avec le mode sélectionné et la seed si applicable + private void startGame(String mode, long seed) { + Board board = new Board(this.gameFrame,seed); + this.gameFrame.setVisible(true); + this.gameFrame.add(board); } } diff --git a/TestV2/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java b/TestV2/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java index ea6873f..c9b31ac 100644 --- a/TestV2/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java +++ b/TestV2/src/fr/monkhanny/dorfromantik/controller/MainMenuButtonController.java @@ -19,8 +19,9 @@ public class MainMenuButtonController implements ActionListener { private JFrame settingsFrame; private JFrame howToPlayFrame; private JFrame gameModeFrame; + private JFrame gameFrame; - public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame, JFrame howToPlayFrame, JFrame gameModeFrame) { + public MainMenuButtonController(MainMenu mainMenu, JFrame settingsFrame, JFrame howToPlayFrame, JFrame gameModeFrame, JFrame gameFrame) { this.mainMenu = mainMenu; // Ajouter les écouteurs d'événements sur les boutons ButtonPanel buttonPanel = mainMenu.getButtonPanel(); @@ -50,6 +51,12 @@ public class MainMenuButtonController implements ActionListener { this.gameModeFrame.setVisible(false); this.gameModeFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + // Paramètrage de la fenêtre du jeu + this.gameFrame = gameFrame; + this.gameFrame.setLocationRelativeTo(null); + this.gameFrame.setVisible(false); + this.gameFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + } @Override @@ -87,6 +94,9 @@ public class MainMenuButtonController implements ActionListener { this.gameModeFrame.setSize(mainMenuSize); this.gameModeFrame.setLocation(mainMenuLocation); + this.gameFrame.setSize(mainMenuSize); + this.gameFrame.setLocation(mainMenuLocation); + // Cacher la fenêtre du menu principal this.mainMenu.setVisible(false); diff --git a/TestV2/src/fr/monkhanny/dorfromantik/game/Board.java b/TestV2/src/fr/monkhanny/dorfromantik/game/Board.java new file mode 100644 index 0000000..821a80c --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/game/Board.java @@ -0,0 +1,60 @@ +package fr.monkhanny.dorfromantik.game; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.awt.Graphics; +import javax.swing.JPanel; +import java.awt.Graphics; +import javax.swing.JFrame; + +/** + * Représente le plateau de jeu. + */ +public class Board extends JPanel{ + private List tiles; + private Random random; + private Game game; + private JFrame gameFrame; + + // Constructeur avec seed + public Board(JFrame gameFrame, long seed) { + this.gameFrame = gameFrame; + this.tiles = new ArrayList<>(); + this.random = new Random(seed); + this.game = new Game(seed); + + // Placer une tuile centrale au démarrage + initializeCentralTile(); + } + + + private void initializeCentralTile() { + int centerX = gameFrame.getWidth() / 2; + int centerY = gameFrame.getHeight() / 2; + + Tile centralTile = new Tile(this, centerX, centerY, 50); + addTile(centralTile); + } + + public void addTile(Tile tile) { + tiles.add(tile); + } + + public Random getRandom() { + return random; + } + + public Game getGame() { + return game; + } + + + public void paintComponent(Graphics g) { + super.paintComponent(g); + for (Tile tile : tiles) { + tile.paintTileWithPosition(g,1f); + } + } +} + diff --git a/TestV2/src/fr/monkhanny/dorfromantik/game/Cell.java b/TestV2/src/fr/monkhanny/dorfromantik/game/Cell.java new file mode 100644 index 0000000..affab58 --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/game/Cell.java @@ -0,0 +1,95 @@ +package fr.monkhanny.dorfromantik.game; + +import java.awt.*; +import javax.swing.*; + +/** + * Représente une cellule de base sur le plateau de jeu. + * C'est la classe parente pour la classe Tile. + */ +public class Cell extends JComponent { + private Board board; // Le plateau de jeu auquel cette cellule appartient + private int x; // Coordonnée x du centre de la cellule + private int y; // Coordonnée y du centre de la cellule + private int radius; // Rayon de la cellule (si on parle d'un hexagone, c'est le rayon de l'hexagone) + + /** + * Constructeur de la classe Cell. + * + * @param board Le plateau de jeu auquel cette cellule appartient + * @param x La coordonnée x du centre de la cellule + * @param y La coordonnée y du centre de la cellule + * @param radius Le rayon de la cellule + */ + public Cell(Board board, int x, int y, int radius) { + this.board = board; + this.x = x; + this.y = y; + this.radius = radius; + + // Définir la taille du composant pour l'affichage + this.setSize(2 * radius, 2 * radius); + this.setLocation(x - radius, y - radius); + } + + /** + * Récupère le plateau de jeu auquel cette cellule appartient. + * + * @return Le plateau de jeu + */ + public Board getBoard() { + return board; + } + + /** + * Récupère la coordonnée x du centre de la cellule. + * + * @return La coordonnée x + */ + public int getXCoord() { + return x; + } + + /** + * Récupère la coordonnée y du centre de la cellule. + * + * @return La coordonnée y + */ + public int getYCoord() { + return y; + } + + /** + * Récupère le rayon de la cellule. + * + * @return Le rayon de la cellule + */ + public int getRadius() { + return radius; + } + + /** + * Convertit une coordonnée en degrés en une valeur de 0 à 360. + * + * @param angle L'angle en degrés + * @return La valeur normalisée entre 0 et 360 degrés + */ + public static double to360Degrees(double angle) { + angle = angle % 360; + if (angle < 0) { + angle += 360; + } + return angle; + } + + /** + * Méthode pour redessiner la cellule si nécessaire. + * Elle sera surchargée par les classes dérivées comme Tile. + * + * @param g Le contexte graphique + */ + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + } +} diff --git a/TestV2/src/fr/monkhanny/dorfromantik/game/Game.java b/TestV2/src/fr/monkhanny/dorfromantik/game/Game.java new file mode 100644 index 0000000..2a8077b --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/game/Game.java @@ -0,0 +1,27 @@ +package fr.monkhanny.dorfromantik.game; + +import java.util.Random; + +/** + * Représente un objet de jeu qui gère les fonctionnalités générales. + */ +public class Game { + private Random random; + + // Nouveau constructeur qui accepte un seed + public Game(long seed) { + this.random = new Random(seed); + } + + // Constructeur par défaut pour conserver la flexibilité + public Game() { + this.random = new Random(); + } + + public int getRandomInt(int max) { + return random.nextInt(max); + } +} + + + diff --git a/TestV2/src/fr/monkhanny/dorfromantik/game/Tile.java b/TestV2/src/fr/monkhanny/dorfromantik/game/Tile.java new file mode 100644 index 0000000..7dc3c8f --- /dev/null +++ b/TestV2/src/fr/monkhanny/dorfromantik/game/Tile.java @@ -0,0 +1,334 @@ +package fr.monkhanny.dorfromantik.game; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.RenderingHints; +import java.util.HashMap; +import java.util.Arrays; + +import fr.monkhanny.dorfromantik.enums.Biome; +import fr.monkhanny.dorfromantik.enums.TileOrientation; +import fr.monkhanny.dorfromantik.utils.Hexagon; + + +public class Tile extends Cell { + + private HashMap sideBiomes = new HashMap<>(); + + /** + * Constructeur d'une tuile avec des biomes spécifiques pour chaque côté. + * + * @param board Le plateau de jeu + * @param x La position x du centre de la tuile + * @param y La position y du centre de la tuile + * @param radius Le rayon de la tuile + * @param biomes Biomes associés aux côtés de la tuile + */ + public Tile(Board board, int x, int y, int radius, Biome... biomes) { + super(board, x, y, radius); + TileOrientation[] sides = TileOrientation.values(); + for (int i = 0; i < sides.length; i++) { + this.sideBiomes.put(sides[i], biomes[i]); + } + } + + /** + * Constructeur d'une tuile avec des biomes aléatoires. + * + * @param board Le plateau de jeu + * @param x La position x du centre de la tuile + * @param y La position y du centre de la tuile + * @param radius Le rayon de la tuile + */ + public Tile(Board board, int x, int y, int radius) { + super(board, x, y, radius); + this.assignRandomBiomes(); + } + + /** + * Constructeur d'une tuile avec des biomes spécifiques pour chaque côté + * à partir d'un centre donné. + * + * @param board Le plateau de jeu + * @param center Le centre de la tuile + * @param radius Le rayon de la tuile + * @param biomes Biomes associés aux côtés de la tuile + */ + public Tile(Board board, Point center, int radius, Biome... biomes) { + this(board, center.x, center.y, radius, biomes); + } + + /** + * Constructeur d'une tuile avec des biomes aléatoires à partir d'un centre donné. + * + * @param board Le plateau de jeu + * @param center Le centre de la tuile + * @param radius Le rayon de la tuile + */ + public Tile(Board board, Point center, int radius) { + this(board, center.x, center.y, radius); + } + + /** + * Définit les biomes pour cette tuile. + * + * @param biomes Biomes associés aux côtés + */ + public void setBiomes(Biome... biomes) { + TileOrientation[] sides = TileOrientation.values(); + for (int i = 0; i < sides.length; i++) { + this.sideBiomes.put(sides[i], biomes[i]); + } + } + + /** + * Assigne des biomes aléatoires aux côtés de la tuile. + */ + public void assignRandomBiomes() { + Game game = this.getBoard().getGame(); + Biome[] biomes = Biome.values(); + TileOrientation[] sides = TileOrientation.values(); + + this.sideBiomes.clear(); + + Biome firstBiome = biomes[game.getRandomInt(biomes.length)]; + biomes = Arrays.stream(biomes).filter(b -> b != firstBiome).toArray(Biome[]::new); + Biome secondBiome = biomes[game.getRandomInt(biomes.length)]; + + int firstBiomeSideCount = game.getRandomInt(sides.length + 1); + int firstBiomeSideOffset = game.getRandomInt(sides.length); + + for (int i = 0; i < sides.length; i++) { + TileOrientation side = sides[(i + firstBiomeSideOffset) % sides.length]; + Biome assignedBiome = (i < firstBiomeSideCount) ? firstBiome : secondBiome; + this.sideBiomes.put(side, assignedBiome); + } + } + + /** + * Récupère le biome associé à un côté donné. + * + * @param side Le côté de la tuile + * @return Le biome associé au côté + */ + public Biome getBiome(TileOrientation side) { + return this.sideBiomes.get(side); + } + + /** + * Récupère le biome dominant de la tuile, basé sur la majorité des côtés. + * + * @return Le biome dominant + */ + private Biome getDominantBiome() { + TileOrientation[] sides = TileOrientation.values(); + + int firstBiomeCount = 0; + int secondBiomeCount = 0; + Biome firstBiome = this.getBiome(sides[0]); + Biome secondBiome = null; + + for (TileOrientation side : sides) { + Biome currentBiome = this.getBiome(side); + if (currentBiome.equals(firstBiome)) { + firstBiomeCount++; + } else { + secondBiome = currentBiome; + secondBiomeCount++; + } + } + + if (firstBiomeCount > secondBiomeCount) { + return firstBiome; + } else if (firstBiomeCount < secondBiomeCount) { + return secondBiome; + } + + return null; + } + + /** + * Récupère les biomes associés à chaque côté de la tuile. + * + * @return Tableau des biomes de la tuile + */ + public Biome[] getBiomes() { + Biome[] biomes = new Biome[TileOrientation.values().length]; + for (TileOrientation side : TileOrientation.values()) { + biomes[side.ordinal()] = this.getBiome(side); + } + return biomes; + } + + /** + * Effectue une rotation de la tuile dans le sens horaire ou antihoraire. + * + * @param clockwise Si true, rotation horaire; sinon antihoraire + */ + public void rotate(boolean clockwise) { + TileOrientation[] sides = TileOrientation.values(); + HashMap newBiomesMap = new HashMap<>(); + + for (int i = 0; i < sides.length; i++) { + TileOrientation side = sides[i]; + TileOrientation newSide = clockwise ? sides[(i + 1) % sides.length] : sides[(i + sides.length - 1) % sides.length]; + newBiomesMap.put(newSide, this.sideBiomes.get(side)); + } + + this.sideBiomes = newBiomesMap; + this.repaint(); + } + + /** + * Vérifie si un biome spécifique existe sur la tuile. + * + * @param biome Le biome à vérifier + * @return true si le biome est présent, false sinon + */ + public boolean containsBiome(Biome biome) { + for (TileOrientation side : TileOrientation.values()) { + if (this.getBiome(side) == biome) { + return true; + } + } + return false; + } + + /** + * Récupère le côté de la tuile en fonction de la position (x, y) relative. + * + * @param x La position x + * @param y La position y + * @return Le côté de la tuile correspondant + */ + private TileOrientation determineSide(int x, int y) { + int radius = this.getRadius(); + TileOrientation[] sides = TileOrientation.values(); + double angle = Cell.to360Degrees(Math.toDegrees(Math.atan2(y - radius, x - radius)) + 120); + + int floorSide = (int) Math.floor(Cell.to360Degrees(angle - 2) / 60); + int ceilSide = (int) Math.floor(Cell.to360Degrees(angle + 2) / 60); + + if (floorSide == ceilSide) { + return sides[floorSide]; + } + + Biome floorBiome = this.getBiome(sides[floorSide]); + Biome dominantBiome = this.getDominantBiome(); + + if (dominantBiome == null && y > radius) { + return TileOrientation.SOUTH; + } + + if (dominantBiome == null && y < radius) { + return TileOrientation.NORTH; + } + + return floorBiome.equals(dominantBiome) ? sides[ceilSide] : sides[floorSide]; + } + + /** + * Dessine une rangée d'hexagones sur la tuile. + * + * @param g2d Le contexte graphique + * @param rowX Position X de la rangée + * @param rowY Position Y de la rangée + * @param radius Rayon des hexagones + * @param rowLength Nombre d'hexagones dans la rangée + */ + private void drawHexagonRow(Graphics2D g2d, double rowX, double rowY, double radius, int rowLength) { + int gRadius = this.getRadius(); + + for (int i = 0; i < rowLength; i++) { + Color[] colors; + int x = (int) Math.round(rowX + radius * Math.sqrt(3) * i); + int y = (int) Math.round(rowY); + + if (x == Math.round(gRadius) && y == Math.round(gRadius)) { + Biome dominantBiome = this.getDominantBiome(); + colors = (dominantBiome != null) ? dominantBiome.getBiomeColors() : this.getBiome(TileOrientation.SOUTH).getBiomeColors(); + } else { + colors = this.getBiome(this.determineSide(x, y)).getBiomeColors(); + } + + g2d.setColor(colors[i % colors.length]); + g2d.fillPolygon(new Hexagon(x, y, (int) Math.ceil(radius), 90)); + } + } + + /** + * Méthode principale de dessin de la tuile. + * + * @param g Le contexte graphique + * @param scale L'échelle de la tuile + */ + protected void paintTile(Graphics g, float scale) { + super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g.create(); + int radius = this.getRadius(); + Point center = new Point(radius, radius); + radius = (int) (radius * scale); + Hexagon hexagon = new Hexagon(center, radius); + + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setClip(hexagon); + + double hexRadius = radius / Math.sqrt(3) / 3; + double paddingX = center.x - radius; + double paddingY = center.y - radius; + + this.drawHexagonRow(g2d, paddingX + radius * 0.5, paddingY + radius - radius * Math.sqrt(3) / 2, hexRadius, 4); + this.drawHexagonRow(g2d, paddingX, paddingY + radius - radius * Math.sqrt(3) / 3, hexRadius, 6); + this.drawHexagonRow(g2d, paddingX - radius * 0.5, paddingY + radius - radius * Math.sqrt(3) / 6, hexRadius, 8); + this.drawHexagonRow(g2d, paddingX - radius, paddingY + radius, hexRadius, 10); + this.drawHexagonRow(g2d, paddingX - radius * 0.5, paddingY + radius + radius * Math.sqrt(3) / 6, hexRadius, 8); + this.drawHexagonRow(g2d, paddingX, paddingY + radius + radius * Math.sqrt(3) / 3, hexRadius, 6); + this.drawHexagonRow(g2d, paddingX + radius * 0.5, paddingY + radius + radius * Math.sqrt(3) / 2, hexRadius, 4); + + g2d.setClip(null); + g2d.setStroke(new BasicStroke((int) radius / 15)); + g2d.setColor(Color.BLACK); + g2d.drawPolygon(hexagon); + + g2d.dispose(); + } + + protected void paintTileWithPosition(Graphics g, float scale) { + super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g.create(); + int radius = this.getRadius(); + Point center = new Point(this.getXCoord(), this.getYCoord()); + radius = (int) (radius * scale); + Hexagon hexagon = new Hexagon(center, radius); + + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setClip(hexagon); + + double hexRadius = radius / Math.sqrt(3) / 3; + double paddingX = center.x - radius; + double paddingY = center.y - radius; + + this.drawHexagonRow(g2d, paddingX + radius * 0.5, paddingY + radius - radius * Math.sqrt(3) / 2, hexRadius, 4); + this.drawHexagonRow(g2d, paddingX, paddingY + radius - radius * Math.sqrt(3) / 3, hexRadius, 6); + this.drawHexagonRow(g2d, paddingX - radius * 0.5, paddingY + radius - radius * Math.sqrt(3) / 6, hexRadius, 8); + this.drawHexagonRow(g2d, paddingX - radius, paddingY + radius, hexRadius, 10); + this.drawHexagonRow(g2d, paddingX - radius * 0.5, paddingY + radius + radius * Math.sqrt(3) / 6, hexRadius, 8); + this.drawHexagonRow(g2d, paddingX, paddingY + radius + radius * Math.sqrt(3) / 3, hexRadius, 6); + this.drawHexagonRow(g2d, paddingX + radius * 0.5, paddingY + radius + radius * Math.sqrt(3) / 2, hexRadius, 4); + + g2d.setClip(null); + g2d.setStroke(new BasicStroke((int) radius / 15)); + g2d.setColor(Color.BLACK); + g2d.drawPolygon(hexagon); + + g2d.dispose(); + } + + @Override + public void paintComponent(Graphics g) { + this.paintTile(g, 1f); + } +} diff --git a/TestV2/src/fr/monkhanny/dorfromantik/gui/GameModeSelectionPanel.java b/TestV2/src/fr/monkhanny/dorfromantik/gui/GameModeSelectionPanel.java index 34c3781..887ac7f 100644 --- a/TestV2/src/fr/monkhanny/dorfromantik/gui/GameModeSelectionPanel.java +++ b/TestV2/src/fr/monkhanny/dorfromantik/gui/GameModeSelectionPanel.java @@ -113,7 +113,16 @@ public class GameModeSelectionPanel extends JPanel { return seedPanel; } - public String getSeed() { + public String getStringSeed() { return seedField.getText(); } + + public long getLongSeed(){ + try{ + return Long.parseLong(seedField.getText()); + } catch (NumberFormatException e){ + System.err.println("Invalid seed, using current time as seed"); + return System.currentTimeMillis(); + } + } }