Battle fixed 50 times in a row

This commit is contained in:
iryupnik 2020-06-07 16:43:05 +02:00
parent 33c5abe4dd
commit e6dd427805
7 changed files with 124 additions and 29 deletions

View File

@ -2,6 +2,7 @@ package ruscz.game.gameOfProd.Battle;
import ruscz.game.gameOfProd.Cells.InteractionCell;
import ruscz.game.gameOfProd.Dialog.Dialog;
import ruscz.game.gameOfProd.Sounds.SoundManager;
import ruscz.game.gameOfProd.Windows.WindowOfBattle;
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
@ -17,9 +18,7 @@ public class Battle {
private final WindowOfBattle windowOfBattle;
private Timer timer;
public void setTurnBelongTo(BattlePerson turnBelongTo) {
this.turnBelongTo = turnBelongTo;
}
private final SoundManager soundManager;
private BattlePerson turnBelongTo;
@ -42,10 +41,6 @@ public class Battle {
private boolean timerStopped;
public BattlePerson getTurnBelongTo() {
return turnBelongTo;
}
public void setPlayerAttack(boolean playerAttack) {
windowOfBattle.getMenuOfActions().setVisible(false);
windowOfBattle.getEnemyDescription().setVisible(false);
@ -56,6 +51,7 @@ public class Battle {
this.heroes = heroes;
this.enemies = enemies;
this.windowOfBattle = window;
soundManager = new SoundManager();
}
public LinkedList<Enemy> getEnemies() {
@ -81,7 +77,6 @@ public class Battle {
windowOfBattle.repaint();
turnOrder = new LinkedList<>();
timer = new Timer(1000, actionEvent -> {
for (Enemy e: enemies) System.out.println(e.health);
if (checkHealthOfEnemies()) endBattle(true);
if (checkHealthOfHeroes()) endBattle(false);
if(playerAttack)
@ -134,9 +129,9 @@ public class Battle {
turnCount++;
windowOfBattle.repaint();
turnBelongTo.attack(e);
if (windowOfBattle.getHitSound() != null) soundManager.playSound(windowOfBattle.getHitSound(), 6.0f);
windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " to " + e.getName());
//TODO Animation of Attack
windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " damage to " + e.getName()+"!");
//TODO Animation of Death
if (e.health <= 0) enemies.remove(e);
@ -154,26 +149,27 @@ public class Battle {
LinkedList<BattlePerson> turns = new LinkedList<>(enemies);
turns.addAll(heroes);
if (checkIfTurnOrderIsFull(turns))
BattlePerson last = turnOrder.getLast();
if (checkIfTurnOrderIsFull(turns)) {
turnOrder = new LinkedList<>();
}
Collections.shuffle(turns);
turnBelongTo = turns.getFirst();
while (turnOrder.contains(turnBelongTo)){
while (turnOrder.contains(turnBelongTo) || turnBelongTo.equals(last)){
turns.remove(turnBelongTo);
Collections.shuffle(turns);
turnBelongTo = turns.getFirst();
}
System.out.println(turnBelongTo.getClass().getName());
}
private void attackByMonster(Hero e) {
turnCount++;
turnBelongTo.attack(e);
if (windowOfBattle.getHitSound() != null) soundManager.playSound(windowOfBattle.getHitSound(), 6.0f);
windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " to " + e.getName());
//TODO Animation of Attack
windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() + " damage to " + e.getName()+"!");
//TODO Animation of Death
if (e.health <= 0) heroes.remove(e);
@ -198,8 +194,8 @@ public class Battle {
return timer;
}
public boolean isPlayerAttack() {
return playerAttack;
public void setTurnBelongTo(BattlePerson turnBelongTo) {
this.turnBelongTo = turnBelongTo;
}
private boolean checkIfTurnOrderIsFull(LinkedList<BattlePerson> allBattlePerson){

View File

@ -48,18 +48,21 @@ public class EnemyDescription extends JPanel {
setLayout(new GridLayout (he.size() + 1, 3));
for (BattlePerson person: he){
Font f = new Font(Font.DIALOG, Font.BOLD, 20);
JPanel jPanel = new JPanel();
JLabel name = new JLabel(person.getName());
name.setFont(f);
JLabel level = new JLabel("Level: " + person.getLevel());
level.setFont(f);
JLabel health = new JLabel("Health: " + person.getHealth() + "/" + person.getMaxHealth());
health.setFont(f);
jPanel.add(name);
jPanel.add(level);
jPanel.add(health);
add(jPanel);
}
System.out.println(Arrays.toString(getComponents()));
}
private void deletePreviousDescription() {

View File

@ -54,15 +54,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;
@ -71,6 +71,8 @@ public class WindowOfBattle extends JPanel {
private String loseCutscene;
private String name;
private String hitSound;
public Battle getBattle() {
return battle;
}
@ -152,6 +154,9 @@ public class WindowOfBattle extends JPanel {
else if (data[0].equals("<losecutscene>")) {
loseCutscene = data[1];
}
else if (data[0].equals("<attacksound>")){
hitSound = data[1];
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
@ -213,6 +218,10 @@ public class WindowOfBattle extends JPanel {
return name;
}
public String getHitSound() {
return hitSound;
}
class Canvas extends JPanel {
private LinkedList<BufferedImage> images;
private BufferedImage image;

View File

@ -1,6 +1,7 @@
<hero> 100 10 Mark 1 10 1 main-battle
<enemy> 1 1 Karen 1 1 monster-battle hover
<enemy> 120 10 Karen 10 1 monster-battle hover
<music> Fight_Music.wav -10.0f
<attacksound> hit.wav
<image> battle1
<image> battle2
<image> flicker 500

View File

@ -0,0 +1,80 @@
<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>

View File

@ -0,0 +1,6 @@
<location>
<map>storageroom</map>
<x>6</x>
<y>2</y>
<direction>0</direction>
</location>

Binary file not shown.