moved FX app to client dir
This commit is contained in:
19
pom.xml
19
pom.xml
@@ -88,24 +88,13 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
||||||
<groupId>org.openjfx</groupId>
|
<groupId>org.openjfx</groupId>
|
||||||
<artifactId>javafx-maven-plugin</artifactId>
|
<artifactId>javafx-maven-plugin</artifactId>
|
||||||
<version>0.0.8</version>
|
<version>0.0.8</version>
|
||||||
<executions>
|
<configuration>
|
||||||
<execution>
|
<mainClass>client.DeckGridAppFX</mainClass>
|
||||||
<!-- Default configuration for running with: mvn clean javafx:run -->
|
</configuration>
|
||||||
<id>default-cli</id>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>org.example.mesosll07/org.example.mesosll07.HelloApplication</mainClass>
|
|
||||||
<launcher>app</launcher>
|
|
||||||
<jlinkZipName>app</jlinkZipName>
|
|
||||||
<jlinkImageName>app</jlinkImageName>
|
|
||||||
<noManPages>true</noManPages>
|
|
||||||
<stripDebug>true</stripDebug>
|
|
||||||
<noHeaderFiles>true</noHeaderFiles>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package Server;
|
package client;
|
||||||
|
|
||||||
|
import Server.*;
|
||||||
import Server.Automaton.ActionResult;
|
import Server.Automaton.ActionResult;
|
||||||
import Server.Automaton.Game;
|
import Server.Automaton.Game;
|
||||||
import Server.Cards.*;
|
import Server.Cards.*;
|
||||||
import Server.Utils.GameException;
|
|
||||||
import javafx.animation.*;
|
import javafx.animation.*;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
@@ -31,12 +31,9 @@ import org.apache.pdfbox.pdmodel.PDDocument;
|
|||||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DeckGridAppFX extends Application {
|
public class DeckGridAppFX extends Application {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.example.mesosll07;
|
package client;
|
||||||
|
|
||||||
import Server.Automaton.Game;
|
import Server.Automaton.Game;
|
||||||
import Server.Player;
|
import Server.Player;
|
||||||
@@ -8,11 +8,12 @@ module org.example.mesosll07 {
|
|||||||
requires org.apache.logging.log4j;
|
requires org.apache.logging.log4j;
|
||||||
|
|
||||||
opens org.example.mesosll07 to javafx.fxml;
|
opens org.example.mesosll07 to javafx.fxml;
|
||||||
exports org.example.mesosll07;
|
|
||||||
exports Server;
|
exports Server;
|
||||||
opens Server to javafx.fxml;
|
opens Server to javafx.fxml;
|
||||||
exports Server.Cards;
|
exports Server.Cards;
|
||||||
opens Server.Cards to javafx.fxml;
|
opens Server.Cards to javafx.fxml;
|
||||||
exports Server.Automaton;
|
exports Server.Automaton;
|
||||||
opens Server.Automaton to javafx.fxml;
|
opens Server.Automaton to javafx.fxml;
|
||||||
|
exports client;
|
||||||
|
opens client to javafx.fxml;
|
||||||
}
|
}
|
||||||
@@ -1,208 +0,0 @@
|
|||||||
package org.example.mesosll07;
|
|
||||||
|
|
||||||
import javafx.application.Application;
|
|
||||||
import javafx.embed.swing.SwingFXUtils;
|
|
||||||
import javafx.geometry.Insets;
|
|
||||||
import javafx.geometry.Pos;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.scene.control.Button;
|
|
||||||
import javafx.scene.control.Label;
|
|
||||||
import javafx.scene.control.ScrollPane;
|
|
||||||
import javafx.scene.image.Image;
|
|
||||||
import javafx.scene.image.ImageView;
|
|
||||||
import javafx.scene.layout.BorderPane;
|
|
||||||
import javafx.scene.layout.HBox;
|
|
||||||
import javafx.scene.layout.VBox;
|
|
||||||
import javafx.stage.FileChooser;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
||||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DeckGridApp extends Application {
|
|
||||||
|
|
||||||
// Inizializza il Logger
|
|
||||||
private static final Logger logger = LogManager.getLogger(DeckGridApp.class);
|
|
||||||
|
|
||||||
private PDDocument document;
|
|
||||||
private PDFRenderer pdfRenderer;
|
|
||||||
private int totalCards = 0;
|
|
||||||
|
|
||||||
// Contenitori per le tre righe
|
|
||||||
private HBox topRow;
|
|
||||||
private HBox centerRow;
|
|
||||||
private HBox bottomRow;
|
|
||||||
private Button btnShuffle;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(Stage primaryStage) {
|
|
||||||
primaryStage.setTitle("Tavolo da Gioco - Carte Casuali");
|
|
||||||
logger.info("Avvio dell'applicazione JavaFX");
|
|
||||||
|
|
||||||
// Pulsanti
|
|
||||||
Button btnLoad = new Button("Carica PDF Mazzo");
|
|
||||||
btnShuffle = new Button("Rimescola Carte");
|
|
||||||
btnShuffle.setDisable(true); // Disabilitato finché non si carica un PDF
|
|
||||||
|
|
||||||
btnLoad.setOnAction(e -> loadPdf(primaryStage));
|
|
||||||
btnShuffle.setOnAction(e -> distributeRandomCards());
|
|
||||||
|
|
||||||
HBox topMenu = new HBox(15, btnLoad, btnShuffle);
|
|
||||||
topMenu.setAlignment(Pos.CENTER);
|
|
||||||
topMenu.setPadding(new Insets(10));
|
|
||||||
|
|
||||||
// Setup delle tre righe (spazio tra le carte impostato a 10px)
|
|
||||||
topRow = createRowContainer();
|
|
||||||
centerRow = createRowContainer();
|
|
||||||
bottomRow = createRowContainer();
|
|
||||||
|
|
||||||
// Contenitore verticale per le righe
|
|
||||||
VBox tableArea = new VBox(30,
|
|
||||||
new Label("TOP (8 Carte):"), topRow,
|
|
||||||
new Label("CENTER (6 Carte):"), centerRow,
|
|
||||||
new Label("BOTTOM (7 Carte):"), bottomRow
|
|
||||||
);
|
|
||||||
tableArea.setAlignment(Pos.CENTER);
|
|
||||||
tableArea.setPadding(new Insets(20));
|
|
||||||
|
|
||||||
// Mettiamo il tavolo in uno ScrollPane nel caso le carte siano troppo grandi per lo schermo
|
|
||||||
ScrollPane scrollPane = new ScrollPane(tableArea);
|
|
||||||
scrollPane.setFitToWidth(true);
|
|
||||||
|
|
||||||
BorderPane root = new BorderPane();
|
|
||||||
root.setTop(topMenu);
|
|
||||||
root.setCenter(scrollPane);
|
|
||||||
|
|
||||||
// Finestra un po' più grande per contenere tutte queste carte
|
|
||||||
Scene scene = new Scene(root, 1200, 800);
|
|
||||||
primaryStage.setScene(scene);
|
|
||||||
primaryStage.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private HBox createRowContainer() {
|
|
||||||
HBox row = new HBox(15); // 15px di spazio tra una carta e l'altra
|
|
||||||
row.setAlignment(Pos.CENTER);
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadPdf(Stage stage) {
|
|
||||||
FileChooser fileChooser = new FileChooser();
|
|
||||||
fileChooser.setTitle("Seleziona il PDF del mazzo di carte");
|
|
||||||
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("File PDF", "*.pdf"));
|
|
||||||
File file = fileChooser.showOpenDialog(stage);
|
|
||||||
|
|
||||||
if (file != null) {
|
|
||||||
try {
|
|
||||||
if (document != null) {
|
|
||||||
document.close();
|
|
||||||
}
|
|
||||||
logger.info("Caricamento file PDF: {}", file.getAbsolutePath());
|
|
||||||
document = PDDocument.load(file);
|
|
||||||
pdfRenderer = new PDFRenderer(document);
|
|
||||||
totalCards = document.getNumberOfPages();
|
|
||||||
|
|
||||||
logger.info("PDF caricato. Pagine totali (carte): {}", totalCards);
|
|
||||||
btnShuffle.setDisable(false);
|
|
||||||
|
|
||||||
// Distribuisci le carte per la prima volta
|
|
||||||
distributeRandomCards();
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error("Errore nel caricamento del PDF", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void distributeRandomCards() {
|
|
||||||
if (document == null || totalCards == 0) return;
|
|
||||||
|
|
||||||
logger.info("Inizio rimescolamento e distribuzione carte...");
|
|
||||||
|
|
||||||
// Pulisce il tavolo dalle carte precedenti
|
|
||||||
topRow.getChildren().clear();
|
|
||||||
centerRow.getChildren().clear();
|
|
||||||
bottomRow.getChildren().clear();
|
|
||||||
|
|
||||||
// 1. Crea una lista con tutti gli indici (da 0 al numero totale di pagine)
|
|
||||||
List<Integer> deckIndices = new ArrayList<>();
|
|
||||||
for (int i = 0; i < totalCards; i++) {
|
|
||||||
deckIndices.add(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Mescola la lista (Simula la mescolata del mazzo)
|
|
||||||
Collections.shuffle(deckIndices);
|
|
||||||
|
|
||||||
// 3. Distribuisci nelle righe (evitando IndexOutOfBounds se il PDF ha meno di 21 pagine)
|
|
||||||
// Riga Top: 8 carte
|
|
||||||
populateRow(topRow, deckIndices, 0, 8);
|
|
||||||
|
|
||||||
// Riga Center: 6 carte
|
|
||||||
populateRow(centerRow, deckIndices, 8, 6);
|
|
||||||
|
|
||||||
// Riga Bottom: 7 carte
|
|
||||||
populateRow(bottomRow, deckIndices, 14, 7);
|
|
||||||
|
|
||||||
logger.info("Distribuzione completata.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void populateRow(HBox row, List<Integer> deckIndices, int startIndex, int numberOfCards) {
|
|
||||||
for (int i = 0; i < numberOfCards; i++) {
|
|
||||||
int actualIndex = startIndex + i;
|
|
||||||
|
|
||||||
// Se abbiamo esaurito le carte nel PDF, interrompiamo
|
|
||||||
if (actualIndex >= deckIndices.size()) {
|
|
||||||
logger.warn("Il PDF non ha abbastanza carte per riempire questa riga.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pageNumber = deckIndices.get(actualIndex);
|
|
||||||
ImageView cardImage = createCardImageView(pageNumber);
|
|
||||||
|
|
||||||
if (cardImage != null) {
|
|
||||||
row.getChildren().add(cardImage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ImageView createCardImageView(int pageIndex) {
|
|
||||||
try {
|
|
||||||
// Renderizza la pagina. Usiamo 100 DPI invece di 150 per risparmiare RAM,
|
|
||||||
// dato che ora stiamo generando 21 immagini contemporaneamente.
|
|
||||||
BufferedImage bim = pdfRenderer.renderImageWithDPI(pageIndex, 100);
|
|
||||||
Image fxImage = SwingFXUtils.toFXImage(bim, null);
|
|
||||||
|
|
||||||
ImageView imageView = new ImageView(fxImage);
|
|
||||||
// Impostiamo l'altezza fissa per le carte, in modo che stiano sullo schermo
|
|
||||||
imageView.setFitHeight(180);
|
|
||||||
imageView.setPreserveRatio(true);
|
|
||||||
imageView.setStyle("-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.5), 5, 0, 0, 0);");
|
|
||||||
|
|
||||||
return imageView;
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error("Errore durante il rendering della pagina {}", pageIndex, e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() throws Exception {
|
|
||||||
if (document != null) {
|
|
||||||
document.close();
|
|
||||||
logger.info("Documento PDF chiuso correttamente.");
|
|
||||||
}
|
|
||||||
logger.info("Applicazione terminata.");
|
|
||||||
super.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
launch(args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,263 +0,0 @@
|
|||||||
package org.example.mesosll07;
|
|
||||||
|
|
||||||
import javafx.application.Application;
|
|
||||||
import javafx.embed.swing.SwingFXUtils;
|
|
||||||
import javafx.geometry.Insets;
|
|
||||||
import javafx.geometry.Pos;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.scene.control.Button;
|
|
||||||
import javafx.scene.control.Label;
|
|
||||||
import javafx.scene.control.ScrollPane;
|
|
||||||
import javafx.scene.image.Image;
|
|
||||||
import javafx.scene.image.ImageView;
|
|
||||||
import javafx.scene.layout.*;
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import javafx.scene.text.Font;
|
|
||||||
import javafx.scene.text.FontWeight;
|
|
||||||
import javafx.stage.FileChooser;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
||||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class DeckGridApp2 extends Application {
|
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(DeckGridApp2.class);
|
|
||||||
|
|
||||||
private PDDocument document;
|
|
||||||
private PDFRenderer pdfRenderer;
|
|
||||||
private int totalCards = 0;
|
|
||||||
|
|
||||||
// Contenitori Layout
|
|
||||||
private HBox topRow;
|
|
||||||
private HBox centerRow;
|
|
||||||
private HBox bottomRow;
|
|
||||||
private HBox playersArea; // NUOVO: Area per i giocatori
|
|
||||||
private Button btnShuffle;
|
|
||||||
|
|
||||||
// --- LOGICA DI GIOCO SIMULATA ---
|
|
||||||
public enum CardType {
|
|
||||||
CACCIA, UTENSILI, RITUALI, COSTRUZIONI
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Card {
|
|
||||||
int pdfPageIndex;
|
|
||||||
CardType type;
|
|
||||||
|
|
||||||
public Card(int pdfPageIndex, CardType type) {
|
|
||||||
this.pdfPageIndex = pdfPageIndex;
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
public CardType getType() { return type; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Player {
|
|
||||||
String name;
|
|
||||||
int food;
|
|
||||||
int money;
|
|
||||||
List<Card> hand = new ArrayList<>();
|
|
||||||
|
|
||||||
public Player(String name, int food, int money) {
|
|
||||||
this.name = name;
|
|
||||||
this.food = food;
|
|
||||||
this.money = money;
|
|
||||||
}
|
|
||||||
public List<Card> getHand() { return hand; }
|
|
||||||
}
|
|
||||||
// --------------------------------
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(Stage primaryStage) {
|
|
||||||
primaryStage.setTitle("Tavolo da Gioco - Board & Players");
|
|
||||||
|
|
||||||
Button btnLoad = new Button("Carica PDF Mazzo");
|
|
||||||
btnShuffle = new Button("Rimescola & Distribuisci");
|
|
||||||
btnShuffle.setDisable(true);
|
|
||||||
|
|
||||||
btnLoad.setOnAction(e -> loadPdf(primaryStage));
|
|
||||||
btnShuffle.setOnAction(e -> distributeAll());
|
|
||||||
|
|
||||||
HBox topMenu = new HBox(15, btnLoad, btnShuffle);
|
|
||||||
topMenu.setAlignment(Pos.CENTER);
|
|
||||||
topMenu.setPadding(new Insets(10));
|
|
||||||
|
|
||||||
topRow = createRowContainer();
|
|
||||||
centerRow = createRowContainer();
|
|
||||||
bottomRow = createRowContainer();
|
|
||||||
|
|
||||||
// NUOVO: Inizializza l'area giocatori
|
|
||||||
playersArea = new HBox(30);
|
|
||||||
playersArea.setAlignment(Pos.CENTER);
|
|
||||||
playersArea.setPadding(new Insets(20));
|
|
||||||
|
|
||||||
VBox tableArea = new VBox(20,
|
|
||||||
new Label("TOP (8 Carte):"), topRow,
|
|
||||||
new Label("CENTER (6 Carte):"), centerRow,
|
|
||||||
new Label("BOTTOM (7 Carte):"), bottomRow,
|
|
||||||
new Label("--- SITUAZIONE GIOCATORI ---"), playersArea
|
|
||||||
);
|
|
||||||
tableArea.setAlignment(Pos.CENTER);
|
|
||||||
tableArea.setPadding(new Insets(20));
|
|
||||||
|
|
||||||
ScrollPane scrollPane = new ScrollPane(tableArea);
|
|
||||||
scrollPane.setFitToWidth(true);
|
|
||||||
|
|
||||||
BorderPane root = new BorderPane();
|
|
||||||
root.setTop(topMenu);
|
|
||||||
root.setCenter(scrollPane);
|
|
||||||
|
|
||||||
Scene scene = new Scene(root, 1300, 900);
|
|
||||||
primaryStage.setScene(scene);
|
|
||||||
primaryStage.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private HBox createRowContainer() {
|
|
||||||
HBox row = new HBox(10);
|
|
||||||
row.setAlignment(Pos.CENTER);
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadPdf(Stage stage) {
|
|
||||||
FileChooser fileChooser = new FileChooser();
|
|
||||||
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("File PDF", "*.pdf"));
|
|
||||||
File file = fileChooser.showOpenDialog(stage);
|
|
||||||
|
|
||||||
if (file != null) {
|
|
||||||
try {
|
|
||||||
if (document != null) document.close();
|
|
||||||
document = PDDocument.load(file);
|
|
||||||
pdfRenderer = new PDFRenderer(document);
|
|
||||||
totalCards = document.getNumberOfPages();
|
|
||||||
btnShuffle.setDisable(false);
|
|
||||||
|
|
||||||
distributeAll();
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error("Errore PDF", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void distributeAll() {
|
|
||||||
if (document == null || totalCards == 0) return;
|
|
||||||
|
|
||||||
topRow.getChildren().clear();
|
|
||||||
centerRow.getChildren().clear();
|
|
||||||
bottomRow.getChildren().clear();
|
|
||||||
playersArea.getChildren().clear();
|
|
||||||
|
|
||||||
List<Integer> deck = new ArrayList<>();
|
|
||||||
for (int i = 0; i < totalCards; i++) deck.add(i);
|
|
||||||
Collections.shuffle(deck);
|
|
||||||
|
|
||||||
// Distribuisce sul tavolo le prime 21 carte
|
|
||||||
int index = 0;
|
|
||||||
index = populateTable(topRow, deck, index, 8);
|
|
||||||
index = populateTable(centerRow, deck, index, 6);
|
|
||||||
index = populateTable(bottomRow, deck, index, 7);
|
|
||||||
|
|
||||||
// NUOVO: Simula 2 giocatori con le carte rimanenti
|
|
||||||
Random rand = new Random();
|
|
||||||
List<Player> players = Arrays.asList(
|
|
||||||
new Player("Giocatore 1 (Tribù Rossa)", rand.nextInt(15), rand.nextInt(50)),
|
|
||||||
new Player("Giocatore 2 (Tribù Blu)", rand.nextInt(15), rand.nextInt(50))
|
|
||||||
);
|
|
||||||
|
|
||||||
// Assegna 5 carte a caso a ogni giocatore e simula il loro Tipo
|
|
||||||
CardType[] types = CardType.values();
|
|
||||||
for (Player p : players) {
|
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
if (index < deck.size()) {
|
|
||||||
CardType randomType = types[rand.nextInt(types.length)];
|
|
||||||
p.getHand().add(new Card(deck.get(index), randomType));
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Renderizza i giocatori nella UI
|
|
||||||
renderPlayers(players);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int populateTable(HBox row, List<Integer> deck, int startIndex, int amount) {
|
|
||||||
for (int i = 0; i < amount; i++) {
|
|
||||||
if (startIndex >= deck.size()) break;
|
|
||||||
ImageView card = createCardImage(deck.get(startIndex), 150); // Altezza 150px
|
|
||||||
if (card != null) row.getChildren().add(card);
|
|
||||||
startIndex++;
|
|
||||||
}
|
|
||||||
return startIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- NUOVO: RENDERIZZAZIONE GIOCATORI E RAGGRUPPAMENTO (JAVA 8) ---
|
|
||||||
private void renderPlayers(List<Player> players) {
|
|
||||||
for (Player player : players) {
|
|
||||||
VBox playerBox = new VBox(10);
|
|
||||||
playerBox.setPadding(new Insets(15));
|
|
||||||
playerBox.setStyle("-fx-border-color: #555; -fx-border-width: 2; -fx-border-radius: 10; -fx-background-color: #f9f9f9; -fx-background-radius: 10;");
|
|
||||||
|
|
||||||
// Intestazione Giocatore
|
|
||||||
Label nameLbl = new Label(player.name);
|
|
||||||
nameLbl.setFont(Font.font("System", FontWeight.BOLD, 16));
|
|
||||||
|
|
||||||
// Risorse Cibo e Soldi
|
|
||||||
Label statsLbl = new Label("🍖 Cibo: " + player.food + " | 💰 Money: " + player.money);
|
|
||||||
statsLbl.setTextFill(Color.DARKRED);
|
|
||||||
statsLbl.setFont(Font.font("System", FontWeight.BOLD, 14));
|
|
||||||
|
|
||||||
playerBox.getChildren().addAll(nameLbl, statsLbl);
|
|
||||||
|
|
||||||
// JAVA 8 MAGIA: Raggruppa le carte del giocatore per Tipo!
|
|
||||||
Map<CardType, List<Card>> groupedCards = player.getHand().stream()
|
|
||||||
.collect(Collectors.groupingBy(Card::getType));
|
|
||||||
|
|
||||||
// Itera sui gruppi creati e genera la grafica
|
|
||||||
groupedCards.forEach((type, cardsOfType) -> {
|
|
||||||
Label typeLbl = new Label("Tipo: " + type.name() + " (" + cardsOfType.size() + ")");
|
|
||||||
typeLbl.setFont(Font.font("System", FontWeight.NORMAL, 12));
|
|
||||||
|
|
||||||
HBox cardImagesRow = new HBox(5);
|
|
||||||
for (Card c : cardsOfType) {
|
|
||||||
// Carte più piccole (90px) per l'area giocatore
|
|
||||||
ImageView img = createCardImage(c.pdfPageIndex, 90);
|
|
||||||
if (img != null) cardImagesRow.getChildren().add(img);
|
|
||||||
}
|
|
||||||
|
|
||||||
playerBox.getChildren().addAll(typeLbl, cardImagesRow);
|
|
||||||
});
|
|
||||||
|
|
||||||
playersArea.getChildren().add(playerBox);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ImageView createCardImage(int pageIndex, int height) {
|
|
||||||
try {
|
|
||||||
BufferedImage bim = pdfRenderer.renderImageWithDPI(pageIndex, 100);
|
|
||||||
Image fxImage = SwingFXUtils.toFXImage(bim, null);
|
|
||||||
ImageView imageView = new ImageView(fxImage);
|
|
||||||
imageView.setFitHeight(height);
|
|
||||||
imageView.setPreserveRatio(true);
|
|
||||||
imageView.setStyle("-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.4), 4, 0, 0, 0);");
|
|
||||||
return imageView;
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error("Errore rendering pagina {}", pageIndex, e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() throws Exception {
|
|
||||||
if (document != null) document.close();
|
|
||||||
super.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
launch(args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,271 +0,0 @@
|
|||||||
package org.example.mesosll07;
|
|
||||||
|
|
||||||
import Server.Automaton.Game;
|
|
||||||
import Server.Era;
|
|
||||||
import Server.Player;
|
|
||||||
import Server.TotemColor;
|
|
||||||
import javafx.application.Application;
|
|
||||||
import javafx.embed.swing.SwingFXUtils;
|
|
||||||
import javafx.geometry.Insets;
|
|
||||||
import javafx.geometry.Pos;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.scene.control.Button;
|
|
||||||
import javafx.scene.control.Label;
|
|
||||||
import javafx.scene.control.ScrollPane;
|
|
||||||
import javafx.scene.image.Image;
|
|
||||||
import javafx.scene.image.ImageView;
|
|
||||||
import javafx.scene.layout.BorderPane;
|
|
||||||
import javafx.scene.layout.HBox;
|
|
||||||
import javafx.scene.layout.VBox;
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import javafx.scene.text.Font;
|
|
||||||
import javafx.scene.text.FontWeight;
|
|
||||||
import javafx.stage.FileChooser;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
||||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import Server.Cards.*;
|
|
||||||
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
public class DeckGridAppFX extends Application {
|
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(DeckGridAppFX.class);
|
|
||||||
|
|
||||||
private PDDocument documentFront;
|
|
||||||
private PDDocument documentBack;
|
|
||||||
private PDFRenderer pdfRendererFront;
|
|
||||||
private PDFRenderer pdfRendererBack;
|
|
||||||
private int totalCards = 0;
|
|
||||||
|
|
||||||
// Contenitori Layout
|
|
||||||
private HBox topRow;
|
|
||||||
private HBox centerRow;
|
|
||||||
private HBox bottomRow;
|
|
||||||
private HBox playersArea; // NUOVO: Area per i giocatori
|
|
||||||
private Button btnShuffle;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(Stage primaryStage) {
|
|
||||||
|
|
||||||
List<Player> players = new ArrayList<>();
|
|
||||||
players.add(new Player("Yoshi", TotemColor.YELLOW));
|
|
||||||
players.add(new Player("Pippo", TotemColor.PURPLE));
|
|
||||||
players.add(new Player("John", TotemColor.RED));
|
|
||||||
players.add(new Player("Baggio", TotemColor.BLUE));
|
|
||||||
players.add(new Player("Gino", TotemColor.GREEN));
|
|
||||||
|
|
||||||
Game game = new Game(players);
|
|
||||||
|
|
||||||
InputStream frontStream = getClass().getResourceAsStream("/files/Cards_total_front_PROMO.pdf");
|
|
||||||
InputStream backStream = getClass().getResourceAsStream("/files/Cards_total_back_PROMO.pdf");
|
|
||||||
InputStream csvStream = getClass().getResourceAsStream("/files/cards.csv");
|
|
||||||
|
|
||||||
try {
|
|
||||||
documentFront = PDDocument.load(frontStream);
|
|
||||||
pdfRendererFront = new PDFRenderer(documentFront);
|
|
||||||
|
|
||||||
documentBack = PDDocument.load(backStream);
|
|
||||||
pdfRendererBack = new PDFRenderer(documentBack);
|
|
||||||
|
|
||||||
} catch ( IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
//File fileCsv = new File(getClass().getResource("/files/cards.csv").toURI());
|
|
||||||
game.newGame(csvStream);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
primaryStage.setTitle("Tavolo da Gioco - Board & Players");
|
|
||||||
|
|
||||||
|
|
||||||
btnShuffle = new Button("Rimescola & Distribuisci");
|
|
||||||
btnShuffle.setDisable(true);
|
|
||||||
|
|
||||||
|
|
||||||
btnShuffle.setOnAction(e -> distributeAll(game));
|
|
||||||
|
|
||||||
HBox topMenu = new HBox(15, btnShuffle);
|
|
||||||
topMenu.setAlignment(Pos.CENTER);
|
|
||||||
topMenu.setPadding(new Insets(10));
|
|
||||||
|
|
||||||
topRow = createRowContainer();
|
|
||||||
centerRow = createRowContainer();
|
|
||||||
bottomRow = createRowContainer();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// NUOVO: Inizializza l'area giocatori
|
|
||||||
playersArea = new HBox(30);
|
|
||||||
playersArea.setAlignment(Pos.CENTER);
|
|
||||||
playersArea.setPadding(new Insets(20));
|
|
||||||
|
|
||||||
distributeAll(game);
|
|
||||||
VBox tableArea = new VBox(20,
|
|
||||||
new Label("TOP"), topRow,
|
|
||||||
new Label("CENTER "), centerRow,
|
|
||||||
new Label("DOWN"), bottomRow,
|
|
||||||
new Label("--- SITUAZIONE GIOCATORI ---"), playersArea
|
|
||||||
);
|
|
||||||
tableArea.setAlignment(Pos.CENTER);
|
|
||||||
tableArea.setPadding(new Insets(20));
|
|
||||||
|
|
||||||
ScrollPane scrollPane = new ScrollPane(tableArea);
|
|
||||||
scrollPane.setFitToWidth(true);
|
|
||||||
|
|
||||||
BorderPane root = new BorderPane();
|
|
||||||
root.setTop(topMenu);
|
|
||||||
root.setCenter(scrollPane);
|
|
||||||
|
|
||||||
Scene scene = new Scene(root, 1300, 900);
|
|
||||||
primaryStage.setScene(scene);
|
|
||||||
primaryStage.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private HBox createRowContainer() {
|
|
||||||
HBox row = new HBox(10);
|
|
||||||
row.setAlignment(Pos.CENTER);
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void distributeAll(Game game) {
|
|
||||||
if (documentFront == null) return;
|
|
||||||
|
|
||||||
topRow.getChildren().clear();
|
|
||||||
centerRow.getChildren().clear();
|
|
||||||
bottomRow.getChildren().clear();
|
|
||||||
playersArea.getChildren().clear();
|
|
||||||
|
|
||||||
List<Integer> deck = new ArrayList<>();
|
|
||||||
for (int i = 0; i < 118; i++) deck.add(i);
|
|
||||||
Collections.shuffle(deck);
|
|
||||||
|
|
||||||
// Distribuisce sul tavolo le prime 21 carte
|
|
||||||
int index = 0;
|
|
||||||
index = populateTable(topRow, deck, index, 8);
|
|
||||||
index = populateTable(centerRow, deck, index, 6);
|
|
||||||
index = populateTable(bottomRow, deck, index, 7);
|
|
||||||
|
|
||||||
// NUOVO: Simula 2 giocatori con le carte rimanenti
|
|
||||||
Random rand = new Random();
|
|
||||||
List<Player> players =game.getPlayers();
|
|
||||||
|
|
||||||
// Assegna 5 carte a caso a ogni giocatore e simula il loro Tipo
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (Player p : players) {
|
|
||||||
for (int j=0;j<4;j++){
|
|
||||||
int idx = rand.nextInt(game.getGameBoard().getCardDeck().getTribeDeck().size());
|
|
||||||
Card c = game.getGameBoard().getCardDeck().drawTribeOne();
|
|
||||||
p.getPlayerTribe().addCharacter((CharacterCard) c);
|
|
||||||
}
|
|
||||||
for (int j=0;j<2;j++){
|
|
||||||
int idx = rand.nextInt(game.getGameBoard().getCardDeck().getBuildingDeck(Era.I).size());
|
|
||||||
Card c = game.getGameBoard().getCardDeck().drawBuildingOne(Era.I);
|
|
||||||
p.getPlayerTribe().addBuilding((BuildingCard) c);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Renderizza i giocatori nella UI
|
|
||||||
renderPlayers(players);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int populateTable(HBox row, List<Integer> deck, int startIndex, int amount) {
|
|
||||||
for (int i = 0; i < amount; i++) {
|
|
||||||
if (startIndex >= deck.size()) break;
|
|
||||||
ImageView card = createCardImage(deck.get(startIndex), 150, true); // Altezza 150px
|
|
||||||
if (card != null) row.getChildren().add(card);
|
|
||||||
startIndex++;
|
|
||||||
}
|
|
||||||
return startIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- NUOVO: RENDERIZZAZIONE GIOCATORI E RAGGRUPPAMENTO (JAVA 8) ---
|
|
||||||
private void renderPlayers(List<Player> players) {
|
|
||||||
for (Player player : players) {
|
|
||||||
VBox playerBox = new VBox(10);
|
|
||||||
playerBox.setPadding(new Insets(15));
|
|
||||||
playerBox.setStyle("-fx-border-color: #555; -fx-border-width: 2; -fx-border-radius: 10; -fx-background-color: #f9f9f9; -fx-background-radius: 10;");
|
|
||||||
|
|
||||||
// Intestazione Giocatore
|
|
||||||
Label nameLbl = new Label(player.getNickname());
|
|
||||||
nameLbl.setFont(Font.font("System", FontWeight.BOLD, 16));
|
|
||||||
|
|
||||||
// Risorse Cibo e Soldi
|
|
||||||
Label statsLbl = new Label("🍖 Cibo: " + player.getFoodTokens() + " | 💰 Money: " + player.getPrestigePoints());
|
|
||||||
statsLbl.setTextFill(Color.DARKRED);
|
|
||||||
statsLbl.setFont(Font.font("System", FontWeight.BOLD, 14));
|
|
||||||
|
|
||||||
playerBox.getChildren().addAll(nameLbl, statsLbl);
|
|
||||||
|
|
||||||
// JAVA 8 MAGIA: Raggruppa le carte del giocatore per Tipo!
|
|
||||||
Map<CharacterType, List<CharacterCard>> groupedCards = player.getPlayerTribe().getCharacters().stream()
|
|
||||||
.collect(Collectors.groupingBy(CharacterCard::getCharacterType));
|
|
||||||
|
|
||||||
// Itera sui gruppi creati e genera la grafica
|
|
||||||
groupedCards.forEach((type, cardsOfType) -> {
|
|
||||||
Label typeLbl = new Label("Tipo: " + type.name() + " (" + cardsOfType.size() + ")");
|
|
||||||
typeLbl.setFont(Font.font("System", FontWeight.NORMAL, 12));
|
|
||||||
|
|
||||||
HBox cardImagesRow = new HBox(5);
|
|
||||||
for (Card c : cardsOfType) {
|
|
||||||
// Carte più piccole (90px) per l'area giocatore
|
|
||||||
ImageView img = createCardImage(c.getCardId(), 90, true);
|
|
||||||
if (img != null) cardImagesRow.getChildren().add(img);
|
|
||||||
}
|
|
||||||
|
|
||||||
playerBox.getChildren().addAll(typeLbl, cardImagesRow);
|
|
||||||
});
|
|
||||||
|
|
||||||
playersArea.getChildren().add(playerBox);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ImageView createCardImage(int pageIndex, int height, boolean front) {
|
|
||||||
try {
|
|
||||||
BufferedImage bim =null;
|
|
||||||
if (front) bim = pdfRendererFront.renderImageWithDPI(pageIndex, 100);
|
|
||||||
else bim = pdfRendererBack.renderImageWithDPI(pageIndex, 100);
|
|
||||||
|
|
||||||
Image fxImage = SwingFXUtils.toFXImage(bim, null);
|
|
||||||
ImageView imageView = new ImageView(fxImage);
|
|
||||||
imageView.setFitHeight(height);
|
|
||||||
imageView.setPreserveRatio(true);
|
|
||||||
imageView.setStyle("-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.4), 4, 0, 0, 0);");
|
|
||||||
return imageView;
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error("Errore rendering pagina {}", pageIndex, e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() throws Exception {
|
|
||||||
if (documentFront != null) documentFront.close();
|
|
||||||
super.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
launch(args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package org.example.mesosll07;
|
|
||||||
|
|
||||||
import javafx.application.Application;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class HelloApplication extends Application {
|
|
||||||
@Override
|
|
||||||
public void start(Stage stage) throws IOException {
|
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
|
|
||||||
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
|
|
||||||
stage.setTitle("Hello!");
|
|
||||||
stage.setScene(scene);
|
|
||||||
stage.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package org.example.mesosll07;
|
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.scene.control.Label;
|
|
||||||
|
|
||||||
public class HelloController {
|
|
||||||
@FXML
|
|
||||||
private Label welcomeText;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
protected void onHelloButtonClick() {
|
|
||||||
welcomeText.setText("Welcome to JavaFX Application!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package org.example.mesosll07;
|
|
||||||
|
|
||||||
import javafx.application.Application;
|
|
||||||
|
|
||||||
public class Launcher {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Application.launch(HelloApplication.class, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user