Battle divided to Classess
This commit is contained in:
parent
a8d51bfb88
commit
f59cd3f8a1
@ -3,6 +3,7 @@ package ruscz.game.gameOfProd.Battle;
|
|||||||
import ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
import ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -82,7 +83,7 @@ public class Battle {
|
|||||||
private void returnControlToPlayer(){
|
private void returnControlToPlayer(){
|
||||||
timer.stop();
|
timer.stop();
|
||||||
windowOfBattle.getMenuOfActions().setVisible(true);
|
windowOfBattle.getMenuOfActions().setVisible(true);
|
||||||
windowOfBattle.getMenuOfActions().getComponents()[0].setEnabled(true);
|
for (Component e: windowOfBattle.getMenuOfActions().getComponents()) e.setEnabled(true);
|
||||||
windowOfBattle.getEnemyDescription().setVisible(true);
|
windowOfBattle.getEnemyDescription().setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,11 +93,13 @@ public class Battle {
|
|||||||
windowOfBattle.getEnemyDescription().setVisible(false);
|
windowOfBattle.getEnemyDescription().setVisible(false);
|
||||||
windowOfBattle.repaint();
|
windowOfBattle.repaint();
|
||||||
turnBelongTo.attack(e);
|
turnBelongTo.attack(e);
|
||||||
|
|
||||||
|
windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " 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);
|
||||||
windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " to " + e.getName());
|
|
||||||
playerAttack = false;
|
|
||||||
|
|
||||||
|
playerAttack = false;
|
||||||
turnBelongTo = null;
|
turnBelongTo = null;
|
||||||
delay = 2;
|
delay = 2;
|
||||||
}
|
}
|
||||||
@ -118,10 +121,11 @@ public class Battle {
|
|||||||
private void attackByMonster(Hero e) {
|
private void attackByMonster(Hero e) {
|
||||||
turnCount++;
|
turnCount++;
|
||||||
turnBelongTo.attack(e);
|
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());
|
windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " to " + e.getName());
|
||||||
|
//TODO Animation of Attack
|
||||||
|
//TODO Animation of Death
|
||||||
|
if (e.health <= 0) heroes.remove(e);
|
||||||
delay = 2;
|
delay = 2;
|
||||||
turnBelongTo = null;
|
turnBelongTo = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
package ruscz.game.gameOfProd.BattleUI;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.CELL_SIZE;
|
||||||
|
|
||||||
|
public class CommandList extends JPanel {
|
||||||
|
public CommandList(WindowOfBattle window){
|
||||||
|
setSize(CELL_SIZE * 8, CELL_SIZE * 6);
|
||||||
|
setLocation(CELL_SIZE * 4, CELL_SIZE * 2);
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
package ruscz.game.gameOfProd.BattleUI;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.*;
|
||||||
|
|
||||||
|
public class ConsoleInput extends JPanel {
|
||||||
|
private JTextPane input;
|
||||||
|
private JButton submit;
|
||||||
|
private JButton list;
|
||||||
|
private JButton exit;
|
||||||
|
|
||||||
|
public ConsoleInput(WindowOfBattle window) {
|
||||||
|
setSize(CELL_SIZE * (CANVAS_WIDTH - 4), CELL_SIZE);
|
||||||
|
setLocation(CELL_SIZE * 4, CELL_SIZE * CANVAS_HEIGHT * 3 / 4 - CELL_SIZE);
|
||||||
|
setVisible(false);
|
||||||
|
|
||||||
|
input = new JTextPane();
|
||||||
|
submit = new JButton("Submit");
|
||||||
|
list = new JButton("List");
|
||||||
|
exit = new JButton("x");
|
||||||
|
|
||||||
|
submit.addActionListener(e -> {
|
||||||
|
//TODO Take text from Field and work with parser
|
||||||
|
});
|
||||||
|
|
||||||
|
list.addActionListener(e -> {
|
||||||
|
submit.setEnabled(false);
|
||||||
|
list.setEnabled(false);
|
||||||
|
exit.setEnabled(false);
|
||||||
|
|
||||||
|
window.getCommandList().setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
exit.addActionListener(e -> {
|
||||||
|
setVisible(false);
|
||||||
|
|
||||||
|
window.getMenuOfActions().getAttack().setEnabled(true);
|
||||||
|
window.getMenuOfActions().getConsole().setEnabled(true);
|
||||||
|
window.getMenuOfActions().getConsole().setEnabled(true);
|
||||||
|
window.getMenuOfActions().getConsole().setEnabled(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
add(input);
|
||||||
|
add(submit);
|
||||||
|
add(list);
|
||||||
|
add(exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JTextPane getInput() {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getSubmit() {
|
||||||
|
return submit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getList() {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getExit() {
|
||||||
|
return exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package ruscz.game.gameOfProd.BattleUI;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.*;
|
||||||
|
|
||||||
|
public class EnemyDescription extends JPanel {
|
||||||
|
public EnemyDescription(WindowOfBattle window) {
|
||||||
|
setSize(CELL_SIZE * CANVAS_WIDTH * 2 / 3, CELL_SIZE * CANVAS_HEIGHT / 4);
|
||||||
|
setLocation(0, CELL_SIZE * CANVAS_HEIGHT * 3 / 4);
|
||||||
|
setBackground(Color.cyan);
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package ruscz.game.gameOfProd.BattleUI;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.CELL_SIZE;
|
||||||
|
|
||||||
|
public class ItemsInventory extends JPanel {
|
||||||
|
public ItemsInventory(WindowOfBattle window){
|
||||||
|
setSize(CELL_SIZE * 8, CELL_SIZE * 6);
|
||||||
|
setLocation(CELL_SIZE * 4, CELL_SIZE * 2);
|
||||||
|
setBackground(Color.yellow);
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,85 @@
|
|||||||
|
package ruscz.game.gameOfProd.BattleUI;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.*;
|
||||||
|
|
||||||
|
public class MenuOfActions extends JPanel {
|
||||||
|
private JButton attack;
|
||||||
|
private JButton console;
|
||||||
|
private JButton inventory;
|
||||||
|
private JButton escape;
|
||||||
|
|
||||||
|
public MenuOfActions(WindowOfBattle window) {
|
||||||
|
setSize(CELL_SIZE * CANVAS_WIDTH / 3, CELL_SIZE * CANVAS_HEIGHT / 4);
|
||||||
|
setLocation(CELL_SIZE * CANVAS_WIDTH * 2 / 3, CELL_SIZE * CANVAS_HEIGHT * 3 / 4);
|
||||||
|
setBackground(Color.green);
|
||||||
|
setVisible(false);
|
||||||
|
|
||||||
|
attack = new JButton("Attack");
|
||||||
|
console = new JButton("Console");
|
||||||
|
inventory = new JButton("Items");
|
||||||
|
escape = new JButton("Run Away");
|
||||||
|
|
||||||
|
attack.addActionListener(e -> {
|
||||||
|
attack.setEnabled(false);
|
||||||
|
console.setEnabled(false);
|
||||||
|
inventory.setEnabled(false);
|
||||||
|
escape.setEnabled(false);
|
||||||
|
|
||||||
|
window.getBattle().setPlayerAttack(true);
|
||||||
|
window.getBattle().getTimer().start();
|
||||||
|
});
|
||||||
|
|
||||||
|
console.addActionListener(e -> {
|
||||||
|
attack.setEnabled(false);
|
||||||
|
console.setEnabled(false);
|
||||||
|
inventory.setEnabled(false);
|
||||||
|
escape.setEnabled(false);
|
||||||
|
|
||||||
|
window.getConsoleInput().setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
inventory.addActionListener(e -> {
|
||||||
|
attack.setEnabled(false);
|
||||||
|
console.setEnabled(false);
|
||||||
|
inventory.setEnabled(false);
|
||||||
|
escape.setEnabled(false);
|
||||||
|
|
||||||
|
window.getItemsInventory().setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
escape.addActionListener(e -> {
|
||||||
|
attack.setEnabled(false);
|
||||||
|
console.setEnabled(false);
|
||||||
|
inventory.setEnabled(false);
|
||||||
|
escape.setEnabled(false);
|
||||||
|
|
||||||
|
//TODO RunAway
|
||||||
|
});
|
||||||
|
|
||||||
|
add(attack);
|
||||||
|
add(console);
|
||||||
|
add(inventory);
|
||||||
|
add(escape);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getAttack() {
|
||||||
|
return attack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getConsole() {
|
||||||
|
return console;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getEscape() {
|
||||||
|
return escape;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package ruscz.game.gameOfProd.BattleUI;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.*;
|
||||||
|
|
||||||
|
public class SituationText extends JPanel {
|
||||||
|
public SituationText(WindowOfBattle window) {
|
||||||
|
setSize(CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_HEIGHT / 4);
|
||||||
|
setLocation(0, CELL_SIZE * CANVAS_HEIGHT * 3 / 4);
|
||||||
|
setBackground(Color.BLUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,15 +1,13 @@
|
|||||||
package ruscz.game.gameOfProd.Windows;
|
package ruscz.game.gameOfProd.Windows;
|
||||||
|
|
||||||
import ruscz.game.gameOfProd.Battle.*;
|
import ruscz.game.gameOfProd.Battle.*;
|
||||||
|
import ruscz.game.gameOfProd.BattleUI.*;
|
||||||
import ruscz.game.gameOfProd.Game;
|
import ruscz.game.gameOfProd.Game;
|
||||||
import ruscz.game.gameOfProd.Save.LoadManager;
|
|
||||||
import ruscz.game.gameOfProd.Save.SaveManager;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
|
|
||||||
public class WindowOfBattle extends JPanel {
|
public class WindowOfBattle extends JPanel {
|
||||||
@ -18,45 +16,46 @@ public class WindowOfBattle extends JPanel {
|
|||||||
public static int CANVAS_HEIGHT = 13;
|
public static int CANVAS_HEIGHT = 13;
|
||||||
|
|
||||||
private static final int KEY_ESCAPE = 27;
|
private static final int KEY_ESCAPE = 27;
|
||||||
|
|
||||||
private static boolean isReadyToPaint;
|
private static boolean isReadyToPaint;
|
||||||
|
|
||||||
public JPanel getSituationText() {
|
public SituationText getSituationText() {
|
||||||
return situationText;
|
return situationText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getEnemyDescription() {
|
public EnemyDescription getEnemyDescription() {
|
||||||
return enemyDescription;
|
return enemyDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getMenuOfActions() {
|
public MenuOfActions getMenuOfActions() {
|
||||||
return menuOfActions;
|
return menuOfActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getConsoleInput() {
|
public ConsoleInput getConsoleInput() {
|
||||||
return consoleInput;
|
return consoleInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getCommandList() {
|
public CommandList getCommandList() {
|
||||||
return commandList;
|
return commandList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getItemsInventory() {
|
public ItemsInventory getItemsInventory() {
|
||||||
return itemsInventory;
|
return itemsInventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Canvas canvas;
|
private Canvas canvas;
|
||||||
private JPanel situationText;
|
private SituationText situationText;
|
||||||
private JPanel enemyDescription;
|
private EnemyDescription enemyDescription;
|
||||||
private JPanel menuOfActions;
|
private MenuOfActions menuOfActions;
|
||||||
private JPanel consoleInput;
|
private ConsoleInput consoleInput;
|
||||||
private JPanel commandList;
|
private CommandList commandList;
|
||||||
private JPanel itemsInventory;
|
private ItemsInventory itemsInventory;
|
||||||
|
|
||||||
private Game game;
|
private Game game;
|
||||||
private Battle battle;
|
private Battle battle;
|
||||||
private LoadManager loadManager;
|
|
||||||
private SaveManager saveManager;
|
public Battle getBattle() {
|
||||||
|
return battle;
|
||||||
|
}
|
||||||
|
|
||||||
public WindowOfBattle(Game game) {
|
public WindowOfBattle(Game game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
@ -71,66 +70,12 @@ public class WindowOfBattle extends JPanel {
|
|||||||
setBackground(Color.BLACK);
|
setBackground(Color.BLACK);
|
||||||
|
|
||||||
canvas = new Canvas();
|
canvas = new Canvas();
|
||||||
canvas.setPreferredSize(new Dimension(
|
situationText = new SituationText(this);
|
||||||
CELL_SIZE * CANVAS_WIDTH,
|
enemyDescription = new EnemyDescription(this);
|
||||||
CELL_SIZE * CANVAS_HEIGHT));
|
menuOfActions = new MenuOfActions(this);
|
||||||
canvas.setSize(CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_HEIGHT);
|
consoleInput = new ConsoleInput(this);
|
||||||
canvas.setBackground(Color.RED);
|
commandList = new CommandList(this);
|
||||||
|
itemsInventory = new ItemsInventory(this);
|
||||||
situationText = new JPanel();
|
|
||||||
situationText.setSize(CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_HEIGHT / 4);
|
|
||||||
situationText.setLocation(0, CELL_SIZE * CANVAS_HEIGHT * 3 / 4);
|
|
||||||
situationText.setBackground(Color.BLUE);
|
|
||||||
|
|
||||||
enemyDescription = new JPanel();
|
|
||||||
enemyDescription.setSize(CELL_SIZE * CANVAS_WIDTH * 2 / 3, CELL_SIZE * CANVAS_HEIGHT / 4);
|
|
||||||
enemyDescription.setLocation(0, CELL_SIZE * CANVAS_HEIGHT * 3 / 4);
|
|
||||||
enemyDescription.setBackground(Color.cyan);
|
|
||||||
enemyDescription.setVisible(false);
|
|
||||||
|
|
||||||
menuOfActions = new JPanel();
|
|
||||||
menuOfActions.setSize(CELL_SIZE * CANVAS_WIDTH / 3, CELL_SIZE * CANVAS_HEIGHT / 4);
|
|
||||||
menuOfActions.setLocation(CELL_SIZE * CANVAS_WIDTH * 2 / 3, CELL_SIZE * CANVAS_HEIGHT * 3 / 4);
|
|
||||||
menuOfActions.setBackground(Color.green);
|
|
||||||
menuOfActions.setVisible(false);
|
|
||||||
JButton attack = new JButton("Attack");
|
|
||||||
attack.addActionListener(e -> {
|
|
||||||
attack.setEnabled(false);
|
|
||||||
battle.setPlayerAttack(true);
|
|
||||||
battle.getTimer().start();
|
|
||||||
});
|
|
||||||
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);
|
|
||||||
consoleInput.setLocation(CELL_SIZE * 4, CELL_SIZE * CANVAS_HEIGHT * 3 / 4 - CELL_SIZE);
|
|
||||||
consoleInput.setVisible(false);
|
|
||||||
|
|
||||||
commandList = new JPanel();
|
|
||||||
commandList.setSize(CELL_SIZE * 8, CELL_SIZE * 6);
|
|
||||||
commandList.setLocation(CELL_SIZE * 4, CELL_SIZE * 2);
|
|
||||||
commandList.setVisible(false);
|
|
||||||
|
|
||||||
itemsInventory = new JPanel();
|
|
||||||
itemsInventory.setSize(CELL_SIZE * 8, CELL_SIZE * 6);
|
|
||||||
itemsInventory.setLocation(CELL_SIZE * 4, CELL_SIZE * 2);
|
|
||||||
itemsInventory.setBackground(Color.yellow);
|
|
||||||
itemsInventory.setVisible(false);
|
|
||||||
|
|
||||||
add(lp);
|
add(lp);
|
||||||
lp.add(canvas, JLayeredPane.DEFAULT_LAYER);
|
lp.add(canvas, JLayeredPane.DEFAULT_LAYER);
|
||||||
@ -198,7 +143,19 @@ public class WindowOfBattle extends JPanel {
|
|||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
|
||||||
class Canvas extends JPanel {
|
class Canvas extends JPanel {
|
||||||
|
Canvas(){
|
||||||
|
setPreferredSize(new Dimension(
|
||||||
|
CELL_SIZE * CANVAS_WIDTH,
|
||||||
|
CELL_SIZE * CANVAS_HEIGHT));
|
||||||
|
setSize(CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_HEIGHT);
|
||||||
|
setBackground(Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
super.paint(g);
|
super.paint(g);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user