Battle continues.....
This commit is contained in:
parent
28559cbb7e
commit
325a929c3f
@ -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);
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,9 @@ import ruscz.game.gameOfProd.Battle.Enemy;
|
||||
import ruscz.game.gameOfProd.Battle.Hero;
|
||||
import ruscz.game.gameOfProd.BattleUI.*;
|
||||
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.Sounds.MusicManager;
|
||||
|
||||
@ -21,7 +24,7 @@ import java.util.Scanner;
|
||||
|
||||
|
||||
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_HEIGHT = 13;
|
||||
|
||||
@ -52,15 +55,15 @@ public class WindowOfBattle extends JPanel {
|
||||
return itemsInventory;
|
||||
}
|
||||
|
||||
private Canvas canvas;
|
||||
private SituationText situationText;
|
||||
private EnemyDescription enemyDescription;
|
||||
private MenuOfActions menuOfActions;
|
||||
private ConsoleInput consoleInput;
|
||||
private CommandList commandList;
|
||||
private ItemsInventory itemsInventory;
|
||||
private final Canvas canvas;
|
||||
private final SituationText situationText;
|
||||
private final EnemyDescription enemyDescription;
|
||||
private final MenuOfActions menuOfActions;
|
||||
private final ConsoleInput consoleInput;
|
||||
private final CommandList commandList;
|
||||
private final ItemsInventory itemsInventory;
|
||||
|
||||
private Game game;
|
||||
private final Game game;
|
||||
private Battle battle;
|
||||
|
||||
private MusicManager musicManager;
|
||||
@ -80,6 +83,7 @@ public class WindowOfBattle extends JPanel {
|
||||
lp.setSize(CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_HEIGHT);
|
||||
|
||||
setBackground(Color.BLACK);
|
||||
//setLayout(new GridBagLayout());
|
||||
|
||||
canvas = new Canvas();
|
||||
situationText = new SituationText(this);
|
||||
@ -109,8 +113,10 @@ public class WindowOfBattle extends JPanel {
|
||||
}
|
||||
|
||||
public void startBattle(String name) {
|
||||
SaveManager saveManager = game.getFreeMove().getMapManager().getSaveManager();
|
||||
saveManager.saveGame();
|
||||
if (game.getFreeMove() != null) {
|
||||
SaveManager saveManager = game.getFreeMove().getMapManager().getSaveManager();
|
||||
saveManager.saveGame();
|
||||
}
|
||||
|
||||
LinkedList<Hero> heroes = new LinkedList<>();
|
||||
LinkedList<Enemy> enemies = new LinkedList<>();
|
||||
@ -118,19 +124,17 @@ public class WindowOfBattle extends JPanel {
|
||||
try {
|
||||
File battleFile = new File("src/main/resources/battles/" + name + ".txt");
|
||||
Scanner scanner = new Scanner(battleFile);
|
||||
while(scanner.hasNextLine()) {
|
||||
while (scanner.hasNextLine()) {
|
||||
String[] data = scanner.nextLine().split(" ");
|
||||
if (data[0].equals("<hero>")) {
|
||||
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]));
|
||||
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],
|
||||
Integer.parseInt(data[4]), Integer.parseInt(data[5]));
|
||||
enemies.add(enemy);
|
||||
}
|
||||
else if (data[0].equals("<music>")) {
|
||||
} else if (data[0].equals("<music>")) {
|
||||
musicManager = new MusicManager(data[1], Float.parseFloat(data[2]));
|
||||
}
|
||||
}
|
||||
@ -138,7 +142,6 @@ public class WindowOfBattle extends JPanel {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
MusicManager musicManager = new MusicManager("Fight_Music.wav", -15.0f);
|
||||
battle = new Battle(heroes, enemies, this);
|
||||
|
||||
isReadyToPaint = true;
|
||||
@ -151,7 +154,7 @@ public class WindowOfBattle extends JPanel {
|
||||
|
||||
battle.startBattle();
|
||||
|
||||
if (musicManager != null){
|
||||
if (musicManager != null) {
|
||||
musicManager.playMusic();
|
||||
musicManager.setVolumeToMaxVolume();
|
||||
}
|
||||
@ -178,8 +181,12 @@ public class WindowOfBattle extends JPanel {
|
||||
return game;
|
||||
}
|
||||
|
||||
public MusicManager getMusicManager() {
|
||||
return musicManager;
|
||||
}
|
||||
|
||||
class Canvas extends JPanel {
|
||||
Canvas(){
|
||||
Canvas() {
|
||||
setPreferredSize(new Dimension(
|
||||
CELL_SIZE * CANVAS_WIDTH,
|
||||
CELL_SIZE * CANVAS_HEIGHT));
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
<hero> 100 10 Mark 1 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>
|
||||
<x>1</x>
|
||||
<y>9</y>
|
||||
<active>true</active>
|
||||
<active>false</active>
|
||||
</chest>
|
||||
</events>
|
||||
</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>
|
||||
<map>storageroom</map>
|
||||
<x>6</x>
|
||||
<y>2</y>
|
||||
<direction>0</direction>
|
||||
<x>2</x>
|
||||
<y>7</y>
|
||||
<direction>3</direction>
|
||||
</location>
|
||||
Loading…
x
Reference in New Issue
Block a user