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

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine-Bouche committed Jun 17, 2022
2 parents c9ddd6d + a4af44d commit ba297a0
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 91 deletions.
63 changes: 52 additions & 11 deletions src/main/java/fr/sae/terraria/controller/MenuController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,80 @@
public class MenuController implements Initializable
{
@FXML public HBox recipeRock;
@FXML public HBox recipeTorch;

@FXML public HBox recipeWoodPickaxe;
@FXML public HBox recipeStonePickaxe;
@FXML public HBox recipeIronPickaxe;

@FXML public HBox recipeWoodAxe;
@FXML public HBox recipeStoneAxe;
@FXML public HBox recipeIronAxe;

@FXML public HBox recipeWoodSword;
@FXML public HBox recipeStoneSword;
@FXML public HBox recipeIronSword;

public Environment environment = null;
public Player player = null;


@Override public void initialize(URL location, ResourceBundle resources)
{
// Craft de la roche à partir de 3 pierres
this.recipeRock.addEventFilter(Event.ANY, ev -> {
if (ev.getEventType().getName().equalsIgnoreCase("MOUSE_PRESSED"))
this.recipeRock.addEventFilter(Event.ANY, event -> {
if (event.getEventType().getName().equalsIgnoreCase("MOUSE_PRESSED"))
this.player.pickup(Craft.rock(this.environment));
});

this.recipeWoodPickaxe.addEventFilter(Event.ANY, ev -> {
if (ev.getEventType().getName().equalsIgnoreCase("MOUSE_PRESSED"))
this.recipeTorch.addEventFilter(Event.ANY, event -> {
if (event.getEventType().getName().equalsIgnoreCase("MOUSE_PRESSED"))
this.player.pickup(Craft.torch(this.environment));
});


// LES PIOCHES
this.recipeWoodPickaxe.addEventFilter(Event.ANY, event -> {
if (event.getEventType().getName().equalsIgnoreCase("MOUSE_PRESSED"))
this.player.pickup(Craft.pickaxe(this.environment, MaterialSet.WOOD));
});

this.recipeStonePickaxe.addEventFilter(Event.ANY, ev -> {
if (ev.getEventType().getName().equalsIgnoreCase("MOUSE_PRESSED"))
this.recipeStonePickaxe.addEventFilter(Event.ANY, event -> {
if (event.getEventType().getName().equalsIgnoreCase("MOUSE_PRESSED"))
this.player.pickup(Craft.pickaxe(this.environment, MaterialSet.STONE));
});

this.recipeIronPickaxe.addEventFilter(Event.ANY, ev -> {
if (ev.getEventType().getName().equalsIgnoreCase("MOUSE_PRESSED"))
this.recipeIronPickaxe.addEventFilter(Event.ANY, event -> {
if (event.getEventType().getName().equalsIgnoreCase("MOUSE_PRESSED"))
this.player.pickup(Craft.pickaxe(this.environment, MaterialSet.IRON));
});
this.recipeWoodPickaxe.addEventFilter(Event.ANY, ev -> {
if (ev.getEventType().getName().equalsIgnoreCase("MOUSE_PRESSED"))
this.player.pickup(Craft.pickaxe(this.environment, MaterialSet.WOOD));


// LES HACHES
this.recipeWoodAxe.addEventFilter(Event.ANY, event -> {

});

this.recipeStoneAxe.addEventFilter(Event.ANY, event -> {

});

this.recipeIronAxe.addEventFilter(Event.ANY, event -> {

});


// LES EPEES
this.recipeWoodSword.addEventFilter(Event.ANY, event -> {

});

this.recipeStoneSword.addEventFilter(Event.ANY, event -> {

});

this.recipeIronSword.addEventFilter(Event.ANY, event -> {

});
}
}
7 changes: 1 addition & 6 deletions src/main/java/fr/sae/terraria/modele/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
import fr.sae.terraria.modele.entities.Rabbit;
import fr.sae.terraria.modele.entities.Slime;
import fr.sae.terraria.modele.entities.blocks.Block;
import fr.sae.terraria.modele.entities.blocks.BlockSet;
import fr.sae.terraria.modele.entities.blocks.Tree;
import fr.sae.terraria.modele.entities.entity.CollideObjectType;
import fr.sae.terraria.modele.entities.entity.Entity;
import fr.sae.terraria.modele.entities.entity.ReproductiveObjectType;
import fr.sae.terraria.modele.entities.items.Meat;
import fr.sae.terraria.modele.entities.items.Vodka;
import fr.sae.terraria.modele.entities.player.Player;
import fr.sae.terraria.modele.entities.tools.MaterialSet;
Expand Down Expand Up @@ -122,8 +119,6 @@ private void gameLoop()
KeyFrame keyFrame = new KeyFrame(Duration.seconds(Terraria.TARGET_FPS), (ev -> {
// TODO TEST
if (!caught[0]) {
this.player.pickup(new Block(BlockSet.TORCH, this));
this.player.pickup(new Meat(this));
this.player.pickup(new Tool(ToolSet.PICKAXE, MaterialSet.IRON));
this.player.pickup(new Vodka(this));
this.player.pickup(new Tool(ToolSet.SWORD, MaterialSet.IRON));
Expand Down Expand Up @@ -180,7 +175,7 @@ public static Clip playSound(String path, boolean loop)
} catch (Exception e) { e.printStackTrace(); }

if (!Objects.isNull(clip)) {
clip.loop((loop) ? Clip.LOOP_CONTINUOUSLY : 0);
clip.loop(loop ? Clip.LOOP_CONTINUOUSLY : 0);
clip.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ private void loots()
} else if (Block.isRock(this)) {
for (int loot = 0; loot < Block.ROCK_NB_LOOTS; loot++)
player.pickup(Item.STONE);

if (Math.random() > .5)
player.pickup(Item.COAL);
if (Math.random() < .05)
player.pickup(Item.IRON);
} else if (Block.isTallGrass(this)) {
for (int loot = (int) (Math.random()*3)+1; loot <= TallGrass.LOOTS_FIBRE_MAX; loot++)
player.pickup(Item.FIBER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public Meat(final Environment environment)

@Override public void consumes()
{
Player player = environment.getPlayer();
Environment.playSound("sound/eat.wav", false);

Player player = environment.getPlayer();
if (player.getPv() < player.getPvMax())
player.setPv(player.getPv() + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public Vodka(final Environment environment)

@Override public void consumes()
{
Environment.playSound("sound/eat.wav", false);

Player player = environment.getPlayer();
Inventory inventory = player.getInventory();
inventory.get().get(inventory.getPosCursor()).remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fr.sae.terraria.modele.Environment;
import fr.sae.terraria.modele.TileMaps;
import fr.sae.terraria.modele.entities.entity.*;
import fr.sae.terraria.modele.entities.items.Item;
import fr.sae.terraria.modele.entities.player.inventory.Inventory;
import fr.sae.terraria.modele.entities.player.inventory.Stack;
import fr.sae.terraria.vue.View;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import fr.sae.terraria.modele.entities.player.craft.recipes.Ingredient;
import fr.sae.terraria.modele.entities.player.craft.recipes.PickaxeRecipe;
import fr.sae.terraria.modele.entities.player.craft.recipes.RockRecipe;
import fr.sae.terraria.modele.entities.player.craft.recipes.TorchRecipe;
import fr.sae.terraria.modele.entities.player.inventory.Inventory;
import fr.sae.terraria.modele.entities.player.inventory.Stack;
import fr.sae.terraria.modele.entities.tools.MaterialSet;
Expand All @@ -33,6 +34,23 @@ public static Block rock(final Environment environment)
return (!Objects.isNull(rockIngredients)) ? new Block(BlockSet.ROCK, environment) : null;
}

public static Block torch(final Environment environment)
{
Inventory inventory = environment.getPlayer().getInventory();

Ingredient torchIngredients = TorchRecipe.apply(inventory);
if (!Objects.isNull(torchIngredients)) for (int i = 0; i < torchIngredients.get().length; i++) {
Stack stack = torchIngredients.get()[i];

if (Item.isStick(stack.getItem()))
stack.removeQuantity(TorchRecipe.NB_STICKS);
if (Item.isCoal(stack.getItem()))
stack.removeQuantity(TorchRecipe.NB_COALS);
}

return (!Objects.isNull(torchIngredients)) ? new Block(BlockSet.TORCH, environment) : null;
}

public static Tool pickaxe(final Environment environment, final MaterialSet material)
{
Inventory inventory = environment.getPlayer().getInventory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ public static boolean irons(final Ingredient ingredient, final Stack stack, fina
boolean haveEnoughIrons = Item.isIron(stack.getItem()) && stack.haveEnoughQuantity(nbStones);
return haveEnoughIrons && IngredientSet.putStackIntoIngredientsList(ingredient, stack);
}

public static boolean coals(final Ingredient ingredient, final Stack stack, final int nbCoals)
{
boolean haveEnoughCoals = Item.isCoal(stack.getItem()) && stack.haveEnoughQuantity(nbCoals);
return haveEnoughCoals && IngredientSet.putStackIntoIngredientsList(ingredient, stack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class RockRecipe
public static Ingredient apply(final Inventory inventory)
{
Ingredient ingredient = new Ingredient(RockRecipe.NB_INGREDIENTS);
boolean haveEnoughStone ;
boolean haveEnoughStone;

int i = 0;
do {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package fr.sae.terraria.modele.entities.player.craft.recipes;

import fr.sae.terraria.modele.entities.player.inventory.Inventory;
import fr.sae.terraria.modele.entities.player.inventory.Stack;


public class TorchRecipe
{
private static final int NB_INGREDIENTS = 2;
public static final int NB_COALS = 1;
public static final int NB_STICKS = 1;


public static Ingredient apply(final Inventory inventory)
{
Ingredient ingredient = new Ingredient(TorchRecipe.NB_INGREDIENTS);
boolean haveEnoughCoal = false;
boolean haveEnoughSticks = false;

int i = 0;
do {
Stack stack = inventory.get().get(i);

if (!haveEnoughCoal)
haveEnoughCoal = IngredientSet.coals(ingredient, stack, TorchRecipe.NB_COALS);
if (!haveEnoughSticks)
haveEnoughSticks = IngredientSet.sticks(ingredient, stack, TorchRecipe.NB_COALS);
i++;
} while (i < inventory.get().size() && (!haveEnoughCoal || !haveEnoughSticks));

return (haveEnoughCoal && haveEnoughSticks) ? ingredient : null;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package fr.sae.terraria.modele.entities.player.inventory;

import fr.sae.terraria.modele.entities.entity.StowableObjectType;
import fr.sae.terraria.modele.entities.items.Item;
import fr.sae.terraria.modele.entities.player.Player;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.scene.input.KeyCode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public boolean removeQuantity(int quantity)
return false;
}

@Override public String toString(){
@Override public String toString()
{
if (item instanceof Block)
return String.valueOf(((Block) item).getTypeOfBlock());
return item.toString();
Expand Down
Binary file added src/main/resources/fr/sae/terraria/sound/hit.wav
Binary file not shown.
Loading

0 comments on commit ba297a0

Please sign in to comment.