End of Battle (works!)
This commit is contained in:
parent
5167562025
commit
a8d51bfb88
@ -13,7 +13,6 @@ public class Battle {
|
||||
private WindowOfBattle windowOfBattle;
|
||||
private Timer timer;
|
||||
private BattlePerson turnBelongTo;
|
||||
private BattlePerson turnWas;
|
||||
|
||||
private int turnCount;
|
||||
private int delay;
|
||||
@ -42,12 +41,23 @@ public class Battle {
|
||||
return heroes;
|
||||
}
|
||||
|
||||
private boolean checkHealthOfEnemies(){
|
||||
return enemies.isEmpty();
|
||||
}
|
||||
|
||||
private boolean checkHealthOfHeroes(){
|
||||
return heroes.isEmpty();
|
||||
}
|
||||
|
||||
public void startBattle() {
|
||||
turnBelongTo = heroes.getFirst();
|
||||
windowOfBattle.getMenuOfActions().setVisible(true);
|
||||
windowOfBattle.getEnemyDescription().setVisible(true);
|
||||
windowOfBattle.repaint();
|
||||
timer = new Timer(1000, actionEvent -> {
|
||||
for (Enemy e: enemies) System.out.println(e.health);
|
||||
if (checkHealthOfEnemies()) endBattle(true);
|
||||
if (checkHealthOfHeroes()) endBattle(false);
|
||||
if(playerAttack)
|
||||
attackByHero(randomEnemy());
|
||||
else if (delay != 0)
|
||||
@ -55,16 +65,24 @@ public class Battle {
|
||||
else if (turnBelongTo == null)
|
||||
nextTurn();
|
||||
else if (turnBelongTo.getClass().getName().equals(Enemy.class.getName()))
|
||||
attackByMonster();
|
||||
attackByMonster(randomHero());
|
||||
else {
|
||||
returnControlToPlayer();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void endBattle(boolean b) {
|
||||
//TODO Return to Map
|
||||
timer.stop();
|
||||
if (b) windowOfBattle.writeToOutput("Win!");
|
||||
else windowOfBattle.writeToOutput("Lose!");
|
||||
}
|
||||
|
||||
private void returnControlToPlayer(){
|
||||
timer.stop();
|
||||
windowOfBattle.getMenuOfActions().setVisible(true);
|
||||
windowOfBattle.getMenuOfActions().getComponents()[0].setEnabled(true);
|
||||
windowOfBattle.getEnemyDescription().setVisible(true);
|
||||
}
|
||||
|
||||
@ -73,11 +91,12 @@ public class Battle {
|
||||
windowOfBattle.getMenuOfActions().setVisible(false);
|
||||
windowOfBattle.getEnemyDescription().setVisible(false);
|
||||
windowOfBattle.repaint();
|
||||
e.setHealth(e.getHealth() - turnBelongTo.getLevel() * turnBelongTo.getStrength());
|
||||
turnBelongTo.attack(e);
|
||||
//TODO Animation of Death
|
||||
if (e.health <= 0) enemies.remove(e);
|
||||
windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " to " + e.getName());
|
||||
playerAttack = false;
|
||||
|
||||
|
||||
turnBelongTo = null;
|
||||
delay = 2;
|
||||
}
|
||||
@ -89,19 +108,19 @@ public class Battle {
|
||||
|
||||
LinkedList<BattlePerson> turns = new LinkedList<>(enemies);
|
||||
turns.addAll(heroes);
|
||||
|
||||
//TODO Check turns (maybe List)
|
||||
Collections.shuffle(turns);
|
||||
turnBelongTo = turns.getFirst();
|
||||
|
||||
System.out.println(turnBelongTo.getClass().getName());
|
||||
}
|
||||
|
||||
private void attackByMonster() {
|
||||
private void attackByMonster(Hero e) {
|
||||
turnCount++;
|
||||
LinkedList list = getHeroes();
|
||||
Random rand = new Random();
|
||||
Hero e = (Hero) list.get(rand.nextInt(list.size()));
|
||||
e.setHealth(e.getHealth() - turnBelongTo.getLevel() * turnBelongTo.getStrength());
|
||||
turnBelongTo.attack(e);
|
||||
//TODO Animation of Death
|
||||
if (e.health <= 0) heroes.remove(e);
|
||||
|
||||
windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " to " + e.getName());
|
||||
delay = 2;
|
||||
turnBelongTo = null;
|
||||
@ -113,6 +132,12 @@ public class Battle {
|
||||
return (Enemy) list.get(rand.nextInt(list.size()));
|
||||
}
|
||||
|
||||
private Hero randomHero(){
|
||||
LinkedList list = getHeroes();
|
||||
Random rand = new Random();
|
||||
return (Hero) list.get(rand.nextInt(list.size()));
|
||||
}
|
||||
|
||||
public Timer getTimer() {
|
||||
return timer;
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ public class Hero extends BattlePerson {
|
||||
|
||||
@Override
|
||||
public void attack(BattlePerson enemy) {
|
||||
enemy.setHealth(enemy.getHealth() - (strength));
|
||||
enemy.setHealth(enemy.getHealth() - (strength * level));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -41,18 +41,18 @@ public class Game extends JFrame {
|
||||
battle = new WindowOfBattle(this);
|
||||
|
||||
//tohle spustí na začátku menu
|
||||
add(menu);
|
||||
// add(menu);
|
||||
|
||||
//tohle spustí na začátku hru
|
||||
// add(freeMove);
|
||||
// freeMove.start(true);
|
||||
// add(freeMove);
|
||||
// freeMove.start(true);
|
||||
|
||||
//tohle spustí na začátku bitvu
|
||||
// add(battle);
|
||||
// battle.startBattle();
|
||||
add(battle);
|
||||
battle.startBattle();
|
||||
|
||||
//Tohle spustí na začátku tileset overview
|
||||
new EditorManager();
|
||||
// new EditorManager();
|
||||
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setUndecorated(true);
|
||||
@ -64,6 +64,8 @@ public class Game extends JFrame {
|
||||
setExtendedState(MAXIMIZED_BOTH);
|
||||
}
|
||||
|
||||
public Game game() {return this;}
|
||||
public Game game() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ public class InfoManager {
|
||||
private JScrollPane scrollInfo;
|
||||
private JLayeredPane view;
|
||||
|
||||
LinkedList<JRadioButton> radioButtons;
|
||||
private LinkedList<JRadioButton> radioButtons;
|
||||
|
||||
public InfoManager(LevelEditor editor) {
|
||||
this.editor = editor;
|
||||
|
||||
@ -2,6 +2,8 @@ package ruscz.game.gameOfProd.Windows;
|
||||
|
||||
import ruscz.game.gameOfProd.Battle.*;
|
||||
import ruscz.game.gameOfProd.Game;
|
||||
import ruscz.game.gameOfProd.Save.LoadManager;
|
||||
import ruscz.game.gameOfProd.Save.SaveManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@ -53,6 +55,8 @@ public class WindowOfBattle extends JPanel {
|
||||
|
||||
private Game game;
|
||||
private Battle battle;
|
||||
private LoadManager loadManager;
|
||||
private SaveManager saveManager;
|
||||
|
||||
public WindowOfBattle(Game game) {
|
||||
this.game = game;
|
||||
@ -91,11 +95,26 @@ public class WindowOfBattle extends JPanel {
|
||||
menuOfActions.setVisible(false);
|
||||
JButton attack = new JButton("Attack");
|
||||
attack.addActionListener(e -> {
|
||||
attack.setEnabled(false);
|
||||
battle.setPlayerAttack(true);
|
||||
battle.getTimer().start();
|
||||
});
|
||||
attack.setLayout(null);
|
||||
JButton console = new JButton("Console");
|
||||
console.addActionListener(e -> {
|
||||
|
||||
});
|
||||
JButton inventory = new JButton("Items");
|
||||
inventory.addActionListener(e -> {
|
||||
|
||||
});
|
||||
JButton escape = new JButton("Run Away");
|
||||
escape.addActionListener(e -> {
|
||||
|
||||
});
|
||||
menuOfActions.add(attack);
|
||||
menuOfActions.add(console);
|
||||
menuOfActions.add(inventory);
|
||||
menuOfActions.add(escape);
|
||||
|
||||
consoleInput = new JPanel();
|
||||
consoleInput.setSize(CELL_SIZE * (CANVAS_WIDTH - 4), CELL_SIZE);
|
||||
@ -133,7 +152,10 @@ public class WindowOfBattle extends JPanel {
|
||||
}
|
||||
|
||||
public void startBattle() {
|
||||
Hero hero = new Hero(100, 1, "Mark", 1, 100, 1);
|
||||
//saveManager.saveGame();
|
||||
|
||||
//TODO Enemies from Files
|
||||
Hero hero = new Hero(100, 100, "Mark", 1, 100, 1);
|
||||
Enemy enemy1 = new Enemy(10, 1, "123", 1, 1);
|
||||
Enemy enemy2 = new Enemy(10, 1, "test", 1, 2);
|
||||
|
||||
@ -150,13 +172,13 @@ public class WindowOfBattle extends JPanel {
|
||||
Timer t = new Timer(10, actionEvent -> {
|
||||
repaint();
|
||||
canvas.repaint();
|
||||
if (situationText.isVisible()) {
|
||||
situationText.repaint();
|
||||
}
|
||||
situationText.repaint();
|
||||
});
|
||||
t.start();
|
||||
|
||||
battle.startBattle();
|
||||
|
||||
//loadManager.loadSavedGame();
|
||||
}
|
||||
|
||||
public Canvas getCanvas() {
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
<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>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>false</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>
|
||||
@ -0,0 +1,6 @@
|
||||
<item>
|
||||
<name>blue-key-card</name>
|
||||
<multiplicity>1</multiplicity>
|
||||
<image>39</image>
|
||||
<action>key</action>
|
||||
</item>
|
||||
@ -0,0 +1,6 @@
|
||||
<location>
|
||||
<map>openspace</map>
|
||||
<x>8</x>
|
||||
<y>16</y>
|
||||
<direction>3</direction>
|
||||
</location>
|
||||
@ -0,0 +1 @@
|
||||
TODO: Village
|
||||
Loading…
x
Reference in New Issue
Block a user