Javadoc
This commit is contained in:
parent
22d6595797
commit
490f607986
@ -12,35 +12,27 @@ import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Class for Battle with graphic implementation
|
||||
*/
|
||||
public class Battle {
|
||||
private final LinkedList<Enemy> enemies;
|
||||
private final LinkedList<Hero> heroes;
|
||||
private final WindowOfBattle windowOfBattle;
|
||||
private Timer timer;
|
||||
|
||||
private final SoundManager soundManager;
|
||||
|
||||
private BattlePerson turnBelongTo;
|
||||
|
||||
private LinkedList<BattlePerson> turnOrder;
|
||||
|
||||
private int turnCount;
|
||||
private int delay;
|
||||
|
||||
private boolean playerAttack;
|
||||
|
||||
public void setDelay(int delay) { this.delay = delay; }
|
||||
|
||||
public boolean isTimerStopped() {
|
||||
return timerStopped;
|
||||
}
|
||||
|
||||
public void setTimerStopped(boolean timerStopped) {
|
||||
this.timerStopped = timerStopped;
|
||||
}
|
||||
|
||||
private boolean timerStopped;
|
||||
|
||||
/**
|
||||
* Hide Menu and Enemy Description
|
||||
* Set Attack of Player
|
||||
* @param playerAttack
|
||||
*/
|
||||
public void setPlayerAttack(boolean playerAttack) {
|
||||
windowOfBattle.getMenuOfActions().setVisible(false);
|
||||
windowOfBattle.getEnemyDescription().setVisible(false);
|
||||
@ -67,14 +59,25 @@ public class Battle {
|
||||
return heroes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, if all enemies dies
|
||||
* @return true if all dies
|
||||
*/
|
||||
public boolean checkHealthOfEnemies(){
|
||||
return enemies.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, if all heroes dies
|
||||
* @return true if all dies
|
||||
*/
|
||||
public boolean checkHealthOfHeroes(){
|
||||
return heroes.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start fight by showing menu and creating Timer of battle
|
||||
*/
|
||||
public void startBattle() {
|
||||
turnBelongTo = heroes.getFirst();
|
||||
windowOfBattle.getMenuOfActions().setVisible(true);
|
||||
@ -98,6 +101,10 @@ public class Battle {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* End battle and start cutscene of win or lose
|
||||
* @param b true if win, false if lose
|
||||
*/
|
||||
public void endBattle(boolean b) {
|
||||
timer.stop();
|
||||
timerStopped = true;
|
||||
@ -124,6 +131,9 @@ public class Battle {
|
||||
// saveManager.saveGame();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all Menus and Enemy Description
|
||||
*/
|
||||
private void returnControlToPlayer(){
|
||||
timer.stop();
|
||||
timerStopped = true;
|
||||
@ -133,8 +143,12 @@ public class Battle {
|
||||
windowOfBattle.getSituationText().hideText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attack with animation and logic
|
||||
* Do delay of 2 seconds
|
||||
* @param e Enemy to attack
|
||||
*/
|
||||
private void attackByHero(Enemy e) {
|
||||
turnCount++;
|
||||
windowOfBattle.repaint();
|
||||
turnBelongTo.attack(e);
|
||||
turnBelongTo.setImageEffect("attack");
|
||||
@ -151,6 +165,9 @@ public class Battle {
|
||||
delay = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function, which decide who will attack next
|
||||
*/
|
||||
private void nextTurn() {
|
||||
windowOfBattle.getMenuOfActions().setVisible(false);
|
||||
windowOfBattle.getEnemyDescription().setVisible(false);
|
||||
@ -174,8 +191,12 @@ public class Battle {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attack with animation and logic
|
||||
* Do delay of 2 seconds
|
||||
* @param e Hero to attack
|
||||
*/
|
||||
private void attackByMonster(Hero e) {
|
||||
turnCount++;
|
||||
turnBelongTo.attack(e);
|
||||
turnBelongTo.setImageEffect("attack");
|
||||
if (windowOfBattle.getHitSound() != null) soundManager.playSound(windowOfBattle.getHitSound(), -10.0f);
|
||||
@ -191,12 +212,20 @@ public class Battle {
|
||||
turnBelongTo = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Random enemy from list
|
||||
* @return Random enemy
|
||||
*/
|
||||
private Enemy randomEnemy(){
|
||||
LinkedList list = getEnemies();
|
||||
Random rand = new Random();
|
||||
return (Enemy) list.get(rand.nextInt(list.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Random hero from list
|
||||
* @return Random hero
|
||||
*/
|
||||
private Hero randomHero(){
|
||||
LinkedList list = getHeroes();
|
||||
Random rand = new Random();
|
||||
@ -218,8 +247,23 @@ public class Battle {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove person from one of the list, if died
|
||||
* @param person Person to delete
|
||||
*/
|
||||
public void removePersonFromList(BattlePerson person) {
|
||||
if (person.getClass().getName().equals("ruscz.game.gameOfProd.Battle.Hero")) heroes.remove(person);
|
||||
else enemies.remove(person);
|
||||
}
|
||||
|
||||
public void setDelay(int delay) { this.delay = delay; }
|
||||
|
||||
public boolean isTimerStopped() {
|
||||
return timerStopped;
|
||||
}
|
||||
|
||||
public void setTimerStopped(boolean timerStopped) {
|
||||
this.timerStopped = timerStopped;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package ruscz.game.gameOfProd.Battle;
|
||||
|
||||
/**
|
||||
* Enemy class for battle
|
||||
*/
|
||||
public class Enemy extends BattlePerson {
|
||||
private int id;
|
||||
private final int id;
|
||||
|
||||
public Enemy(int hp, int lvl, String name, int str, int id, String image) {
|
||||
super(hp, lvl, name, str, image);
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package ruscz.game.gameOfProd.Battle;
|
||||
|
||||
/**
|
||||
* Hero class for Battle
|
||||
*/
|
||||
public class Hero extends BattlePerson {
|
||||
private int mana;
|
||||
private int defence;
|
||||
|
||||
@ -8,6 +8,10 @@ import java.awt.*;
|
||||
|
||||
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.CELL_SIZE;
|
||||
|
||||
/**
|
||||
* JPanel with commands to game command line
|
||||
* Used, but because of Text Parser doesn't have any of commands
|
||||
*/
|
||||
public class CommandList extends JPanel {
|
||||
public CommandList(WindowOfBattle window){
|
||||
setSize(CELL_SIZE * 8, CELL_SIZE * 6);
|
||||
|
||||
@ -8,6 +8,10 @@ import java.awt.*;
|
||||
|
||||
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.*;
|
||||
|
||||
/**
|
||||
* JPanel with command line
|
||||
* Used, but because of Text Parser doesn't work
|
||||
*/
|
||||
public class ConsoleInput extends JPanel {
|
||||
private final JTextPane input;
|
||||
private final JButton submit;
|
||||
|
||||
@ -9,6 +9,9 @@ import java.util.LinkedList;
|
||||
|
||||
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.*;
|
||||
|
||||
/**
|
||||
* JPanel with info about Enemies and Heroes
|
||||
*/
|
||||
public class EnemyDescription extends JPanel {
|
||||
|
||||
private final WindowOfBattle windowOfBattle;
|
||||
@ -23,6 +26,9 @@ public class EnemyDescription extends JPanel {
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates info about all persons in battle
|
||||
*/
|
||||
public void updateDescription() {
|
||||
setVisible(true);
|
||||
deletePreviousDescription();
|
||||
@ -31,6 +37,9 @@ public class EnemyDescription extends JPanel {
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all Components to JPanel (Description of Person: name, level, health)
|
||||
*/
|
||||
private void addNewDescription() {
|
||||
if (getComponentCount() != 0) return;
|
||||
if (windowOfBattle.getBattle() == null) return;
|
||||
@ -60,6 +69,9 @@ public class EnemyDescription extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all Components from JPanel
|
||||
*/
|
||||
private void deletePreviousDescription() {
|
||||
if (getComponentCount() == 0) return;
|
||||
for (Component c: getComponents())
|
||||
|
||||
@ -12,6 +12,9 @@ import java.awt.*;
|
||||
|
||||
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.CELL_SIZE;
|
||||
|
||||
/**
|
||||
* JPanel with Inventory
|
||||
*/
|
||||
public class ItemsInventory extends JPanel {
|
||||
private final JPanel items;
|
||||
private final ImageCell imageCell;
|
||||
@ -43,6 +46,10 @@ public class ItemsInventory extends JPanel {
|
||||
add(returnToMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh all Items by deleting all previous info and adding new (Description of Item: image, name, multiplicity and action of that)
|
||||
* Have enabled or disabled button Use
|
||||
*/
|
||||
public void refreshItemsInField() {
|
||||
for (Component c: items.getComponents())
|
||||
items.remove(c);
|
||||
|
||||
@ -8,6 +8,9 @@ import java.util.Random;
|
||||
|
||||
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.*;
|
||||
|
||||
/**
|
||||
* JPanel with menu of Action, that User can do
|
||||
*/
|
||||
public class MenuOfActions extends JPanel {
|
||||
private final JButton attack;
|
||||
private final JButton console;
|
||||
|
||||
@ -7,6 +7,9 @@ import java.awt.*;
|
||||
|
||||
import static ruscz.game.gameOfProd.Windows.WindowOfBattle.*;
|
||||
|
||||
/**
|
||||
* JPanel with text, describing fight
|
||||
*/
|
||||
public class SituationText extends JPanel {
|
||||
public SituationText(WindowOfBattle window) {
|
||||
setSize(CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_HEIGHT / 4);
|
||||
@ -15,6 +18,9 @@ public class SituationText extends JPanel {
|
||||
setBorder(BorderFactory.createLineBorder(new Color(213, 108, 18), 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide text from JPanel (Just deleting them)
|
||||
*/
|
||||
public void hideText() {
|
||||
JLabel label = (JLabel) getComponent(0);
|
||||
label.setText("");
|
||||
|
||||
@ -7,10 +7,13 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Cell with collision to Player
|
||||
*/
|
||||
public class Block extends Cell {
|
||||
private ImageCell imageCell;
|
||||
private boolean paint;
|
||||
private String partial;
|
||||
private final ImageCell imageCell;
|
||||
private final boolean paint;
|
||||
private final String partial;
|
||||
|
||||
public Block(int x, int y, Map map, boolean paint) {
|
||||
super(x, y, WindowOfFreeMove.CELL_SIZE, Color.BLUE);
|
||||
@ -26,10 +29,17 @@ public class Block extends Cell {
|
||||
this.paint = paint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this Block in this position
|
||||
* @param x X position
|
||||
* @param y Y position
|
||||
* @return true if Block is in this position
|
||||
*/
|
||||
public boolean isInBlock(int x, int y) {
|
||||
return (this.getX() == x) && (this.getY() == y);
|
||||
}
|
||||
|
||||
|
||||
public boolean isInBlock(int x, int y, boolean half) {
|
||||
return (this.getX() == x) && (this.getY() == y) && !(partial.equals("d"));
|
||||
}
|
||||
|
||||
@ -2,9 +2,12 @@ package ruscz.game.gameOfProd.Cells;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* General class for Cell
|
||||
*/
|
||||
public class Cell {
|
||||
private int x, y;
|
||||
private int size;
|
||||
private final int size;
|
||||
private Color color;
|
||||
|
||||
public Cell(int x, int y, int size, Color color) {
|
||||
@ -13,6 +16,11 @@ public class Cell {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set position of Cell
|
||||
* @param x X position
|
||||
* @param y Y position
|
||||
*/
|
||||
public void set(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
@ -13,7 +13,7 @@ import java.util.LinkedList;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ChestCell extends InteractionCell {
|
||||
private LinkedList<Item> chestInventory;
|
||||
private final LinkedList<Item> chestInventory;
|
||||
private boolean showItem;
|
||||
private boolean isActive;
|
||||
|
||||
|
||||
@ -10,11 +10,8 @@ import java.awt.*;
|
||||
public class DoorCell extends InteractionCell {
|
||||
private boolean isOpen;
|
||||
private boolean isLocked;
|
||||
private boolean directionVert;
|
||||
private final boolean directionVert;
|
||||
private String sound;
|
||||
private String soundOpen;
|
||||
private String soundClose;
|
||||
private String soundLocked;
|
||||
private float volume;
|
||||
|
||||
public DoorCell(int x, int y, boolean directionVert, String message, Dialog dialog, Map map, WindowOfFreeMove window) {
|
||||
|
||||
@ -6,11 +6,11 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||
import java.awt.*;
|
||||
|
||||
public class EventMoveToCell extends Cell {
|
||||
private Map map;
|
||||
private WindowOfFreeMove window;
|
||||
private int id;
|
||||
private int directionOut;
|
||||
private boolean paint;
|
||||
private final Map map;
|
||||
private final WindowOfFreeMove window;
|
||||
private final int id;
|
||||
private final int directionOut;
|
||||
private final boolean paint;
|
||||
|
||||
public int getId(){
|
||||
return id;
|
||||
@ -36,7 +36,7 @@ public class EventMoveToCell extends Cell {
|
||||
window.paintMapOnWindow();
|
||||
window.repaintCanvas();
|
||||
if (!isActiveTriggerBehindMoveTo())
|
||||
window.setCanPersonMove(true);
|
||||
WindowOfFreeMove.setCanPersonMove(true);
|
||||
}
|
||||
|
||||
private boolean isActiveTriggerBehindMoveTo() {
|
||||
|
||||
@ -19,11 +19,11 @@ import java.util.Scanner;
|
||||
|
||||
public class InteractionCell extends Cell {
|
||||
protected String message;
|
||||
protected ruscz.game.gameOfProd.Dialog.Dialog dialog;
|
||||
protected Dialog dialog;
|
||||
protected Scanner scanner;
|
||||
private ImageCell imageCell;
|
||||
private SoundManager soundManager;
|
||||
private WindowOfFreeMove window;
|
||||
private final ImageCell imageCell;
|
||||
private final SoundManager soundManager;
|
||||
private final WindowOfFreeMove window;
|
||||
protected boolean paint;
|
||||
private Timer timer;
|
||||
private Timer textTimer;
|
||||
@ -50,7 +50,7 @@ public class InteractionCell extends Cell {
|
||||
readDialogFile("empty");
|
||||
}
|
||||
else {
|
||||
window.setCanPersonMove(false);
|
||||
WindowOfFreeMove.setCanPersonMove(false);
|
||||
readDialogFile(message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,10 +7,9 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||
import java.awt.*;
|
||||
|
||||
public class Person extends Cell {
|
||||
|
||||
private final int WALKING_SPEED = 3;
|
||||
|
||||
private Map map;
|
||||
private final Map map;
|
||||
private ImagePerson imagePerson;
|
||||
private int directionMove;
|
||||
private int directionSight;
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
package ruscz.game.gameOfProd.Cells;
|
||||
|
||||
import ruscz.game.gameOfProd.Game;
|
||||
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class RandomEncounterCell extends Cell {
|
||||
private final int level;
|
||||
private final Game game;
|
||||
|
||||
public RandomEncounterCell(int x, int y, int lvl, Game game) {
|
||||
super(x, y, WindowOfFreeMove.CELL_SIZE, Color.pink);
|
||||
this.level = lvl;
|
||||
this.game = game;
|
||||
}
|
||||
}
|
||||
@ -7,15 +7,18 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Class for showing text on Dialog Bar
|
||||
*/
|
||||
public class Dialog {
|
||||
private String text;
|
||||
private int textLength;
|
||||
private ImageDialog imageDialog;
|
||||
private Timer timer;
|
||||
private DialogBar dialogBar;
|
||||
private final DialogBar dialogBar;
|
||||
private int charNumber;
|
||||
private boolean timerIsRunning;
|
||||
private SoundManager soundManager;
|
||||
private final SoundManager soundManager;
|
||||
private String voice;
|
||||
private boolean voiceover;
|
||||
|
||||
@ -27,7 +30,11 @@ public class Dialog {
|
||||
voiceover = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Takes String of Text and prepare JLabel with all settings needed
|
||||
* @param string Text to show
|
||||
* @return JLabel with text
|
||||
*/
|
||||
public JLabel prepareDialogBar(String string) {
|
||||
int cellSize = WindowOfFreeMove.CELL_SIZE;
|
||||
Font f1 = new Font("Times New Roman", Font.PLAIN, cellSize / 2);
|
||||
@ -51,6 +58,10 @@ public class Dialog {
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function, that add next symbol from text to DialogBar
|
||||
* Stop timer of adding symbols, if full text is showed
|
||||
*/
|
||||
private void showByChar() {
|
||||
if (charNumber >= textLength)
|
||||
return;
|
||||
@ -66,6 +77,9 @@ public class Dialog {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Showing DialogBar with animation of adding symbol
|
||||
*/
|
||||
public void showText() {
|
||||
charNumber = 0;
|
||||
if (text.contains("<html>"))
|
||||
@ -81,6 +95,9 @@ public class Dialog {
|
||||
timer.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Showing block of text with fast changing of text (while, not Timer)
|
||||
*/
|
||||
public void showFastText() {
|
||||
charNumber = 0;
|
||||
if (text.contains("<html>"))
|
||||
@ -96,6 +113,9 @@ public class Dialog {
|
||||
timerIsRunning = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip for animation of symbols
|
||||
*/
|
||||
public void skipShowText() {
|
||||
timer.stop();
|
||||
timerIsRunning = false;
|
||||
@ -105,6 +125,9 @@ public class Dialog {
|
||||
dialogBar.repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide text from Dialog Bar
|
||||
*/
|
||||
public void hideText() {
|
||||
dialogBar.setVisible(false);
|
||||
dialogBar.unsetImageDialog();
|
||||
|
||||
@ -6,6 +6,9 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Graphical interpretation for Dialog, used to show text
|
||||
*/
|
||||
public class DialogBar extends JPanel {
|
||||
private ImageDialog imageDialog;
|
||||
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
package ruscz.game.gameOfProd.Dialog;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class MenuBar extends JPanel {
|
||||
}
|
||||
@ -22,7 +22,7 @@ import java.util.LinkedList;
|
||||
* It also holds references to all major classes
|
||||
*/
|
||||
public class WindowOfFreeMove extends JLayeredPane {
|
||||
public static final int CELL_SIZE = 69;
|
||||
public static final int CELL_SIZE = 70;
|
||||
public static int CANVAS_WIDTH = 50;
|
||||
public static int CANVAS_HEIGHT = 50;
|
||||
public static final int WINDOW_WIDTH = 13;
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
<trigger>
|
||||
<x>6</x>
|
||||
<y>4</y>
|
||||
<active>false</active>
|
||||
<active>true</active>
|
||||
</trigger>
|
||||
<trigger>
|
||||
<x>14</x>
|
||||
@ -24,7 +24,7 @@
|
||||
<chest>
|
||||
<x>1</x>
|
||||
<y>2</y>
|
||||
<active>false</active>
|
||||
<active>true</active>
|
||||
</chest>
|
||||
<chest>
|
||||
<x>15</x>
|
||||
@ -35,7 +35,7 @@
|
||||
<x>8</x>
|
||||
<y>4</y>
|
||||
<locked>false</locked>
|
||||
<open>true</open>
|
||||
<open>false</open>
|
||||
</dooŕ>
|
||||
<door>
|
||||
<x>2</x>
|
||||
@ -152,7 +152,7 @@
|
||||
<trigger>
|
||||
<x>6</x>
|
||||
<y>2</y>
|
||||
<active>false</active>
|
||||
<active>true</active>
|
||||
</trigger>
|
||||
<door>
|
||||
<x>6</x>
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
<item>
|
||||
<name>cup-o'-coffee</name>
|
||||
<multiplicity>1</multiplicity>
|
||||
<image>295</image>
|
||||
<action>heal</action>
|
||||
</item>
|
||||
@ -1,6 +1,6 @@
|
||||
<location>
|
||||
<map>openspace</map>
|
||||
<x>8</x>
|
||||
<y>15</y>
|
||||
<direction>3</direction>
|
||||
<map>storageroom</map>
|
||||
<x>6</x>
|
||||
<y>2</y>
|
||||
<direction>0</direction>
|
||||
</location>
|
||||
Loading…
x
Reference in New Issue
Block a user