From f1e2ca6806babda49f2fee2f2ebabb409bc35529 Mon Sep 17 00:00:00 2001 From: NaulaN Date: Sun, 19 Jun 2022 12:03:43 +0200 Subject: [PATCH 1/4] Durabbility of pickaxe is variable --- .../modele/entities/tools/MaterialSet.java | 16 +++++++++++++--- .../sae/terraria/modele/entities/tools/Tool.java | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/fr/sae/terraria/modele/entities/tools/MaterialSet.java b/src/main/java/fr/sae/terraria/modele/entities/tools/MaterialSet.java index 4c03141..e56119c 100644 --- a/src/main/java/fr/sae/terraria/modele/entities/tools/MaterialSet.java +++ b/src/main/java/fr/sae/terraria/modele/entities/tools/MaterialSet.java @@ -3,12 +3,22 @@ public enum MaterialSet { - WOOD, - STONE, - IRON; + WOOD(1.), + STONE(1.5), + IRON(2.); + private final double durabilityMultiplicator; + + + MaterialSet(double durabilityMultiplicator) + { + this.durabilityMultiplicator = durabilityMultiplicator; + } public static boolean isWood(MaterialSet material) { return material == MaterialSet.WOOD; } public static boolean isStone(MaterialSet material) { return material == MaterialSet.STONE; } public static boolean isIron(MaterialSet material) { return material == MaterialSet.IRON; } + + + public double getDurabilityMultiplicator() { return this.durabilityMultiplicator; } } diff --git a/src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java b/src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java index f36e22b..ea2276c 100644 --- a/src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java +++ b/src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java @@ -24,7 +24,8 @@ public Tool(final ToolSet tool, final MaterialSet material) super(); this.tool = tool; this.material = material; - this.durability = new SimpleIntegerProperty(Tool.DEFAULT_DURABILITY); + + this.durability = new SimpleIntegerProperty((int) (Tool.DEFAULT_DURABILITY*material.getDurabilityMultiplicator())); } /** Utilise l'outil */ From 9fa98cec54531911a6893d3587a1c0d0623a1b8d Mon Sep 17 00:00:00 2001 From: NaulaN Date: Sun, 19 Jun 2022 12:13:11 +0200 Subject: [PATCH 2/4] Ajustement du main --- src/main/java/fr/sae/terraria/Terraria.java | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/fr/sae/terraria/Terraria.java b/src/main/java/fr/sae/terraria/Terraria.java index 7457810..2769572 100644 --- a/src/main/java/fr/sae/terraria/Terraria.java +++ b/src/main/java/fr/sae/terraria/Terraria.java @@ -19,6 +19,10 @@ import java.util.Objects; +/** + * Document utilisateur + * Repo Github + */ public class Terraria extends Application { // Constantes @@ -28,6 +32,7 @@ public class Terraria extends Application public static final int DISPLAY_RENDERING_HEIGHT = 256; private final String titleWindow = "Terraria-Like"; + private final boolean resizable = false; private final int widthWindow = 1280; private final int heightWindow = 720; @@ -59,14 +64,17 @@ public void start(Stage stage) throws IOException Scene menu = new Scene(fxmlLoader.load(), this.widthWindow, this.heightWindow); stage.setTitle(this.titleWindow); - stage.setResizable(false); + stage.setResizable(this.resizable); BooleanProperty switchScene = new SimpleBooleanProperty(); // Change de scènes suivant les valeurs boolean switchScene.addListener((obs, oldB, newB) -> stage.setScene(newB.equals(Boolean.TRUE) ? game : menu)); stage.setScene(game); - int[] timePressedKey = new int[1]; // Permet que le menu ne clignote pas et reste afficher même si le bouton 'M' est encore enfoncer. + stage.sizeToScene(); + + // Permet que le menu ne clignote pas et reste afficher même si le bouton 'M' est encore enfoncer. + int[] timePressedKey = new int[] {1}; stage.addEventFilter(KeyEvent.KEY_PRESSED, key -> { if (key.getCode() == KeyCode.M && timePressedKey[0] <= 1) switchScene.set(!switchScene.get()); @@ -75,7 +83,6 @@ public void start(Stage stage) throws IOException key.consume(); }); stage.addEventFilter(KeyEvent.KEY_RELEASED, key -> timePressedKey[0] = 1); - stage.sizeToScene(); // Synchronise les changements du joueur entre les contrôleurs. stage.sceneProperty().addListener(((obs, oldScene, newScene) -> { @@ -92,18 +99,15 @@ public void start(Stage stage) throws IOException } } })); - stage.widthProperty().addListener((obs, oldV, newV) -> { - gameController.scaleMultiplicatorWidth = (newV.intValue() / Terraria.DISPLAY_RENDERING_WIDTH); - }); - stage.heightProperty().addListener((obs, oldV, newV) -> { - gameController.scaleMultiplicatorHeight = ((newV.intValue()-gameController.title.getPrefHeight()) / Terraria.DISPLAY_RENDERING_HEIGHT); - }); + // Quand le joueur meurt, le jeux ce met à l'arrêt gameController.environment.getPlayer().pvProperty().addListener((obs, oldV, newV) ->{ - if (newV.longValue() == 0){ + if (newV.intValue() == 0) stage.close(); - } }); + stage.widthProperty().addListener((obs, oldWidth, newWidth) -> gameController.scaleMultiplicatorWidth = (newWidth.intValue() / Terraria.DISPLAY_RENDERING_WIDTH)); + stage.heightProperty().addListener((obs, oldHeight, newHeight) -> gameController.scaleMultiplicatorHeight = ((newHeight.intValue()-gameController.title.getPrefHeight()) / Terraria.DISPLAY_RENDERING_HEIGHT)); + stage.show(); } } \ No newline at end of file From 2aea3a5e57fc9d738d7f4d562010bcf1a16e5636 Mon Sep 17 00:00:00 2001 From: NaulaN Date: Sun, 19 Jun 2022 12:33:55 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Ajustement=20des=20d=C3=A9g=C3=A2ts=20des?= =?UTF-8?q?=20outils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../terraria/modele/entities/tools/Tool.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java b/src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java index ea2276c..f4b07cb 100644 --- a/src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java +++ b/src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java @@ -11,7 +11,7 @@ public class Tool implements StowableObjectType public static final double CRAFTED_WITH_IRON = 1.5; public static final int DEFAULT_DURABILITY = 100; - public static final int DEFAULT_DAMAGE = 1; + public static final int DEFAULT_DAMAGE = 2; private final IntegerProperty durability; @@ -37,18 +37,9 @@ public void use() public double damage() { - if (this.tool == ToolSet.SWORD) { - if (this.material == MaterialSet.WOOD) - return Tool.DEFAULT_DAMAGE * Tool.CRAFTED_WITH_WOOD; - else if (this.material == MaterialSet.IRON) - return Tool.DEFAULT_DAMAGE * Tool.CRAFTED_WITH_IRON; - } else { - if (this.material == MaterialSet.WOOD) - return Tool.DEFAULT_DAMAGE * (Tool.CRAFTED_WITH_WOOD/2); - else if (this.material == MaterialSet.IRON) - return Tool.DEFAULT_DAMAGE * (Tool.CRAFTED_WITH_IRON/2); - } - return Tool.DEFAULT_DAMAGE; + if (Tool.isSword(this)) + return Tool.DEFAULT_DAMAGE * this.material.getDurabilityMultiplicator(); + return Tool.DEFAULT_DAMAGE * (this.material.getDurabilityMultiplicator()/2); } public static boolean isAxe(Tool tool) { return tool.getTypeOfTool() == ToolSet.AXE; } From 04637bfb47b60b906806cc397a7a773803bc0598 Mon Sep 17 00:00:00 2001 From: NaulaN Date: Sun, 19 Jun 2022 13:42:00 +0200 Subject: [PATCH 4/4] =?UTF-8?q?Ajustement=20des=20d=C3=A9g=C3=A2ts=20des?= =?UTF-8?q?=20outils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java b/src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java index f4b07cb..a8fd09a 100644 --- a/src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java +++ b/src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java @@ -7,9 +7,6 @@ public class Tool implements StowableObjectType { - public static final double CRAFTED_WITH_WOOD = 1.; - public static final double CRAFTED_WITH_IRON = 1.5; - public static final int DEFAULT_DURABILITY = 100; public static final int DEFAULT_DAMAGE = 2;