From 371a4b8be4b6fc701b7862dc473f4f5b14f1edfa Mon Sep 17 00:00:00 2001 From: Artem Didytschuk Date: Fri, 25 Jun 2021 00:10:35 +0200 Subject: [PATCH] =?UTF-8?q?Grundger=C3=BCst=20f=C3=BCr=20Inventory=20hinzu?= =?UTF-8?q?gef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unfertig aber ich mach das schon ;)) Container größtenteils schon fertig, werde wahrscheinlich noch ein paar hinzufügen müssen. Muss außerdem noch zum HUD verbunden werden, das würde ich auch machen, wenn das niemand vor mir macht. Ich hätte an eine box gedacht, in der das ausgewählte Item angezeigt wird und das Item wird mit einer taste gewechselt. --- Zoelda/src/main/entities/Snake.java | 5 +- .../main/entities/player/PlayerInventory.java | 73 +++++++++++++++++++ Zoelda/src/main/items/Item.java | 13 ++++ 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 Zoelda/src/main/entities/player/PlayerInventory.java create mode 100644 Zoelda/src/main/items/Item.java diff --git a/Zoelda/src/main/entities/Snake.java b/Zoelda/src/main/entities/Snake.java index 3dcdef4..5a1a8cd 100644 --- a/Zoelda/src/main/entities/Snake.java +++ b/Zoelda/src/main/entities/Snake.java @@ -1,10 +1,11 @@ package main.entities; -import java.util.ArrayList; - import ea.Vektor; import main.Main; import main.SheetLoader; +import main.entities.player.Player; + +import java.util.ArrayList; public class Snake extends LivingEntity { diff --git a/Zoelda/src/main/entities/player/PlayerInventory.java b/Zoelda/src/main/entities/player/PlayerInventory.java new file mode 100644 index 0000000..945243f --- /dev/null +++ b/Zoelda/src/main/entities/player/PlayerInventory.java @@ -0,0 +1,73 @@ +package main.entities.player; + +import main.items.Item; + +/** + * Container Klasse für das Inventar des Spielers, + * eventuell später verallgemeinerbar für Truhen o.ä. je nach design dieser. + */ +public class PlayerInventory { + private int coins; + private Item[] items; + private int currentItem; + + /** + * Erstellt ein Player Inventar, welches einen Coin counter und ein Item Inventar enthält. + * @param inventorySize Gibt die größe des Item inventars als int an. + */ + public PlayerInventory(int inventorySize){ + items = new Item [inventorySize]; + } + + /** + * Getter für den Coin counter + * @return Gibt die Anzahl der Coins im Inventar als int zurück. + */ + public int getCoins(){ + return coins; + } + + /** + * Getter für das Items im Inventar. + * @return gibt ein Array mit allen Item Objekten zurück, die im Inventar enthalten sind. + */ + public Item[] getItems(){ + return items; + } + + /** + * Ersetzt das jetzige Inventar um ein neues mit im Item-Array items angegebenen Items. + * @param items Array mit Items die das Inventar ersetzen sollen. + */ + public void setItems(Item[] items) { + this.items = items; + } + + /** + * Setzt das gerade ausgewählte Item fest. + * @param currentItem int gibt an welcher Index des Item Arrays ausgewählt werden soll. + */ + public void setCurrentItem(int currentItem) { + this.currentItem = currentItem; + } + + /** + * Methode zum Hinzufügen von Items. + * @param newItem Das Item, dass hinzugefügt werden soll. + * @return gibt zurück ob das Item hinzugefügt wurde, d.h. true wenn hinzugefügt und false wenn nicht hinzugefügt. + */ + public boolean addItem(Item newItem){ + for(int i =0;i< items.length;i++) { + if (items[i] == null) { + items[i] = newItem; + return true; + } + } + return false; + } + + + + + +} diff --git a/Zoelda/src/main/items/Item.java b/Zoelda/src/main/items/Item.java new file mode 100644 index 0000000..f7b665e --- /dev/null +++ b/Zoelda/src/main/items/Item.java @@ -0,0 +1,13 @@ +package main.items; +//TODO:Hier soll die Item Oberklasse entstehen +public class Item { + + /** + * TODO: + * @return + */ + public String getIconPath(){ + TODO: + return ""; + } +}