Battle continues.....
This commit is contained in:
parent
28559cbb7e
commit
325a929c3f
@ -9,10 +9,15 @@ import java.util.LinkedList;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class Battle {
|
public class Battle {
|
||||||
private LinkedList<Enemy> enemies;
|
private final LinkedList<Enemy> enemies;
|
||||||
private LinkedList<Hero> heroes;
|
private final LinkedList<Hero> heroes;
|
||||||
private WindowOfBattle windowOfBattle;
|
private final WindowOfBattle windowOfBattle;
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
|
|
||||||
|
public void setTurnBelongTo(BattlePerson turnBelongTo) {
|
||||||
|
this.turnBelongTo = turnBelongTo;
|
||||||
|
}
|
||||||
|
|
||||||
private BattlePerson turnBelongTo;
|
private BattlePerson turnBelongTo;
|
||||||
|
|
||||||
private LinkedList<BattlePerson> turnOrder;
|
private LinkedList<BattlePerson> turnOrder;
|
||||||
@ -22,6 +27,8 @@ public class Battle {
|
|||||||
|
|
||||||
private boolean playerAttack;
|
private boolean playerAttack;
|
||||||
|
|
||||||
|
public void setDelay(int delay) { this.delay = delay; }
|
||||||
|
|
||||||
public boolean isTimerStopped() {
|
public boolean isTimerStopped() {
|
||||||
return timerStopped;
|
return timerStopped;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.CELL_SIZE;
|
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.CELL_SIZE;
|
||||||
|
|
||||||
public class CommandList extends JPanel {
|
public class CommandList extends JPanel {
|
||||||
@ -11,5 +13,14 @@ public class CommandList extends JPanel {
|
|||||||
setSize(CELL_SIZE * 8, CELL_SIZE * 6);
|
setSize(CELL_SIZE * 8, CELL_SIZE * 6);
|
||||||
setLocation(CELL_SIZE * 4, CELL_SIZE * 2);
|
setLocation(CELL_SIZE * 4, CELL_SIZE * 2);
|
||||||
setVisible(false);
|
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 -> {
|
list.addActionListener(e -> {
|
||||||
submit.setEnabled(false);
|
// submit.setEnabled(false);
|
||||||
list.setEnabled(false);
|
// list.setEnabled(false);
|
||||||
exit.setEnabled(false);
|
// exit.setEnabled(false);
|
||||||
|
|
||||||
window.getCommandList().setVisible(true);
|
window.getCommandList().setVisible(true);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
package ruscz.game.gameOfProd.BattleUI;
|
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 ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@ -8,10 +13,75 @@ import java.awt.*;
|
|||||||
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.CELL_SIZE;
|
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.CELL_SIZE;
|
||||||
|
|
||||||
public class ItemsInventory extends JPanel {
|
public class ItemsInventory extends JPanel {
|
||||||
|
private final JPanel items;
|
||||||
|
private final ImageCell imageCell;
|
||||||
|
private final WindowOfBattle windowOfBattle;
|
||||||
|
|
||||||
public ItemsInventory(WindowOfBattle window){
|
public ItemsInventory(WindowOfBattle window){
|
||||||
|
imageCell = new ImageCell();
|
||||||
|
imageCell.imageItem("TransparentIcons.png");
|
||||||
|
windowOfBattle = window;
|
||||||
|
|
||||||
setSize(CELL_SIZE * 8, CELL_SIZE * 6);
|
setSize(CELL_SIZE * 8, CELL_SIZE * 6);
|
||||||
setLocation(CELL_SIZE * 4, CELL_SIZE * 2);
|
setLocation(CELL_SIZE * 4, CELL_SIZE * 2);
|
||||||
setBackground(Color.yellow);
|
setBackground(Color.yellow);
|
||||||
setVisible(false);
|
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);
|
inventory.setEnabled(false);
|
||||||
escape.setEnabled(false);
|
escape.setEnabled(false);
|
||||||
|
|
||||||
|
window.getItemsInventory().refreshItemsInField();
|
||||||
window.getItemsInventory().setVisible(true);
|
window.getItemsInventory().setVisible(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import java.util.LinkedList;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Npc extends Person {
|
public class Npc extends Person {
|
||||||
private MapManager mapManager;
|
private final MapManager mapManager;
|
||||||
private String name;
|
private String name;
|
||||||
private int direction;
|
private int direction;
|
||||||
private int width;
|
private int width;
|
||||||
@ -36,14 +36,6 @@ public class Npc extends Person {
|
|||||||
loadNpc();
|
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) {
|
public Npc(int x, int y, Map map, MapManager mapManager) {
|
||||||
super(x, y, map);
|
super(x, y, map);
|
||||||
this.mapManager = mapManager;
|
this.mapManager = mapManager;
|
||||||
@ -57,7 +49,7 @@ public class Npc extends Person {
|
|||||||
}
|
}
|
||||||
final int[] i = {0};
|
final int[] i = {0};
|
||||||
timer = new Timer(500, actionEvent -> {
|
timer = new Timer(500, actionEvent -> {
|
||||||
if (i[0] == directions.size()) stopTimer(endX, endY);
|
if (i[0] == directions.size()) stopNPCMove(endX, endY);
|
||||||
else {
|
else {
|
||||||
switch (directions.get(i[0])) {
|
switch (directions.get(i[0])) {
|
||||||
case UP:
|
case UP:
|
||||||
@ -83,7 +75,7 @@ public class Npc extends Person {
|
|||||||
timer.start();
|
timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopTimer(int endX, int endY) {
|
private void stopNPCMove(int endX, int endY) {
|
||||||
timer.stop();
|
timer.stop();
|
||||||
if (battle != null && endX == mapManager.getActualMap().getPerson().getX() && endY == mapManager.getActualMap().getPerson().getY()) {
|
if (battle != null && endX == mapManager.getActualMap().getPerson().getX() && endY == mapManager.getActualMap().getPerson().getY()) {
|
||||||
mapManager.getWindow().startBattle(battle);
|
mapManager.getWindow().startBattle(battle);
|
||||||
|
|||||||
@ -48,7 +48,7 @@ public class Game extends JFrame {
|
|||||||
|
|
||||||
//tohle spustí na začátku bitvu
|
//tohle spustí na začátku bitvu
|
||||||
// add(battle);
|
// add(battle);
|
||||||
// battle.startBattle();
|
// battle.startBattle("storageroombattle");
|
||||||
|
|
||||||
//Tohle spustí na začátku tileset overview
|
//Tohle spustí na začátku tileset overview
|
||||||
//new LevelEditor();
|
//new LevelEditor();
|
||||||
|
|||||||
@ -1,12 +1,16 @@
|
|||||||
package ruscz.game.gameOfProd.Inventory;
|
package ruscz.game.gameOfProd.Inventory;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Image.ImageCell;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
private ItemAction itemAction;
|
private ItemAction itemAction;
|
||||||
private String name;
|
private final String name;
|
||||||
private int multiplicity;
|
private int multiplicity;
|
||||||
private int image;
|
private final int image;
|
||||||
|
|
||||||
|
|
||||||
public Item(String name, int multiplicity, int image, String itemAction) {
|
public Item(String name, int multiplicity, int image, String itemAction) {
|
||||||
this.name = parseName(name);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,6 +6,9 @@ import ruscz.game.gameOfProd.Battle.Enemy;
|
|||||||
import ruscz.game.gameOfProd.Battle.Hero;
|
import ruscz.game.gameOfProd.Battle.Hero;
|
||||||
import ruscz.game.gameOfProd.BattleUI.*;
|
import ruscz.game.gameOfProd.BattleUI.*;
|
||||||
import ruscz.game.gameOfProd.Game;
|
import ruscz.game.gameOfProd.Game;
|
||||||
|
import ruscz.game.gameOfProd.Image.ImageCell;
|
||||||
|
import ruscz.game.gameOfProd.Inventory.InventoryManager;
|
||||||
|
import ruscz.game.gameOfProd.Inventory.Item;
|
||||||
import ruscz.game.gameOfProd.Save.SaveManager;
|
import ruscz.game.gameOfProd.Save.SaveManager;
|
||||||
import ruscz.game.gameOfProd.Sounds.MusicManager;
|
import ruscz.game.gameOfProd.Sounds.MusicManager;
|
||||||
|
|
||||||
@ -21,7 +24,7 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
|
|
||||||
public class WindowOfBattle extends JPanel {
|
public class WindowOfBattle extends JPanel {
|
||||||
public static final int CELL_SIZE = 50;
|
public static final int CELL_SIZE = 60;
|
||||||
public static int CANVAS_WIDTH = 16;
|
public static int CANVAS_WIDTH = 16;
|
||||||
public static int CANVAS_HEIGHT = 13;
|
public static int CANVAS_HEIGHT = 13;
|
||||||
|
|
||||||
@ -52,15 +55,15 @@ public class WindowOfBattle extends JPanel {
|
|||||||
return itemsInventory;
|
return itemsInventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Canvas canvas;
|
private final Canvas canvas;
|
||||||
private SituationText situationText;
|
private final SituationText situationText;
|
||||||
private EnemyDescription enemyDescription;
|
private final EnemyDescription enemyDescription;
|
||||||
private MenuOfActions menuOfActions;
|
private final MenuOfActions menuOfActions;
|
||||||
private ConsoleInput consoleInput;
|
private final ConsoleInput consoleInput;
|
||||||
private CommandList commandList;
|
private final CommandList commandList;
|
||||||
private ItemsInventory itemsInventory;
|
private final ItemsInventory itemsInventory;
|
||||||
|
|
||||||
private Game game;
|
private final Game game;
|
||||||
private Battle battle;
|
private Battle battle;
|
||||||
|
|
||||||
private MusicManager musicManager;
|
private MusicManager musicManager;
|
||||||
@ -80,6 +83,7 @@ public class WindowOfBattle extends JPanel {
|
|||||||
lp.setSize(CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_HEIGHT);
|
lp.setSize(CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_HEIGHT);
|
||||||
|
|
||||||
setBackground(Color.BLACK);
|
setBackground(Color.BLACK);
|
||||||
|
//setLayout(new GridBagLayout());
|
||||||
|
|
||||||
canvas = new Canvas();
|
canvas = new Canvas();
|
||||||
situationText = new SituationText(this);
|
situationText = new SituationText(this);
|
||||||
@ -109,8 +113,10 @@ public class WindowOfBattle extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void startBattle(String name) {
|
public void startBattle(String name) {
|
||||||
SaveManager saveManager = game.getFreeMove().getMapManager().getSaveManager();
|
if (game.getFreeMove() != null) {
|
||||||
saveManager.saveGame();
|
SaveManager saveManager = game.getFreeMove().getMapManager().getSaveManager();
|
||||||
|
saveManager.saveGame();
|
||||||
|
}
|
||||||
|
|
||||||
LinkedList<Hero> heroes = new LinkedList<>();
|
LinkedList<Hero> heroes = new LinkedList<>();
|
||||||
LinkedList<Enemy> enemies = new LinkedList<>();
|
LinkedList<Enemy> enemies = new LinkedList<>();
|
||||||
@ -118,19 +124,17 @@ public class WindowOfBattle extends JPanel {
|
|||||||
try {
|
try {
|
||||||
File battleFile = new File("src/main/resources/battles/" + name + ".txt");
|
File battleFile = new File("src/main/resources/battles/" + name + ".txt");
|
||||||
Scanner scanner = new Scanner(battleFile);
|
Scanner scanner = new Scanner(battleFile);
|
||||||
while(scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
String[] data = scanner.nextLine().split(" ");
|
String[] data = scanner.nextLine().split(" ");
|
||||||
if (data[0].equals("<hero>")) {
|
if (data[0].equals("<hero>")) {
|
||||||
Hero hero = new Hero(Integer.parseInt(data[1]), Integer.parseInt(data[2]), data[3],
|
Hero hero = new Hero(Integer.parseInt(data[1]), Integer.parseInt(data[2]), data[3],
|
||||||
Integer.parseInt(data[4]), Integer.parseInt(data[5]), Integer.parseInt(data[6]));
|
Integer.parseInt(data[4]), Integer.parseInt(data[5]), Integer.parseInt(data[6]));
|
||||||
heroes.add(hero);
|
heroes.add(hero);
|
||||||
}
|
} else if (data[0].equals("<enemy>")) {
|
||||||
else if (data[0].equals("<enemy>")) {
|
|
||||||
Enemy enemy = new Enemy(Integer.parseInt(data[1]), Integer.parseInt(data[2]), data[3],
|
Enemy enemy = new Enemy(Integer.parseInt(data[1]), Integer.parseInt(data[2]), data[3],
|
||||||
Integer.parseInt(data[4]), Integer.parseInt(data[5]));
|
Integer.parseInt(data[4]), Integer.parseInt(data[5]));
|
||||||
enemies.add(enemy);
|
enemies.add(enemy);
|
||||||
}
|
} else if (data[0].equals("<music>")) {
|
||||||
else if (data[0].equals("<music>")) {
|
|
||||||
musicManager = new MusicManager(data[1], Float.parseFloat(data[2]));
|
musicManager = new MusicManager(data[1], Float.parseFloat(data[2]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,7 +142,6 @@ public class WindowOfBattle extends JPanel {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
MusicManager musicManager = new MusicManager("Fight_Music.wav", -15.0f);
|
|
||||||
battle = new Battle(heroes, enemies, this);
|
battle = new Battle(heroes, enemies, this);
|
||||||
|
|
||||||
isReadyToPaint = true;
|
isReadyToPaint = true;
|
||||||
@ -151,7 +154,7 @@ public class WindowOfBattle extends JPanel {
|
|||||||
|
|
||||||
battle.startBattle();
|
battle.startBattle();
|
||||||
|
|
||||||
if (musicManager != null){
|
if (musicManager != null) {
|
||||||
musicManager.playMusic();
|
musicManager.playMusic();
|
||||||
musicManager.setVolumeToMaxVolume();
|
musicManager.setVolumeToMaxVolume();
|
||||||
}
|
}
|
||||||
@ -178,8 +181,12 @@ public class WindowOfBattle extends JPanel {
|
|||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MusicManager getMusicManager() {
|
||||||
|
return musicManager;
|
||||||
|
}
|
||||||
|
|
||||||
class Canvas extends JPanel {
|
class Canvas extends JPanel {
|
||||||
Canvas(){
|
Canvas() {
|
||||||
setPreferredSize(new Dimension(
|
setPreferredSize(new Dimension(
|
||||||
CELL_SIZE * CANVAS_WIDTH,
|
CELL_SIZE * CANVAS_WIDTH,
|
||||||
CELL_SIZE * CANVAS_HEIGHT));
|
CELL_SIZE * CANVAS_HEIGHT));
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
<hero> 100 10 Mark 1 10 1
|
<hero> 100 10 Mark 1 10 1
|
||||||
<enemy> 100 10 Karen 10 1
|
<enemy> 100 10 Karen 10 1
|
||||||
<music> Fight_Music.wav -10.0f
|
<music> Fight_Music.wav -20.0f
|
||||||
@ -44,7 +44,7 @@
|
|||||||
<chest>
|
<chest>
|
||||||
<x>1</x>
|
<x>1</x>
|
||||||
<y>9</y>
|
<y>9</y>
|
||||||
<active>true</active>
|
<active>false</active>
|
||||||
</chest>
|
</chest>
|
||||||
</events>
|
</events>
|
||||||
</map>
|
</map>
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
<item>
|
||||||
|
<name>blue-key-card</name>
|
||||||
|
<multiplicity>1</multiplicity>
|
||||||
|
<image>39</image>
|
||||||
|
<action>key</action>
|
||||||
|
</item>
|
||||||
@ -1,6 +1,6 @@
|
|||||||
<location>
|
<location>
|
||||||
<map>storageroom</map>
|
<map>storageroom</map>
|
||||||
<x>6</x>
|
<x>2</x>
|
||||||
<y>2</y>
|
<y>7</y>
|
||||||
<direction>0</direction>
|
<direction>3</direction>
|
||||||
</location>
|
</location>
|
||||||
Loading…
x
Reference in New Issue
Block a user