diff --git a/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java b/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java index 72d06bd..7351bd8 100644 --- a/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java +++ b/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java @@ -9,10 +9,15 @@ import java.util.LinkedList; import java.util.Random; public class Battle { - private LinkedList enemies; - private LinkedList heroes; - private WindowOfBattle windowOfBattle; + private final LinkedList enemies; + private final LinkedList heroes; + private final WindowOfBattle windowOfBattle; private Timer timer; + + public void setTurnBelongTo(BattlePerson turnBelongTo) { + this.turnBelongTo = turnBelongTo; + } + private BattlePerson turnBelongTo; private LinkedList turnOrder; @@ -22,6 +27,8 @@ public class Battle { private boolean playerAttack; + public void setDelay(int delay) { this.delay = delay; } + public boolean isTimerStopped() { return timerStopped; } diff --git a/src/main/java/ruscz/game/gameOfProd/BattleUI/CommandList.java b/src/main/java/ruscz/game/gameOfProd/BattleUI/CommandList.java index 583931b..6df4068 100644 --- a/src/main/java/ruscz/game/gameOfProd/BattleUI/CommandList.java +++ b/src/main/java/ruscz/game/gameOfProd/BattleUI/CommandList.java @@ -4,6 +4,8 @@ import ruscz.game.gameOfProd.Windows.WindowOfBattle; import javax.swing.*; +import java.awt.*; + import static ruscz.game.gameOfProd.Windows.WindowOfBattle.CELL_SIZE; public class CommandList extends JPanel { @@ -11,5 +13,14 @@ public class CommandList extends JPanel { setSize(CELL_SIZE * 8, CELL_SIZE * 6); setLocation(CELL_SIZE * 4, CELL_SIZE * 2); setVisible(false); + + JLabel text = new JLabel("It's not a situation to use command line, idiot!"); + JButton jButton = new JButton("Hide this field"); + jButton.addActionListener(e -> { + this.setVisible(false); + }); + + add(text); + add(jButton); } } diff --git a/src/main/java/ruscz/game/gameOfProd/BattleUI/ConsoleInput.java b/src/main/java/ruscz/game/gameOfProd/BattleUI/ConsoleInput.java index b62c4e9..3ee6326 100644 --- a/src/main/java/ruscz/game/gameOfProd/BattleUI/ConsoleInput.java +++ b/src/main/java/ruscz/game/gameOfProd/BattleUI/ConsoleInput.java @@ -31,9 +31,9 @@ public class ConsoleInput extends JPanel { }); list.addActionListener(e -> { - submit.setEnabled(false); - list.setEnabled(false); - exit.setEnabled(false); +// submit.setEnabled(false); +// list.setEnabled(false); +// exit.setEnabled(false); window.getCommandList().setVisible(true); }); diff --git a/src/main/java/ruscz/game/gameOfProd/BattleUI/ItemsInventory.java b/src/main/java/ruscz/game/gameOfProd/BattleUI/ItemsInventory.java index 3554a6f..ffa531a 100644 --- a/src/main/java/ruscz/game/gameOfProd/BattleUI/ItemsInventory.java +++ b/src/main/java/ruscz/game/gameOfProd/BattleUI/ItemsInventory.java @@ -1,5 +1,10 @@ package ruscz.game.gameOfProd.BattleUI; +import ruscz.game.gameOfProd.Image.ImageCell; +import ruscz.game.gameOfProd.Inventory.InventoryManager; +import ruscz.game.gameOfProd.Inventory.Item; +import ruscz.game.gameOfProd.Inventory.ItemAction; +import ruscz.game.gameOfProd.Inventory.ItemPanel; import ruscz.game.gameOfProd.Windows.WindowOfBattle; import javax.swing.*; @@ -8,10 +13,75 @@ import java.awt.*; import static ruscz.game.gameOfProd.Windows.WindowOfBattle.CELL_SIZE; public class ItemsInventory extends JPanel { + private final JPanel items; + private final ImageCell imageCell; + private final WindowOfBattle windowOfBattle; + public ItemsInventory(WindowOfBattle window){ + imageCell = new ImageCell(); + imageCell.imageItem("TransparentIcons.png"); + windowOfBattle = window; + setSize(CELL_SIZE * 8, CELL_SIZE * 6); setLocation(CELL_SIZE * 4, CELL_SIZE * 2); setBackground(Color.yellow); setVisible(false); + + items = new JPanel(); + + JButton returnToMenu = new JButton("x"); + returnToMenu.addActionListener(e -> { + window.getMenuOfActions().getAttack().setEnabled(true); + window.getMenuOfActions().getConsole().setEnabled(true); + window.getMenuOfActions().getInventory().setEnabled(true); + window.getMenuOfActions().getEscape().setEnabled(true); + + setVisible(false); + }); + add(items); + add(returnToMenu); } + + public void refreshItemsInField() { + for (Component c: items.getComponents()) + items.remove(c); + + System.out.println(InventoryManager.getInventory()); + + for (Item item: InventoryManager.getInventory()){ + JPanel jPanel = new JPanel(); + jPanel.setLayout(new GridLayout(1, 5)); + jPanel.setSize(CELL_SIZE * 8, 32); + ItemPanel itemPanel = new ItemPanel(imageCell, item.getImage()); + itemPanel.setSize(32, 32); + + jPanel.add(itemPanel); + jPanel.add(new JLabel(item.getName())); + jPanel.add(new JLabel(String.valueOf(item.getMultiplicity()))); + jPanel.add(new JLabel(String.valueOf(item.getItemAction()))); + + if (item.getItemAction().equals(ItemAction.HEAL)){ + JButton use = new JButton("Use"); + use.addActionListener(e -> { + setVisible(false); + windowOfBattle.getBattle().getHeroes().getFirst().heal(100); + windowOfBattle.getMenuOfActions().setVisible(false); + windowOfBattle.getEnemyDescription().setVisible(false); + windowOfBattle.writeToOutput(windowOfBattle.getBattle().getHeroes().getFirst().getName() + " heals 100 HP"); + InventoryManager.removeItem(item, 1); + windowOfBattle.getBattle().setTurnBelongTo(null); + windowOfBattle.getBattle().setDelay(2); + windowOfBattle.getBattle().getTimer().start(); + }); + jPanel.add(use); + } + + items.add(jPanel); + } + + items.setVisible(true); + if (items.getComponents().length == 0) items.setVisible(false); + } + + } diff --git a/src/main/java/ruscz/game/gameOfProd/BattleUI/MenuOfActions.java b/src/main/java/ruscz/game/gameOfProd/BattleUI/MenuOfActions.java index b3e827e..efccb6a 100644 --- a/src/main/java/ruscz/game/gameOfProd/BattleUI/MenuOfActions.java +++ b/src/main/java/ruscz/game/gameOfProd/BattleUI/MenuOfActions.java @@ -51,6 +51,7 @@ public class MenuOfActions extends JPanel { inventory.setEnabled(false); escape.setEnabled(false); + window.getItemsInventory().refreshItemsInField(); window.getItemsInventory().setVisible(true); }); diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java b/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java index b3f7b5c..8b396e6 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Npc.java @@ -16,7 +16,7 @@ import java.util.LinkedList; import java.util.Scanner; public class Npc extends Person { - private MapManager mapManager; + private final MapManager mapManager; private String name; private int direction; private int width; @@ -36,14 +36,6 @@ public class Npc extends Person { loadNpc(); } - public Npc(int x, int y, String name, String battle, Map map, MapManager mapManager) { - super(x, y, map); - this.name = name; - this.battle = battle; - this.mapManager = mapManager; - loadNpc(); - } - public Npc(int x, int y, Map map, MapManager mapManager) { super(x, y, map); this.mapManager = mapManager; @@ -57,7 +49,7 @@ public class Npc extends Person { } final int[] i = {0}; timer = new Timer(500, actionEvent -> { - if (i[0] == directions.size()) stopTimer(endX, endY); + if (i[0] == directions.size()) stopNPCMove(endX, endY); else { switch (directions.get(i[0])) { case UP: @@ -83,7 +75,7 @@ public class Npc extends Person { timer.start(); } - private void stopTimer(int endX, int endY) { + private void stopNPCMove(int endX, int endY) { timer.stop(); if (battle != null && endX == mapManager.getActualMap().getPerson().getX() && endY == mapManager.getActualMap().getPerson().getY()) { mapManager.getWindow().startBattle(battle); diff --git a/src/main/java/ruscz/game/gameOfProd/Game.java b/src/main/java/ruscz/game/gameOfProd/Game.java index 82d8a34..7e1effe 100644 --- a/src/main/java/ruscz/game/gameOfProd/Game.java +++ b/src/main/java/ruscz/game/gameOfProd/Game.java @@ -48,7 +48,7 @@ public class Game extends JFrame { //tohle spustí na začátku bitvu // add(battle); -// battle.startBattle(); +// battle.startBattle("storageroombattle"); //Tohle spustí na začátku tileset overview //new LevelEditor(); diff --git a/src/main/java/ruscz/game/gameOfProd/Inventory/Item.java b/src/main/java/ruscz/game/gameOfProd/Inventory/Item.java index 0d27cc8..3739435 100644 --- a/src/main/java/ruscz/game/gameOfProd/Inventory/Item.java +++ b/src/main/java/ruscz/game/gameOfProd/Inventory/Item.java @@ -1,12 +1,16 @@ package ruscz.game.gameOfProd.Inventory; +import ruscz.game.gameOfProd.Image.ImageCell; + +import javax.swing.*; import java.util.Objects; public class Item { private ItemAction itemAction; - private String name; + private final String name; private int multiplicity; - private int image; + private final int image; + public Item(String name, int multiplicity, int image, String itemAction) { this.name = parseName(name); diff --git a/src/main/java/ruscz/game/gameOfProd/Inventory/ItemPanel.java b/src/main/java/ruscz/game/gameOfProd/Inventory/ItemPanel.java new file mode 100644 index 0000000..496289e --- /dev/null +++ b/src/main/java/ruscz/game/gameOfProd/Inventory/ItemPanel.java @@ -0,0 +1,21 @@ +package ruscz.game.gameOfProd.Inventory; + +import ruscz.game.gameOfProd.Image.ImageCell; + +import javax.swing.*; +import java.awt.*; + +public class ItemPanel extends JPanel { + ImageCell imageCell; + int item; + + public ItemPanel(ImageCell imageCell, int item){ + this.imageCell = imageCell; + this.item = item; + } + + @Override + public void paint(Graphics g) { + g.drawImage(imageCell.getImagesOfItems().get(item), 0, 0, 32,32, null); + } +} diff --git a/src/main/resources/save/savedGame/events.txt b/src/main/resources/save/savedGame/events.txt index 02fad9d..e69de29 100644 --- a/src/main/resources/save/savedGame/events.txt +++ b/src/main/resources/save/savedGame/events.txt @@ -1,80 +0,0 @@ - - tutorial - - - 11 - 6 - false - - - - - openspace - - - 6 - 4 - true - - - 14 - 16 - false - - - 1 - 2 - true - - - 15 - 7 - true - - - - - office - - - 4 - 2 - false - - - 1 - 9 - true - - - - - boss - - - 4 - 18 - true - - - - - treasure - - - 6 - 1 - true - - - - - storageroom - - - 6 - 2 - true - - - diff --git a/src/main/resources/save/savedGame/person.txt b/src/main/resources/save/savedGame/person.txt index 43fde47..e69de29 100644 --- a/src/main/resources/save/savedGame/person.txt +++ b/src/main/resources/save/savedGame/person.txt @@ -1,6 +0,0 @@ - - storageroom - 6 - 2 - 1 - \ No newline at end of file