Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #37 from NaulaN/develop
Browse files Browse the repository at this point in the history
Sprint n°4 (Ajustement)
  • Loading branch information
naulan-chrzaszcz authored Jun 19, 2022
2 parents e2ec1ab + 04637bf commit 77808bf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
26 changes: 15 additions & 11 deletions src/main/java/fr/sae/terraria/Terraria.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import java.util.Objects;


/**
* <a href="https://github.com/NaulaN/SAE-Terraria-Like/wiki/Document-utilisateur">Document utilisateur</a>
* <a href="https://github.com/NaulaN/SAE-Terraria-Like">Repo Github</a>
*/
public class Terraria extends Application
{
// Constantes
Expand All @@ -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;

Expand Down Expand Up @@ -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());
Expand All @@ -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) -> {
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
23 changes: 6 additions & 17 deletions src/main/java/fr/sae/terraria/modele/entities/tools/Tool.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

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 = 1;
public static final int DEFAULT_DAMAGE = 2;

private final IntegerProperty durability;

Expand All @@ -24,7 +21,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 */
Expand All @@ -36,18 +34,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; }
Expand Down

0 comments on commit 77808bf

Please sign in to comment.