fixed some battle stuff

This commit is contained in:
musilto9 2020-06-08 13:05:31 +02:00
parent 58c1ed49f0
commit 0ff0e6126e
8 changed files with 59 additions and 18 deletions

View File

@ -140,7 +140,10 @@ public class Battle {
turnBelongTo.setImageEffect("attack"); turnBelongTo.setImageEffect("attack");
if (windowOfBattle.getHitSound() != null) soundManager.playSound(windowOfBattle.getHitSound(), -10.0f); if (windowOfBattle.getHitSound() != null) soundManager.playSound(windowOfBattle.getHitSound(), -10.0f);
windowOfBattle.writeToOutput(turnBelongTo.getName() + " deals " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " damage to " + e.getName()+"!"); windowOfBattle.writeToOutput(turnBelongTo.getName() + " deals " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " damage to " + e.getName()+"!");
if (e.health <= 0) e.getKilled(this); if (e.health <= 0) {
if (e.getImage()!= null) e.getKilled(this);
else enemies.remove(e);
}
turnOrder.add(turnBelongTo); turnOrder.add(turnBelongTo);
playerAttack = false; playerAttack = false;
@ -178,7 +181,10 @@ public class Battle {
if (windowOfBattle.getHitSound() != null) soundManager.playSound(windowOfBattle.getHitSound(), -10.0f); if (windowOfBattle.getHitSound() != null) soundManager.playSound(windowOfBattle.getHitSound(), -10.0f);
windowOfBattle.writeToOutput(turnBelongTo.getName() + " deals " + turnBelongTo.getLevel() + " damage to " + e.getName()+"!"); windowOfBattle.writeToOutput(turnBelongTo.getName() + " deals " + turnBelongTo.getLevel() + " damage to " + e.getName()+"!");
if (e.health <= 0) e.getKilled(this); if (e.health <= 0) {
if (e.getImage()!= null) e.getKilled(this);
else heroes.remove(e);
}
turnOrder.add(turnBelongTo); turnOrder.add(turnBelongTo);
delay = 2; delay = 2;

View File

@ -48,7 +48,6 @@ public abstract class BattlePerson {
} }
private void effectCoords(String effect) { private void effectCoords(String effect) {
System.out.println(effect);
if (effect.equals("hover")) { if (effect.equals("hover")) {
final boolean[] isGoingUp = {true}; final boolean[] isGoingUp = {true};
effectTimer = new Timer(100, actionEvent -> { effectTimer = new Timer(100, actionEvent -> {
@ -206,7 +205,7 @@ public abstract class BattlePerson {
return image; return image;
} }
public abstract void heal(int heal); public abstract int heal(int heal);
public abstract void attack(BattlePerson enemy); public abstract void attack(BattlePerson enemy);

View File

@ -18,8 +18,9 @@ public class Enemy extends BattlePerson {
} }
@Override @Override
public void heal(int heal) { public int heal(int heal) {
health += heal; health += heal;
return heal;
} }
@Override @Override

View File

@ -20,11 +20,13 @@ public class Hero extends BattlePerson {
} }
@Override @Override
public void heal(int heal) { public int heal(int heal) {
int h = health;
if (health + heal < maxHealth) health += heal; if (health + heal < maxHealth) health += heal;
else health = maxHealth; else health = maxHealth;
stopEffectTimer(); stopEffectTimer();
getHealed(); getHealed();
return health - h;
} }
@Override @Override

View File

@ -47,7 +47,7 @@ public class ItemsInventory extends JPanel {
for (Component c: items.getComponents()) for (Component c: items.getComponents())
items.remove(c); items.remove(c);
System.out.println(InventoryManager.getInventory()); items.setLayout(new GridLayout(InventoryManager.getInventory().size(), 1));
for (Item item: InventoryManager.getInventory()){ for (Item item: InventoryManager.getInventory()){
JPanel jPanel = new JPanel(); JPanel jPanel = new JPanel();
@ -58,27 +58,29 @@ public class ItemsInventory extends JPanel {
jPanel.add(itemPanel); jPanel.add(itemPanel);
jPanel.add(new JLabel(item.getName())); jPanel.add(new JLabel(item.getName()));
jPanel.add(new JLabel(String.valueOf(item.getMultiplicity()))); jPanel.add(new JLabel(" " + item.getMultiplicity() + "x"));
jPanel.add(new JLabel(String.valueOf(item.getItemAction()))); jPanel.add(new JLabel(String.valueOf(item.getItemAction())));
JButton use = windowOfBattle.style(new JButton("Use"));
if (item.getItemAction().equals(ItemAction.HEAL)){ if (item.getItemAction().equals(ItemAction.HEAL)){
JButton use = windowOfBattle.style(new JButton("Use"));
use.addActionListener(e -> { use.addActionListener(e -> {
setVisible(false); setVisible(false);
windowOfBattle.getBattle().getHeroes().getFirst().heal(100);
windowOfBattle.getMenuOfActions().setVisible(false); windowOfBattle.getMenuOfActions().setVisible(false);
windowOfBattle.getEnemyDescription().setVisible(false); windowOfBattle.getEnemyDescription().setVisible(false);
windowOfBattle.getSituationText().setVisible(true); windowOfBattle.getSituationText().setVisible(true);
windowOfBattle.writeToOutput(windowOfBattle.getBattle().getHeroes().getFirst().getName() + " heals 100 HP"); windowOfBattle.writeToOutput(windowOfBattle.getBattle().getHeroes().getFirst().getName() + " heals "
+ windowOfBattle.getBattle().getHeroes().getFirst().heal(100) + " HP");
InventoryManager.removeItem(item, 1); InventoryManager.removeItem(item, 1);
windowOfBattle.getBattle().addToTurnOrder(windowOfBattle.getBattle().getHeroes().getFirst()); windowOfBattle.getBattle().addToTurnOrder(windowOfBattle.getBattle().getHeroes().getFirst());
windowOfBattle.getBattle().setTurnBelongTo(null); windowOfBattle.getBattle().setTurnBelongTo(null);
windowOfBattle.getBattle().setDelay(2); windowOfBattle.getBattle().setDelay(2);
windowOfBattle.getBattle().getTimer().start(); windowOfBattle.getBattle().getTimer().start();
}); });
jPanel.add(use);
} }
else {
use.setEnabled(false);
}
jPanel.add(use);
items.add(jPanel); items.add(jPanel);
} }

View File

@ -4,6 +4,7 @@ import ruscz.game.gameOfProd.Windows.WindowOfBattle;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.util.Random;
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.*; import static ruscz.game.gameOfProd.Windows.WindowOfBattle.*;
@ -61,7 +62,30 @@ public class MenuOfActions extends JPanel {
inventory.setEnabled(false); inventory.setEnabled(false);
escape.setEnabled(false); escape.setEnabled(false);
window.getBattle().endBattle(true); if (window.isRunAwayPossible()) {
Random r = new Random();
if (r.nextBoolean()) window.getBattle().endBattle(true);
else {
window.getMenuOfActions().setVisible(false);
window.getEnemyDescription().setVisible(false);
window.getSituationText().setVisible(true);
window.writeToOutput("Runaway was not successful.");
window.getBattle().addToTurnOrder(window.getBattle().getHeroes().getFirst());
window.getBattle().setTurnBelongTo(null);
window.getBattle().setDelay(2);
window.getBattle().getTimer().start();
}
}
else {
window.getMenuOfActions().setVisible(false);
window.getEnemyDescription().setVisible(false);
window.getSituationText().setVisible(true);
window.writeToOutput("Runaway is not possible.");
window.getBattle().addToTurnOrder(window.getBattle().getHeroes().getFirst());
window.getBattle().setTurnBelongTo(null);
window.getBattle().setDelay(2);
window.getBattle().getTimer().start();
}
}); });
add(attack); add(attack);

View File

@ -70,8 +70,8 @@ public class WindowOfBattle extends JPanel {
private String winCutscene; private String winCutscene;
private String loseCutscene; private String loseCutscene;
private String name; private String name;
private String hitSound; private String hitSound;
private boolean isRunAwayPossible;
public Battle getBattle() { public Battle getBattle() {
return battle; return battle;
@ -142,7 +142,7 @@ public class WindowOfBattle extends JPanel {
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]));
} }
else if (data[0].equals("<image>")) { else if (data[0].equals("<image>")) {
if (data[1].equals("flicker")) canvas.flicker(Integer.parseInt(data[2])); if (data[1].equals("flicker")) canvas.flicker(Integer.parseInt(data[2]));
@ -157,6 +157,9 @@ public class WindowOfBattle extends JPanel {
else if (data[0].equals("<attacksound>")){ else if (data[0].equals("<attacksound>")){
hitSound = data[1]; hitSound = data[1];
} }
else if (data[0].equals("<runawaypossible>")) {
isRunAwayPossible = Boolean.parseBoolean(data[1]);
}
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
@ -185,7 +188,6 @@ public class WindowOfBattle extends JPanel {
} }
public void writeToOutput(String s) { public void writeToOutput(String s) {
System.out.println(s);
Font f = new Font(Font.SERIF, Font.BOLD, 20); Font f = new Font(Font.SERIF, Font.BOLD, 20);
if (situationText.getComponents().length == 0) { if (situationText.getComponents().length == 0) {
JLabel text = new JLabel(); JLabel text = new JLabel();
@ -235,6 +237,10 @@ public class WindowOfBattle extends JPanel {
return hitSound; return hitSound;
} }
public boolean isRunAwayPossible() {
return isRunAwayPossible;
}
class Canvas extends JPanel { class Canvas extends JPanel {
private LinkedList<BufferedImage> images; private LinkedList<BufferedImage> images;
private BufferedImage image; private BufferedImage image;

View File

@ -6,4 +6,5 @@
<image> battle2 <image> battle2
<image> flicker 500 <image> flicker 500
<wincutscene> cutscene-storageroombattle-win <wincutscene> cutscene-storageroombattle-win
<losecutscene> cutscene-storageroombattle-lose <losecutscene> cutscene-storageroombattle-lose
<runawaypossible> true