diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..ddbf269c0d40191ec643ba46c71f2c20ce46012e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ExternalStorageConfigurationManager" enabled="true" /> + <component name="MavenProjectsManager"> + <option name="originalFiles"> + <list> + <option value="$PROJECT_DIR$/MavenChess/MavenChess/pom.xml" /> + </list> + </option> + </component> + <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="openjdk-20" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/out" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000000000000000000000000000000000000..424af03d629d1aeb7a594b118cfaca31c9e96946 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="AutoImportSettings"> + <option name="autoReloadType" value="ALL" /> + </component> + <component name="ChangeListManager"> + <list default="true" id="48ce1122-5195-4c9c-a37c-f12e93132e40" name="Changes" comment="" /> + <option name="SHOW_DIALOG" value="false" /> + <option name="HIGHLIGHT_CONFLICTS" value="true" /> + <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> + <option name="LAST_RESOLUTION" value="IGNORE" /> + </component> + <component name="Git.Settings"> + <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> + </component> + <component name="MarkdownSettingsMigration"> + <option name="stateVersion" value="1" /> + </component> + <component name="MavenImportPreferences"> + <option name="generalSettings"> + <MavenGeneralSettings> + <option name="useMavenConfig" value="true" /> + <option name="usePluginRegistry" value="true" /> + </MavenGeneralSettings> + </option> + </component> + <component name="ProjectId" id="2PCl7NkLwAmovZQ0EAfpUg8ge55" /> + <component name="ProjectLevelVcsManager"> + <ConfirmationsSetting value="2" id="Add" /> + </component> + <component name="ProjectViewState"> + <option name="hideEmptyMiddlePackages" value="true" /> + <option name="showLibraryContents" value="true" /> + </component> + <component name="PropertiesComponent"><![CDATA[{ + "keyToString": { + "ASKED_ADD_EXTERNAL_FILES": "true", + "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "WebServerToolWindowFactoryState": "false", + "git-widget-placeholder": "main", + "last_opened_file_path": "/home/tuna/Documents/test", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "project.structure.last.edited": "Project", + "project.structure.proportion": "0.15", + "project.structure.side.proportion": "0.2", + "settings.build.tools.auto.reload": "ALL", + "settings.editor.selected.configurable": "MavenSettings", + "vue.rearranger.settings.migration": "true" + } +}]]></component> + <component name="RunAnythingCache"> + <option name="myCommands"> + <command value="mvn package" /> + </option> + </component> + <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> + <component name="TaskManager"> + <task active="true" id="Default" summary="Default task"> + <changelist id="48ce1122-5195-4c9c-a37c-f12e93132e40" name="Changes" comment="" /> + <created>1682968775520</created> + <option name="number" value="Default" /> + <option name="presentableId" value="Default" /> + <updated>1682968775520</updated> + <workItem from="1682968776515" duration="319000" /> + <workItem from="1683094832856" duration="998000" /> + <workItem from="1683099105537" duration="842000" /> + <workItem from="1683116894461" duration="148000" /> + <workItem from="1683893818874" duration="10904000" /> + <workItem from="1683975652605" duration="12733000" /> + <workItem from="1684064051497" duration="8587000" /> + </task> + <servers /> + </component> + <component name="TypeScriptGeneratedFilesManager"> + <option name="version" value="3" /> + </component> + <component name="VcsManagerConfiguration"> + <option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" /> + </component> + <component name="XDebuggerManager"> + <breakpoint-manager> + <breakpoints> + <line-breakpoint enabled="true" type="java-line"> + <url>file://$PROJECT_DIR$/MavenChess/MavenChess/src/main/java/view/BoardView.java</url> + <line>233</line> + <option name="timeStamp" value="1" /> + </line-breakpoint> + </breakpoints> + </breakpoint-manager> + </component> +</project> \ No newline at end of file diff --git a/MavenChess/MavenChess/src/main/java/controller/Game.java b/MavenChess/MavenChess/src/main/java/controller/Game.java index e1c8ff888e505a438e85bbe7b87bc7d5a716f6d8..16e28585d1395835ab2538eb28193b9611595cc8 100644 --- a/MavenChess/MavenChess/src/main/java/controller/Game.java +++ b/MavenChess/MavenChess/src/main/java/controller/Game.java @@ -1,5 +1,6 @@ package controller; +import javafx.scene.control.Alert; import javafx.scene.layout.AnchorPane; import model.*; import view.*; @@ -8,7 +9,7 @@ import java.util.ArrayList; public class Game { private int status; - public static final int WHITE_TURN = 1, BLACK_TURN = 2, WHITE_WON = 3, BLACK_WON = 4; + public static final int WHITE_TURN = 1, BLACK_TURN = 2,GAME_OVER=3; public Game() { status = WHITE_TURN; @@ -53,7 +54,7 @@ public class Game { // if piece is colored (aka targeted), we consider it an action to apply (tile click) if(clickedPiece.isTargeted()) { TileView tile = boardView.getTile(clickedPiece.getPosition().getID()); - clickTile(tile, board, boardView, material, model, log, hud); + clickTile(tile, board, boardView, material, model, log, hud,group2d); return; } if(clickedPiece.isWhite() && isWhiteTurn() || clickedPiece.isBlack() && isBlackTurn()) { @@ -129,7 +130,7 @@ public class Game { } } - public void clickTile(TileView clickedTile, Board board, BoardView boardView, CustomMaterial material, Custom3dModel model, Log log, HUD hud) { + public void clickTile(TileView clickedTile, Board board, BoardView boardView, CustomMaterial material, Custom3dModel model, Log log, HUD hud, AnchorPane group2d) { boolean moved = false; // to tell if an action/movement was used or not @@ -283,16 +284,10 @@ public class Game { nextTurn(); // change player turn log.save(board, boardView); // saves current board hud.rollbackShow(); // show rollback button (if not showed already) - + hud.addGiveup(group2d); // signals if there is a check ! boolean echec = checkVerification(board); // test the opponent check (turn just changed) if(echec) { - if (isWhiteTurn()) { - System.out.println("echec"); - } - if (isBlackTurn()) { - System.out.println("echec"); - } // signals if there is a checkmate ! boolean canPreventMate = false; @@ -307,12 +302,8 @@ public class Game { // checkmate !!! if(!canPreventMate) { - if (isWhiteTurn()) { + hud.afficheMessagefini(getStatus(),group2d,this); - } - if (isBlackTurn()) { - - } } } } diff --git a/MavenChess/MavenChess/src/main/java/controller/Main.java b/MavenChess/MavenChess/src/main/java/controller/Main.java index 40ef9e4aa7288c2c70db707fe9c2d7ad0b70f213..32b69fb99434d86afeeac53e61a1209b79a6f4a6 100644 --- a/MavenChess/MavenChess/src/main/java/controller/Main.java +++ b/MavenChess/MavenChess/src/main/java/controller/Main.java @@ -78,6 +78,7 @@ public class Main extends Application { // init - 2d interface hud = new HUD(); + hud.resize(stage.getWidth(), stage.getHeight()); hud.addAllToScene(group2d); @@ -88,7 +89,8 @@ public class Main extends Application { log = new Log(); // event -------------------------------------------------------------- - + // event - GiveUp buttons (mouse click) + hud.initEventGiveup(game,group2d); // event - camera rotation (mouse dragging) camera.initMouseControl(scene.get3d()); // allow user to move camera with mouse, with some constraints @@ -106,7 +108,7 @@ public class Main extends Application { // event - click on (visual) "colored tiles" to move the selected piece there for(int n = 0 ; n < 64 ; n++) { TileView tile = boardView.getTile(n); - tile.getObj().addEventHandler(MouseEvent.MOUSE_CLICKED, event -> game.clickTile(tile, board, boardView, material, model, log, hud)); + tile.getObj().addEventHandler(MouseEvent.MOUSE_CLICKED, event -> game.clickTile(tile, board, boardView, material, model, log, hud,group2d)); } // event - window resize diff --git a/MavenChess/MavenChess/src/main/java/view/HUD.java b/MavenChess/MavenChess/src/main/java/view/HUD.java index a6440811ccff656f936ad91449d218ac68f45cde..d2d53da10533773dcb4d2aad0a31bc8f2ccfb9e1 100644 --- a/MavenChess/MavenChess/src/main/java/view/HUD.java +++ b/MavenChess/MavenChess/src/main/java/view/HUD.java @@ -1,8 +1,12 @@ package view; +import controller.Game; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.ObservableListBase; +import javafx.event.ActionEvent; +import javafx.scene.control.Alert; +import javafx.scene.control.Button; import javafx.scene.control.ComboBox; import javafx.scene.effect.Glow; import javafx.scene.image.Image; @@ -11,6 +15,11 @@ import javafx.scene.input.MouseEvent; import javafx.scene.layout.AnchorPane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; +import javafx.stage.WindowEvent; +import model.Piece; + +import java.nio.file.FileStore; +import java.util.EventListener; public class HUD { @@ -18,8 +27,13 @@ public class HUD { private ImageView standard_imgView, variant_imgView, rollback_imgView; private Rectangle darkener; + private Button giveup; + private Button mutualGiveup; + private boolean giveupShowed; + private ComboBox combo; private boolean comboShowed; + private Alert finishedGame; public HUD() { standard_img = new Image("/standard.jpg"); @@ -56,6 +70,15 @@ public class HUD { rollback_imgView.setFitWidth(64); rollbackHide(); + + giveup = new Button(); + giveup.setText("Give UP"); + mutualGiveup = new Button(); + mutualGiveup.setText("Mutual Suicide"); + + giveupShowed = false; + + String pieces[] = {"Queen", "Rook", "Bishop", "Knight"}; combo = new ComboBox(FXCollections.observableArrayList(pieces)); combo.getSelectionModel().select(0); @@ -80,6 +103,15 @@ public class HUD { rollback_imgView.setX(width - 36 - (avg / 12)); rollback_imgView.setY(height - 56 - (avg / 12)); rollback_imgView.setFitWidth(avg / 12); + + giveup.setTranslateX(64); + giveup.setTranslateY(height-100); + giveup.setStyle("-fx-font: 20 arial;"); + + + mutualGiveup.setTranslateX(200); + mutualGiveup.setTranslateY(height-100); + mutualGiveup.setStyle("-fx-font: 20 arial;"); //combo.setStyle("-fx-font: " + avg / 24 + " arial;"); //combo.setTranslateX(avg / 24); //combo.setTranslateY(avg / 24); @@ -118,6 +150,12 @@ public class HUD { comboShowed = true; } } + public void addGiveup(AnchorPane group2d){ + if(!giveupShowed){ + group2d.getChildren().addAll(giveup,mutualGiveup); + giveupShowed = true; + } + } public void removeCombo(AnchorPane group2d) { if(comboShowed) { @@ -137,4 +175,39 @@ public class HUD { } return id; } + + public void afficheMessagefini(int color,AnchorPane group2D,Game game){ + + finishedGame = new Alert(Alert.AlertType.INFORMATION); + finishedGame.setTitle("Fin du jeu"); + finishedGame.setHeaderText("Le jeux fini"); + if(color == Piece.WHITE){ + + finishedGame.setContentText("Le gentleman possèdant les belles pieces de couleur claire a décidé de donner la victoire a son adversaire"); + + } + else if(color == Piece.BLACK) { + finishedGame.setContentText("Le gentleman possèdant les belles pieces de couleur sombre a décidé de donner la victoire a son adversaire"); + + } + else{ + finishedGame.setContentText("Les deux gentlemans sont cons et ont décidé de donner la victoire a leurs adversaires"); + } + finishedGame.showAndWait(); + removeGiveUps(group2D); + rollbackHide(); + game.setStatus(Game.GAME_OVER); + + } + + public void removeGiveUps(AnchorPane group2d){ + group2d.getChildren().removeAll(giveup,mutualGiveup); + + } + + public void initEventGiveup(Game game,AnchorPane group2d) { + giveup.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> afficheMessagefini(game.getStatus(),group2d,game)); + mutualGiveup.addEventHandler(MouseEvent.MOUSE_CLICKED, event ->afficheMessagefini(3,group2d,game)); + + } } diff --git a/MavenChess/MavenChess/target/classes/controller/Main.class b/MavenChess/MavenChess/target/classes/controller/Main.class index 1bc0d25ec3cc5cf6c7e59f74b24bec10dc697615..9b83fd76fad385a5877f695d84049fe35c95538a 100644 Binary files a/MavenChess/MavenChess/target/classes/controller/Main.class and b/MavenChess/MavenChess/target/classes/controller/Main.class differ