Merge branch 'master' of gitlab.fel.cvut.cz:B192_B0B36PJV/iryupnik
This commit is contained in:
commit
3c91433a23
@ -2,6 +2,7 @@ package ruscz.game.gameOfProd.Battle;
|
|||||||
|
|
||||||
import ruscz.game.gameOfProd.Cells.InteractionCell;
|
import ruscz.game.gameOfProd.Cells.InteractionCell;
|
||||||
import ruscz.game.gameOfProd.Dialog.Dialog;
|
import ruscz.game.gameOfProd.Dialog.Dialog;
|
||||||
|
import ruscz.game.gameOfProd.Sounds.SoundManager;
|
||||||
import ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
import ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
||||||
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
|
||||||
@ -17,9 +18,7 @@ public class Battle {
|
|||||||
private final WindowOfBattle windowOfBattle;
|
private final WindowOfBattle windowOfBattle;
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
|
|
||||||
public void setTurnBelongTo(BattlePerson turnBelongTo) {
|
private final SoundManager soundManager;
|
||||||
this.turnBelongTo = turnBelongTo;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BattlePerson turnBelongTo;
|
private BattlePerson turnBelongTo;
|
||||||
|
|
||||||
@ -42,10 +41,6 @@ public class Battle {
|
|||||||
|
|
||||||
private boolean timerStopped;
|
private boolean timerStopped;
|
||||||
|
|
||||||
public BattlePerson getTurnBelongTo() {
|
|
||||||
return turnBelongTo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlayerAttack(boolean playerAttack) {
|
public void setPlayerAttack(boolean playerAttack) {
|
||||||
windowOfBattle.getMenuOfActions().setVisible(false);
|
windowOfBattle.getMenuOfActions().setVisible(false);
|
||||||
windowOfBattle.getEnemyDescription().setVisible(false);
|
windowOfBattle.getEnemyDescription().setVisible(false);
|
||||||
@ -56,6 +51,7 @@ public class Battle {
|
|||||||
this.heroes = heroes;
|
this.heroes = heroes;
|
||||||
this.enemies = enemies;
|
this.enemies = enemies;
|
||||||
this.windowOfBattle = window;
|
this.windowOfBattle = window;
|
||||||
|
soundManager = new SoundManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinkedList<Enemy> getEnemies() {
|
public LinkedList<Enemy> getEnemies() {
|
||||||
@ -81,7 +77,6 @@ public class Battle {
|
|||||||
windowOfBattle.repaint();
|
windowOfBattle.repaint();
|
||||||
turnOrder = new LinkedList<>();
|
turnOrder = new LinkedList<>();
|
||||||
timer = new Timer(1000, actionEvent -> {
|
timer = new Timer(1000, actionEvent -> {
|
||||||
for (Enemy e: enemies) System.out.println(e.health);
|
|
||||||
if (checkHealthOfEnemies()) endBattle(true);
|
if (checkHealthOfEnemies()) endBattle(true);
|
||||||
if (checkHealthOfHeroes()) endBattle(false);
|
if (checkHealthOfHeroes()) endBattle(false);
|
||||||
if(playerAttack)
|
if(playerAttack)
|
||||||
@ -136,9 +131,9 @@ public class Battle {
|
|||||||
turnCount++;
|
turnCount++;
|
||||||
windowOfBattle.repaint();
|
windowOfBattle.repaint();
|
||||||
turnBelongTo.attack(e);
|
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());
|
windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " damage to " + e.getName()+"!");
|
||||||
//TODO Animation of Attack
|
|
||||||
//TODO Animation of Death
|
//TODO Animation of Death
|
||||||
if (e.health <= 0) enemies.remove(e);
|
if (e.health <= 0) enemies.remove(e);
|
||||||
|
|
||||||
@ -156,26 +151,27 @@ public class Battle {
|
|||||||
LinkedList<BattlePerson> turns = new LinkedList<>(enemies);
|
LinkedList<BattlePerson> turns = new LinkedList<>(enemies);
|
||||||
turns.addAll(heroes);
|
turns.addAll(heroes);
|
||||||
|
|
||||||
if (checkIfTurnOrderIsFull(turns))
|
BattlePerson last = turnOrder.getLast();
|
||||||
|
if (checkIfTurnOrderIsFull(turns)) {
|
||||||
turnOrder = new LinkedList<>();
|
turnOrder = new LinkedList<>();
|
||||||
|
}
|
||||||
|
|
||||||
Collections.shuffle(turns);
|
Collections.shuffle(turns);
|
||||||
turnBelongTo = turns.getFirst();
|
turnBelongTo = turns.getFirst();
|
||||||
|
|
||||||
while (turnOrder.contains(turnBelongTo)){
|
while (turnOrder.contains(turnBelongTo) || turnBelongTo.equals(last)){
|
||||||
|
turns.remove(turnBelongTo);
|
||||||
Collections.shuffle(turns);
|
Collections.shuffle(turns);
|
||||||
turnBelongTo = turns.getFirst();
|
turnBelongTo = turns.getFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(turnBelongTo.getClass().getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attackByMonster(Hero e) {
|
private void attackByMonster(Hero e) {
|
||||||
turnCount++;
|
turnCount++;
|
||||||
turnBelongTo.attack(e);
|
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());
|
windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() + " damage to " + e.getName()+"!");
|
||||||
//TODO Animation of Attack
|
|
||||||
//TODO Animation of Death
|
//TODO Animation of Death
|
||||||
if (e.health <= 0) heroes.remove(e);
|
if (e.health <= 0) heroes.remove(e);
|
||||||
|
|
||||||
@ -200,8 +196,8 @@ public class Battle {
|
|||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlayerAttack() {
|
public void setTurnBelongTo(BattlePerson turnBelongTo) {
|
||||||
return playerAttack;
|
this.turnBelongTo = turnBelongTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkIfTurnOrderIsFull(LinkedList<BattlePerson> allBattlePerson){
|
private boolean checkIfTurnOrderIsFull(LinkedList<BattlePerson> allBattlePerson){
|
||||||
|
|||||||
@ -48,18 +48,21 @@ public class EnemyDescription extends JPanel {
|
|||||||
setLayout(new GridLayout (he.size() + 1, 3));
|
setLayout(new GridLayout (he.size() + 1, 3));
|
||||||
|
|
||||||
for (BattlePerson person: he){
|
for (BattlePerson person: he){
|
||||||
|
Font f = new Font(Font.DIALOG, Font.BOLD, 20);
|
||||||
|
|
||||||
JPanel jPanel = new JPanel();
|
JPanel jPanel = new JPanel();
|
||||||
JLabel name = new JLabel(person.getName());
|
JLabel name = new JLabel(person.getName());
|
||||||
|
name.setFont(f);
|
||||||
JLabel level = new JLabel("Level: " + person.getLevel());
|
JLabel level = new JLabel("Level: " + person.getLevel());
|
||||||
|
level.setFont(f);
|
||||||
JLabel health = new JLabel("Health: " + person.getHealth() + "/" + person.getMaxHealth());
|
JLabel health = new JLabel("Health: " + person.getHealth() + "/" + person.getMaxHealth());
|
||||||
|
health.setFont(f);
|
||||||
jPanel.add(name);
|
jPanel.add(name);
|
||||||
jPanel.add(level);
|
jPanel.add(level);
|
||||||
jPanel.add(health);
|
jPanel.add(health);
|
||||||
|
|
||||||
add(jPanel);
|
add(jPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(Arrays.toString(getComponents()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deletePreviousDescription() {
|
private void deletePreviousDescription() {
|
||||||
|
|||||||
@ -54,15 +54,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;
|
||||||
@ -71,6 +71,8 @@ public class WindowOfBattle extends JPanel {
|
|||||||
private String loseCutscene;
|
private String loseCutscene;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
private String hitSound;
|
||||||
|
|
||||||
public Battle getBattle() {
|
public Battle getBattle() {
|
||||||
return battle;
|
return battle;
|
||||||
}
|
}
|
||||||
@ -152,6 +154,9 @@ public class WindowOfBattle extends JPanel {
|
|||||||
else if (data[0].equals("<losecutscene>")) {
|
else if (data[0].equals("<losecutscene>")) {
|
||||||
loseCutscene = data[1];
|
loseCutscene = data[1];
|
||||||
}
|
}
|
||||||
|
else if (data[0].equals("<attacksound>")){
|
||||||
|
hitSound = data[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -213,6 +218,10 @@ public class WindowOfBattle extends JPanel {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getHitSound() {
|
||||||
|
return hitSound;
|
||||||
|
}
|
||||||
|
|
||||||
class Canvas extends JPanel {
|
class Canvas extends JPanel {
|
||||||
private LinkedList<BufferedImage> images;
|
private LinkedList<BufferedImage> images;
|
||||||
private BufferedImage image;
|
private BufferedImage image;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
<hero> 100 10 Mark 1 10 1 main-battle
|
<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
|
<music> Fight_Music.wav -10.0f
|
||||||
|
<attacksound> hit.wav
|
||||||
<image> battle1
|
<image> battle1
|
||||||
<image> battle2
|
<image> battle2
|
||||||
<image> flicker 500
|
<image> flicker 500
|
||||||
|
|||||||
BIN
src/main/resources/sounds/hit.wav
Normal file
BIN
src/main/resources/sounds/hit.wav
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user