fixed some battle stuff
This commit is contained in:
parent
58c1ed49f0
commit
0ff0e6126e
@ -140,7 +140,10 @@ public class Battle {
|
||||
turnBelongTo.setImageEffect("attack");
|
||||
if (windowOfBattle.getHitSound() != null) soundManager.playSound(windowOfBattle.getHitSound(), -10.0f);
|
||||
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);
|
||||
playerAttack = false;
|
||||
@ -178,7 +181,10 @@ public class Battle {
|
||||
if (windowOfBattle.getHitSound() != null) soundManager.playSound(windowOfBattle.getHitSound(), -10.0f);
|
||||
|
||||
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);
|
||||
delay = 2;
|
||||
|
||||
@ -48,7 +48,6 @@ public abstract class BattlePerson {
|
||||
}
|
||||
|
||||
private void effectCoords(String effect) {
|
||||
System.out.println(effect);
|
||||
if (effect.equals("hover")) {
|
||||
final boolean[] isGoingUp = {true};
|
||||
effectTimer = new Timer(100, actionEvent -> {
|
||||
@ -206,7 +205,7 @@ public abstract class BattlePerson {
|
||||
return image;
|
||||
}
|
||||
|
||||
public abstract void heal(int heal);
|
||||
public abstract int heal(int heal);
|
||||
|
||||
public abstract void attack(BattlePerson enemy);
|
||||
|
||||
|
||||
@ -18,8 +18,9 @@ public class Enemy extends BattlePerson {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int heal) {
|
||||
public int heal(int heal) {
|
||||
health += heal;
|
||||
return heal;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -20,11 +20,13 @@ public class Hero extends BattlePerson {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int heal) {
|
||||
public int heal(int heal) {
|
||||
int h = health;
|
||||
if (health + heal < maxHealth) health += heal;
|
||||
else health = maxHealth;
|
||||
stopEffectTimer();
|
||||
getHealed();
|
||||
return health - h;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -47,7 +47,7 @@ public class ItemsInventory extends JPanel {
|
||||
for (Component c: items.getComponents())
|
||||
items.remove(c);
|
||||
|
||||
System.out.println(InventoryManager.getInventory());
|
||||
items.setLayout(new GridLayout(InventoryManager.getInventory().size(), 1));
|
||||
|
||||
for (Item item: InventoryManager.getInventory()){
|
||||
JPanel jPanel = new JPanel();
|
||||
@ -58,27 +58,29 @@ public class ItemsInventory extends JPanel {
|
||||
|
||||
jPanel.add(itemPanel);
|
||||
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())));
|
||||
|
||||
if (item.getItemAction().equals(ItemAction.HEAL)){
|
||||
JButton use = windowOfBattle.style(new JButton("Use"));
|
||||
if (item.getItemAction().equals(ItemAction.HEAL)){
|
||||
use.addActionListener(e -> {
|
||||
setVisible(false);
|
||||
windowOfBattle.getBattle().getHeroes().getFirst().heal(100);
|
||||
windowOfBattle.getMenuOfActions().setVisible(false);
|
||||
windowOfBattle.getEnemyDescription().setVisible(false);
|
||||
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);
|
||||
windowOfBattle.getBattle().addToTurnOrder(windowOfBattle.getBattle().getHeroes().getFirst());
|
||||
windowOfBattle.getBattle().setTurnBelongTo(null);
|
||||
windowOfBattle.getBattle().setDelay(2);
|
||||
windowOfBattle.getBattle().getTimer().start();
|
||||
});
|
||||
jPanel.add(use);
|
||||
}
|
||||
|
||||
else {
|
||||
use.setEnabled(false);
|
||||
}
|
||||
jPanel.add(use);
|
||||
items.add(jPanel);
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.*;
|
||||
|
||||
@ -61,7 +62,30 @@ public class MenuOfActions extends JPanel {
|
||||
inventory.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);
|
||||
|
||||
@ -70,8 +70,8 @@ public class WindowOfBattle extends JPanel {
|
||||
private String winCutscene;
|
||||
private String loseCutscene;
|
||||
private String name;
|
||||
|
||||
private String hitSound;
|
||||
private boolean isRunAwayPossible;
|
||||
|
||||
public Battle getBattle() {
|
||||
return battle;
|
||||
@ -142,7 +142,7 @@ public class WindowOfBattle extends JPanel {
|
||||
enemies.add(enemy);
|
||||
}
|
||||
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>")) {
|
||||
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>")){
|
||||
hitSound = data[1];
|
||||
}
|
||||
else if (data[0].equals("<runawaypossible>")) {
|
||||
isRunAwayPossible = Boolean.parseBoolean(data[1]);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
@ -185,7 +188,6 @@ public class WindowOfBattle extends JPanel {
|
||||
}
|
||||
|
||||
public void writeToOutput(String s) {
|
||||
System.out.println(s);
|
||||
Font f = new Font(Font.SERIF, Font.BOLD, 20);
|
||||
if (situationText.getComponents().length == 0) {
|
||||
JLabel text = new JLabel();
|
||||
@ -235,6 +237,10 @@ public class WindowOfBattle extends JPanel {
|
||||
return hitSound;
|
||||
}
|
||||
|
||||
public boolean isRunAwayPossible() {
|
||||
return isRunAwayPossible;
|
||||
}
|
||||
|
||||
class Canvas extends JPanel {
|
||||
private LinkedList<BufferedImage> images;
|
||||
private BufferedImage image;
|
||||
|
||||
@ -7,3 +7,4 @@
|
||||
<image> flicker 500
|
||||
<wincutscene> cutscene-storageroombattle-win
|
||||
<losecutscene> cutscene-storageroombattle-lose
|
||||
<runawaypossible> true
|
||||
Loading…
x
Reference in New Issue
Block a user