improved directory tree & added battle graphics
This commit is contained in:
commit
583cab479d
@ -9,10 +9,15 @@ import java.util.LinkedList;
|
||||
import java.util.Random;
|
||||
|
||||
public class Battle {
|
||||
private LinkedList<Enemy> enemies;
|
||||
private LinkedList<Hero> heroes;
|
||||
private WindowOfBattle windowOfBattle;
|
||||
private final LinkedList<Enemy> enemies;
|
||||
private final LinkedList<Hero> heroes;
|
||||
private final WindowOfBattle windowOfBattle;
|
||||
private Timer timer;
|
||||
|
||||
public void setTurnBelongTo(BattlePerson turnBelongTo) {
|
||||
this.turnBelongTo = turnBelongTo;
|
||||
}
|
||||
|
||||
private BattlePerson turnBelongTo;
|
||||
|
||||
private LinkedList<BattlePerson> turnOrder;
|
||||
@ -22,6 +27,8 @@ public class Battle {
|
||||
|
||||
private boolean playerAttack;
|
||||
|
||||
public void setDelay(int delay) { this.delay = delay; }
|
||||
|
||||
public boolean isTimerStopped() {
|
||||
return timerStopped;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ public class MenuOfActions extends JPanel {
|
||||
inventory.setEnabled(false);
|
||||
escape.setEnabled(false);
|
||||
|
||||
window.getItemsInventory().refreshItemsInField();
|
||||
window.getItemsInventory().setVisible(true);
|
||||
});
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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);
|
||||
|
||||
21
src/main/java/ruscz/game/gameOfProd/Inventory/ItemPanel.java
Normal file
21
src/main/java/ruscz/game/gameOfProd/Inventory/ItemPanel.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
@ -1,80 +0,0 @@
|
||||
<map>
|
||||
<mapName>tutorial</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>11</x>
|
||||
<y>6</y>
|
||||
<active>false</active>
|
||||
</trigger>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>openspace</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>6</x>
|
||||
<y>4</y>
|
||||
<active>true</active>
|
||||
</trigger>
|
||||
<trigger>
|
||||
<x>14</x>
|
||||
<y>16</y>
|
||||
<active>false</active>
|
||||
</trigger>
|
||||
<chest>
|
||||
<x>1</x>
|
||||
<y>2</y>
|
||||
<active>true</active>
|
||||
</chest>
|
||||
<chest>
|
||||
<x>15</x>
|
||||
<y>7</y>
|
||||
<active>true</active>
|
||||
</chest>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>office</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>4</x>
|
||||
<y>2</y>
|
||||
<active>false</active>
|
||||
</trigger>
|
||||
<chest>
|
||||
<x>1</x>
|
||||
<y>9</y>
|
||||
<active>true</active>
|
||||
</chest>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>boss</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>4</x>
|
||||
<y>18</y>
|
||||
<active>true</active>
|
||||
</trigger>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>treasure</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>6</x>
|
||||
<y>1</y>
|
||||
<active>true</active>
|
||||
</trigger>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>storageroom</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>6</x>
|
||||
<y>2</y>
|
||||
<active>true</active>
|
||||
</trigger>
|
||||
</events>
|
||||
</map>
|
||||
@ -1,6 +0,0 @@
|
||||
<location>
|
||||
<map>storageroom</map>
|
||||
<x>6</x>
|
||||
<y>2</y>
|
||||
<direction>1</direction>
|
||||
</location>
|
||||
Loading…
x
Reference in New Issue
Block a user