improved javadoc and enimateMove
This commit is contained in:
parent
490f607986
commit
53f9333ce1
@ -60,7 +60,7 @@ public class Battle {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, if all enemies dies
|
||||
* Checks, if all enemies died
|
||||
* @return true if all dies
|
||||
*/
|
||||
public boolean checkHealthOfEnemies(){
|
||||
@ -68,7 +68,7 @@ public class Battle {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, if all heroes dies
|
||||
* Checks, if all heroes died
|
||||
* @return true if all dies
|
||||
*/
|
||||
public boolean checkHealthOfHeroes(){
|
||||
|
||||
@ -8,6 +8,9 @@ import java.awt.image.RescaleOp;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* General class for all battle actors
|
||||
*/
|
||||
public abstract class BattlePerson {
|
||||
protected int maxHealth;
|
||||
protected int health;
|
||||
@ -34,6 +37,10 @@ public abstract class BattlePerson {
|
||||
strength = str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses image to be displayed
|
||||
* @param name image file name
|
||||
*/
|
||||
public void parseImage(String name) {
|
||||
try {
|
||||
image = ImageIO.read(new File("src/main/resources/characters/" + name.substring(0, name.indexOf("-battle")) + "/" + name + ".png"));
|
||||
@ -47,6 +54,10 @@ public abstract class BattlePerson {
|
||||
effectCoords(effect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts timer that is effecting person's coordinates - creates movement effects
|
||||
* @param effect effect name
|
||||
*/
|
||||
private void effectCoords(String effect) {
|
||||
if (effect.equals("hover")) {
|
||||
final boolean[] isGoingUp = {true};
|
||||
@ -102,6 +113,9 @@ public abstract class BattlePerson {
|
||||
if (effectTimer!= null) effectTimer.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a flashing effect of getting hurt
|
||||
*/
|
||||
private void getHurt() {
|
||||
BufferedImage originalImage = image;
|
||||
BufferedImage whiteImage = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
@ -128,6 +142,9 @@ public abstract class BattlePerson {
|
||||
timer.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a line effect of getting healed
|
||||
*/
|
||||
protected void getHealed() {
|
||||
BufferedImage originalImage = image;
|
||||
BufferedImage whiteImage = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
@ -150,6 +167,10 @@ public abstract class BattlePerson {
|
||||
timer.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays grid effect of dying and removes person from battle
|
||||
* @param battle reference for Battle
|
||||
*/
|
||||
public void getKilled(Battle battle) {
|
||||
BufferedImage originalImage = image;
|
||||
BufferedImage whiteImage = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
@ -11,6 +11,7 @@ public class Enemy extends BattlePerson {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
//this constructor is here for of tests
|
||||
public Enemy(int hp, int lvl, String name, int str, int id) {
|
||||
super(hp, lvl, name, str);
|
||||
this.id = id;
|
||||
|
||||
@ -15,6 +15,7 @@ public class Hero extends BattlePerson {
|
||||
isBlocking = false;
|
||||
}
|
||||
|
||||
//this constructor is here for of tests
|
||||
public Hero(int hp, int lvl, String name, int str, int mana, int defence){
|
||||
super(hp, lvl, name, str);
|
||||
this.mana = mana;
|
||||
|
||||
@ -40,6 +40,12 @@ public class Block extends Cell {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param x X position
|
||||
* @param y Y position
|
||||
* @param half is half-block
|
||||
* @return true if Block is upper half-block
|
||||
*/
|
||||
public boolean isInBlock(int x, int y, boolean half) {
|
||||
return (this.getX() == x) && (this.getY() == y) && !(partial.equals("d"));
|
||||
}
|
||||
|
||||
@ -12,6 +12,9 @@ import java.io.FileNotFoundException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Special type of Interaction cell that holds an inventory
|
||||
*/
|
||||
public class ChestCell extends InteractionCell {
|
||||
private final LinkedList<Item> chestInventory;
|
||||
private boolean showItem;
|
||||
@ -33,6 +36,10 @@ public class ChestCell extends InteractionCell {
|
||||
fillChest(inventory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills chest with item from file
|
||||
* @param inventory name of inventory file
|
||||
*/
|
||||
private void fillChest(String inventory) {
|
||||
try {
|
||||
File inventoryInfo = new File("src/main/resources/chests/" + inventory + ".txt");
|
||||
@ -55,6 +62,9 @@ public class ChestCell extends InteractionCell {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts an item in Players inventory
|
||||
*/
|
||||
private void putItemToInventory() {
|
||||
if (chestInventory.size() == 0) {
|
||||
endEvent();
|
||||
|
||||
@ -7,6 +7,9 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Special type of Interaction cell that can act as a Block or as Empty
|
||||
*/
|
||||
public class DoorCell extends InteractionCell {
|
||||
private boolean isOpen;
|
||||
private boolean isLocked;
|
||||
@ -45,6 +48,9 @@ public class DoorCell extends InteractionCell {
|
||||
super.useItem(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets sound that is played on interaction
|
||||
*/
|
||||
private void setSound() {
|
||||
if (isOpen) {
|
||||
sound = super.getSoundManager().getSoundMap().get("doorOpen");
|
||||
|
||||
@ -5,6 +5,9 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Cell that moves Player between maps
|
||||
*/
|
||||
public class EventMoveToCell extends Cell {
|
||||
private final Map map;
|
||||
private final WindowOfFreeMove window;
|
||||
@ -29,6 +32,9 @@ public class EventMoveToCell extends Cell {
|
||||
|
||||
public int getDirectionOut() { return directionOut; }
|
||||
|
||||
/**
|
||||
* Moves player to map that is linked with this Moveto cell
|
||||
*/
|
||||
public void moveToMap() {
|
||||
window.getMapManager().getActualMap().setIdExit(id);
|
||||
window.setMapManager(this.map);
|
||||
@ -39,6 +45,10 @@ public class EventMoveToCell extends Cell {
|
||||
WindowOfFreeMove.setCanPersonMove(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for active Trigger cells in the directionOut from Door
|
||||
* @return true if there is an active Trigger cell
|
||||
*/
|
||||
private boolean isActiveTriggerBehindMoveTo() {
|
||||
int x = window.getMapManager().getActualMap().getPerson().getX();
|
||||
int y = window.getMapManager().getActualMap().getPerson().getY();
|
||||
|
||||
@ -17,6 +17,9 @@ import java.io.FileNotFoundException;
|
||||
import java.util.Objects;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Cell that is interactible by Player
|
||||
*/
|
||||
public class InteractionCell extends Cell {
|
||||
protected String message;
|
||||
protected Dialog dialog;
|
||||
@ -38,6 +41,9 @@ public class InteractionCell extends Cell {
|
||||
this.paint = paint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts regular event or cut-scene
|
||||
*/
|
||||
public void startEvent() {
|
||||
if (message != null) {
|
||||
if (message.contains("cutscene")) {
|
||||
@ -56,6 +62,10 @@ public class InteractionCell extends Cell {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads event file and passes in on to readNextLine
|
||||
* @param name event file name
|
||||
*/
|
||||
public void readDialogFile(String name) {
|
||||
try {
|
||||
File dialogFile = new File("src/main/resources/dialogs/" + name + ".txt");
|
||||
@ -67,6 +77,9 @@ public class InteractionCell extends Cell {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses line of event text into set of commands
|
||||
*/
|
||||
public void readNextLine() {
|
||||
if (scanner.hasNextLine() && !dialog.getTimerIsRunning()) {
|
||||
String data = scanner.nextLine();
|
||||
@ -211,6 +224,9 @@ public class InteractionCell extends Cell {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends event and bounds camera
|
||||
*/
|
||||
public void endEvent() {
|
||||
if (dialog != null) {
|
||||
dialog.hideText();
|
||||
@ -226,6 +242,11 @@ public class InteractionCell extends Cell {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses line of cut-scene text into a set of commands if the sequence numbers are equal
|
||||
* @param name text to parse
|
||||
* @param i sequence number
|
||||
*/
|
||||
public void playCustscene(String name, int i) {
|
||||
try {
|
||||
File cutsceneFile = new File("src/main/resources/dialogs/cutscenes/" + name + ".txt");
|
||||
@ -257,7 +278,7 @@ public class InteractionCell extends Cell {
|
||||
String[] texts = line.split("<split>");
|
||||
final int[] j = {0};
|
||||
textTimer = new Timer(100, e -> {
|
||||
if (j[0] == texts.length - 1) stopTextTimer();
|
||||
if (j[0] == texts.length - 1) textTimer.stop();
|
||||
if (!dialog.getTimerIsRunning()) {
|
||||
if (texts[j[0]].contains("<br/>")) {
|
||||
texts[j[0]] = "<html>" + texts[j[0]] + "</html>";
|
||||
@ -370,10 +391,10 @@ public class InteractionCell extends Cell {
|
||||
}
|
||||
}
|
||||
|
||||
private void stopTextTimer() {
|
||||
textTimer.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses a selected item
|
||||
* @param item item to be used
|
||||
*/
|
||||
public void useItem(Item item) {
|
||||
InventoryManager.removeItem(item, 1);
|
||||
}
|
||||
|
||||
@ -15,6 +15,9 @@ import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Person-like cell that is controlled by application
|
||||
*/
|
||||
public class Npc extends Person {
|
||||
private final MapManager mapManager;
|
||||
private String name;
|
||||
@ -41,6 +44,11 @@ public class Npc extends Person {
|
||||
this.mapManager = mapManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds closest path from current position to end and moves NPC accordingly
|
||||
* @param endX ending X value
|
||||
* @param endY ending Y value
|
||||
*/
|
||||
public void move(int endX, int endY) {
|
||||
PathFinder pathFinder = new PathFinder(getMap());
|
||||
LinkedList<Direction> directions = pathFinder.getWayWithCollision(getX(), getY(), endX, endY);
|
||||
@ -75,6 +83,11 @@ public class Npc extends Person {
|
||||
timer.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops NPC's movement and if battle name is not null and there is Player in front of NPC, is starts battle sequence
|
||||
* @param endX ending X value
|
||||
* @param endY ending Y value
|
||||
*/
|
||||
private void stopNPCMove(int endX, int endY) {
|
||||
timer.stop();
|
||||
if (battle != null && endX == mapManager.getActualMap().getPerson().getX() && endY == mapManager.getActualMap().getPerson().getY()) {
|
||||
@ -82,30 +95,45 @@ public class Npc extends Person {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves NPC up one cell
|
||||
*/
|
||||
private void moveUp() {
|
||||
int y = getY() - 1;
|
||||
set(getX(), y);
|
||||
direction = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves NPC down one cell
|
||||
*/
|
||||
private void moveDown() {
|
||||
int y = getY() + 1;
|
||||
set(getX(), y);
|
||||
direction = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves NPC left one cell
|
||||
*/
|
||||
private void moveLeft() {
|
||||
int x = getX() - 1;
|
||||
set(x, getY());
|
||||
direction = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves NPC right one cell
|
||||
*/
|
||||
private void moveRight() {
|
||||
int x = getX() + 1;
|
||||
set(x, getY());
|
||||
direction = 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads NPC's attributes from file
|
||||
*/
|
||||
private void loadNpc() {
|
||||
File dialogFile = new File("src/main/resources/characters/" + name + "/" + name + ".txt");
|
||||
Scanner scanner = null;
|
||||
|
||||
@ -6,6 +6,9 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Class managing Player
|
||||
*/
|
||||
public class Person extends Cell {
|
||||
private final int WALKING_SPEED = 3;
|
||||
|
||||
@ -17,6 +20,7 @@ public class Person extends Cell {
|
||||
private boolean isMoving;
|
||||
private static boolean isInEvent;
|
||||
private int distanceOfAnimation;
|
||||
private long time;
|
||||
|
||||
public Map getMap() {
|
||||
return map;
|
||||
@ -61,6 +65,9 @@ public class Person extends Cell {
|
||||
this.imagePerson = new ImagePerson(name, rectangles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for user input then checks if movement is possible then moves Player
|
||||
*/
|
||||
public void move() {
|
||||
if (!isMoving) {
|
||||
int x = this.getX();
|
||||
@ -173,16 +180,37 @@ public class Person extends Cell {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is an Event cell in front of Player
|
||||
* @param x X position of Player
|
||||
* @param y Y position of Player
|
||||
* @param directionSight direction of sight of Player
|
||||
* @return true if there is an event in front of Player
|
||||
*/
|
||||
private boolean isEventInFront(int x, int y, int directionSight) {
|
||||
int[] coords = map.directionSightSwitch(x, y, directionSight);
|
||||
return map.isInteractionCell(coords[0], coords[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is a Door cell in front of Player
|
||||
* @param x X position of Player
|
||||
* @param y Y position of Player
|
||||
* @param directionSight direction of sight of Player
|
||||
* @return true if there is a door in front of Player
|
||||
*/
|
||||
private boolean isDoorInFront(int x, int y, int directionSight) {
|
||||
int[] coords = map.directionSightSwitch(x, y, directionSight);
|
||||
return map.isDoor(coords[0], coords[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is a Chest cell in front of Player
|
||||
* @param x X position of Player
|
||||
* @param y Y position of Player
|
||||
* @param directionSight direction of sight of Player
|
||||
* @return true if there is a chest in front of Player
|
||||
*/
|
||||
private boolean isChestInFront(int x, int y, int directionSight) {
|
||||
int[] coords = map.directionSightSwitch(x, y, directionSight);
|
||||
return map.isActiveChest(coords[0], coords[1]);
|
||||
@ -229,7 +257,15 @@ public class Person extends Cell {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Animates Players move throughout the map
|
||||
* @param g graphics for painting
|
||||
* @param direction Player's movement direction
|
||||
*/
|
||||
public void animateMove(Graphics2D g, int direction){
|
||||
if (System.currentTimeMillis() - time < WindowOfFreeMove.REPAINT_DELAY)
|
||||
WindowOfFreeMove.sleep(WindowOfFreeMove.REPAINT_DELAY - (System.currentTimeMillis() - time));
|
||||
time = System.currentTimeMillis();
|
||||
int Xsize = 0;
|
||||
int Ysize = 0;
|
||||
switch (direction) {
|
||||
|
||||
@ -6,6 +6,9 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Special type of Interaction cell that is triggered on Player stepping onto it
|
||||
*/
|
||||
public class TriggerCell extends InteractionCell {
|
||||
private boolean isActive;
|
||||
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package ruscz.game.gameOfProd.Cells;
|
||||
|
||||
/**
|
||||
* Enumeration of basic cell types
|
||||
*/
|
||||
public enum TypeOfCell {
|
||||
BLOCK, EMPTY, MOVETO, EVENT, SPAWNPOINT;
|
||||
}
|
||||
|
||||
@ -25,9 +25,9 @@ public class ImageCell {
|
||||
private int[][] mapForeground;
|
||||
|
||||
/**
|
||||
* Creates new matrices based on winth and height values
|
||||
* @param width is width of new map
|
||||
* @param height is height of new map
|
||||
* Creates new matrices based on winth and height values
|
||||
*/
|
||||
public void readMapFile(int width, int height) {
|
||||
mapBackground = new int[width][height];
|
||||
@ -35,8 +35,8 @@ public class ImageCell {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name is name of map file
|
||||
* Reads and parses (map-name)-tileset.txt file into matrices and arrays, separates values and passes them on for further parsing
|
||||
* @param name is name of map file
|
||||
*/
|
||||
public void readMapFile(String name) {
|
||||
try {
|
||||
@ -75,8 +75,8 @@ public class ImageCell {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tilesetInfo is name of tileset image
|
||||
* Parses tileset image into a tileset (array)
|
||||
* @param tilesetInfo is name of tileset image
|
||||
*/
|
||||
public void imageTileset(String[] tilesetInfo) {
|
||||
try {
|
||||
@ -113,8 +113,8 @@ public class ImageCell {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param file is name of map tp be parsed
|
||||
* Parses (map-name)-objectset.txt file into a matrix
|
||||
* @param file is name of map tp be parsed
|
||||
*/
|
||||
public void imageObjectset(String file) {
|
||||
try {
|
||||
@ -134,8 +134,8 @@ public class ImageCell {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cellInfo is text representation of cellMap
|
||||
* Parses text into a hash map
|
||||
* @param cellInfo is text representation of cellMap
|
||||
*/
|
||||
public void loadCellMap(String[] cellInfo) {
|
||||
if (cellMap == null)
|
||||
@ -158,8 +158,8 @@ public class ImageCell {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemInfo is name of item image
|
||||
* Parses item image into array
|
||||
* @param itemInfo is name of item image
|
||||
*/
|
||||
public void imageItem(String itemInfo) {
|
||||
int imageWidth = 0;
|
||||
|
||||
@ -15,8 +15,8 @@ public class ImageDoor {
|
||||
private int size;
|
||||
|
||||
/**
|
||||
* @param rectangles is array of door images
|
||||
* Parses images of door into an array
|
||||
* @param rectangles is array of door images
|
||||
*/
|
||||
public void setAllImagesOfDoor(Rectangle[] rectangles){
|
||||
imagesOfDoor = new BufferedImage[4];
|
||||
|
||||
@ -19,8 +19,8 @@ public class ImagePerson {
|
||||
private int subimageHeight;
|
||||
|
||||
/**
|
||||
* @param rectangles is array of hero images
|
||||
* Parses images of hero into an array
|
||||
* @param rectangles is array of hero images
|
||||
*/
|
||||
public void setAllImagesOfDirection(Rectangle[] rectangles){
|
||||
imagesOfDirection = new BufferedImage[12];
|
||||
@ -54,9 +54,9 @@ public class ImagePerson {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resizes image to be properly displayed in game
|
||||
* @param img is image to be resized
|
||||
* @return resized image
|
||||
* Resizes image to be properly displayed in game
|
||||
*/
|
||||
public BufferedImage resize(BufferedImage img) {
|
||||
Image tmp;
|
||||
|
||||
@ -91,10 +91,10 @@ public class CellSetConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new JLabel with name of cell type
|
||||
* @param name is name of label
|
||||
* @param offset is offset of label
|
||||
* @return new JLabel
|
||||
* Creates new JLabel with name of cell type
|
||||
*/
|
||||
private JLabel nameLabel(String name, int offset) {
|
||||
JLabel label = new JLabel("<html><div style='width: 250; text-align:center; font-size: 16'>" + name + "</div></html>");
|
||||
@ -103,10 +103,10 @@ public class CellSetConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new JLabel with image of the selected tile
|
||||
* @param name is name of label
|
||||
* @param offset is offset of label
|
||||
* @return new JLabel
|
||||
* Creates new JLabel with image of the selected tile
|
||||
*/
|
||||
private JLabel iconLabel(String name, int offset) {
|
||||
JLabel label = new JLabel();
|
||||
@ -118,9 +118,9 @@ public class CellSetConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates label with 'Inner Value:' text
|
||||
* @param offset is offset of label
|
||||
* @return new JLabel
|
||||
* Creates label with 'Inner Value:' text
|
||||
*/
|
||||
private JLabel valueLabel(int offset) {
|
||||
JLabel label = new JLabel("Inner Value:");
|
||||
@ -129,10 +129,10 @@ public class CellSetConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates text field for value input
|
||||
* @param name is name of field
|
||||
* @param offset is offset of field
|
||||
* @return new JTextField
|
||||
* Creates text field for value input
|
||||
*/
|
||||
private JTextField numField(String name, int offset) {
|
||||
JTextField field = new JTextField(String.valueOf(editor.getCellMap().get(name)));
|
||||
@ -142,11 +142,11 @@ public class CellSetConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new button for importing value from Tileset Overview
|
||||
* @param iconLabel is label to be changed
|
||||
* @param tileNum is text field to be changed
|
||||
* @param offset is offset of button
|
||||
* @return new JButton
|
||||
* Creates new button for importing value from Tileset Overview
|
||||
*/
|
||||
private JButton importButton(JLabel iconLabel, JTextField tileNum, int offset) {
|
||||
JButton button = new JButton("Import selected tile");
|
||||
@ -166,10 +166,10 @@ public class CellSetConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new button for selecting a tile in Tileset Overview
|
||||
* @param importButton is reference for connected import button
|
||||
* @param offset is offset of button
|
||||
* @return new JButton
|
||||
* Creates new button for selecting a tile in Tileset Overview
|
||||
*/
|
||||
private JButton selectButton(JButton importButton, int offset) {
|
||||
JButton button = new JButton("Select tile");
|
||||
@ -186,9 +186,9 @@ public class CellSetConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new label that is used as a divider between different blocks of fields
|
||||
* @param offset is offset of label
|
||||
* @return new JLabel
|
||||
* Creates new label that is used as a divider between different blocks of fields
|
||||
*/
|
||||
private JLabel dividerLabel(int offset) {
|
||||
JLabel label = new JLabel();
|
||||
|
||||
@ -23,8 +23,8 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type is type of cell
|
||||
* Displays detailed info based on the type of cell provided
|
||||
* @param type is type of cell
|
||||
*/
|
||||
public void displayDetailedCellInfo(String type) {
|
||||
removeAll();
|
||||
@ -68,11 +68,11 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays set of radio buttons for true/false selection
|
||||
* @param title is tile of this field
|
||||
* @param trueLabel is true value
|
||||
* @param falseLabel is false value
|
||||
* @param offset is offset from top of menu
|
||||
* Displays set of radio buttons for true/false selection
|
||||
*/
|
||||
private void trueFalseInfo(String title, String trueLabel, String falseLabel, int offset) {
|
||||
JLabel label = new JLabel("<html><div style='text-align: center; width: 260'>Is " + title + "</div></html>");
|
||||
@ -102,10 +102,10 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays one text field with a name
|
||||
* @param title is tile of this field
|
||||
* @param fieldName is name of text field
|
||||
* @param offset is offset from top of menu
|
||||
* Displays one text field with a name
|
||||
*/
|
||||
private void fieldInfo(String title, String fieldName, int offset) {
|
||||
JLabel label = new JLabel("<html><div style='text-align: center; width: 260'>" + title + "</div></html>");
|
||||
@ -162,8 +162,8 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param offset is offset from top of menu
|
||||
* Displays set of four radio buttons for direction selection
|
||||
* @param offset is offset from top of menu
|
||||
*/
|
||||
private void directionInfo(int offset) {
|
||||
JLabel label = new JLabel("<html><div style='text-align: center; width: 260'>Direction Out</div></html>");
|
||||
@ -208,9 +208,9 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all attributes from menu into text
|
||||
* @param type type of cell
|
||||
* @return cell value as it would be in a text file
|
||||
* Saves all attributes from menu into text
|
||||
*/
|
||||
public String getCellInfo(String type) {
|
||||
String info = type;
|
||||
@ -262,9 +262,9 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes type of cell based on visibility value
|
||||
* @param type type of cell
|
||||
* @return changed type of cell
|
||||
* Changes type of cell based on visibility value
|
||||
*/
|
||||
private String getVisibleInfo(String type) {
|
||||
String info = "";
|
||||
@ -282,8 +282,8 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return text to determine if block is half-block
|
||||
* Checks if a block is supposed to be half-block
|
||||
* @return text to determine if block is half-block
|
||||
*/
|
||||
private String getUpperLowerInfo() {
|
||||
String info = "";
|
||||
@ -301,10 +301,10 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves field value
|
||||
* @param fieldName name of field to be saved
|
||||
* @param isRequired is this field required to be filled in
|
||||
* @return value form field
|
||||
* Saves field value
|
||||
*/
|
||||
private String getFieldInfo(String fieldName, boolean isRequired) {
|
||||
String info = "";
|
||||
@ -324,9 +324,9 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks id field value is an integer and saves it
|
||||
* @param fieldName name of field to be saved
|
||||
* @return value form field
|
||||
* Checks id field value is an integer and saves it
|
||||
*/
|
||||
private String getFieldIntegerInfo(String fieldName) {
|
||||
String info = "";
|
||||
@ -344,10 +344,10 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves true/false value as text
|
||||
* @param trueLabel is name of true button
|
||||
* @param falseLabel is name of false button
|
||||
* @return text representation
|
||||
* Saves true/false value as text
|
||||
*/
|
||||
private String getTrueFalseInfo(String trueLabel, String falseLabel) {
|
||||
String info = "";
|
||||
@ -365,8 +365,8 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return text representation of direction
|
||||
* Saves direction info as text
|
||||
* @return text representation of direction
|
||||
*/
|
||||
private String getDirectionInfo() {
|
||||
String info = "";
|
||||
@ -392,9 +392,9 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes type of cell based on direction value
|
||||
* @param type type of cell
|
||||
* @return changed type of cell
|
||||
* Changes type of cell based on direction value
|
||||
*/
|
||||
private String getDoorInfo(String type) {
|
||||
String info = "";
|
||||
@ -408,8 +408,8 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return text representation
|
||||
* Saves if door is supposed to be locked
|
||||
* @return text representation
|
||||
*/
|
||||
private String getLockedInfo() {
|
||||
String info = "";
|
||||
@ -471,8 +471,8 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value is text true/false value
|
||||
* Parses value and checks corresponding button
|
||||
* @param value is text true/false value
|
||||
*/
|
||||
private void setTrueFalseInfo(String value) {
|
||||
if (value.equals("false")) {
|
||||
@ -502,8 +502,8 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value is text half-block value
|
||||
* Parses value and checks corresponding button
|
||||
* @param value is text half-block value
|
||||
*/
|
||||
private void setUpperLowerInfo(String value) {
|
||||
String name = "";
|
||||
@ -524,9 +524,9 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills a selected field with value
|
||||
* @param fieldName is name of field to be filled in
|
||||
* @param value is new value of field
|
||||
* Fills a selected field with value
|
||||
*/
|
||||
private void setFieldInfo(String fieldName, String value) {
|
||||
for (JTextField field : textFields) {
|
||||
@ -538,8 +538,8 @@ public class DetailedCellInfo extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value is text direction value
|
||||
* Parses value and checks corresponding button
|
||||
* @param value is text direction value
|
||||
*/
|
||||
private void setDirectionInfo(String value) {
|
||||
String name = "";
|
||||
|
||||
@ -32,8 +32,8 @@ public class EditorSaveManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return is tileset valid
|
||||
* Checks if a tileset exists and is not empty
|
||||
* @return is tileset valid
|
||||
*/
|
||||
public boolean validate() {
|
||||
boolean valid = editor.getImagesOfTiles() != null && editor.getImagesOfTiles().size() > 0;
|
||||
|
||||
@ -23,11 +23,11 @@ public class InfoManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides which type of info is needed for a selected cell
|
||||
* @param label is label to be parsed and displayed
|
||||
* @param layer is name of layer on which the cell is located
|
||||
* @param x is X value of cell
|
||||
* @param y is Y value of cell
|
||||
* Decides which type of info is needed for a selected cell
|
||||
*/
|
||||
protected void displayInfo(JLabel label, String layer, int x, int y) {
|
||||
if (info != null) {
|
||||
@ -62,11 +62,11 @@ public class InfoManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays info regarding object cells and tile cells
|
||||
* @param label is label to be parsed and displayed
|
||||
* @param x is X value of cell
|
||||
* @param y is Y value of cell
|
||||
* @param isObject is cell on object layer
|
||||
* Displays info regarding object cells and tile cells
|
||||
*/
|
||||
private void displayObjectAndTileInfo(JLabel label, int x, int y, boolean isObject) {
|
||||
JLabel infoLabel = new JLabel();
|
||||
@ -176,10 +176,10 @@ public class InfoManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays info regarding 'physical' cells (from mapArray)
|
||||
* @param label is label to be parsed and displayed
|
||||
* @param x is X value of cell
|
||||
* @param y is Y value of cell
|
||||
* Displays info regarding 'physical' cells (from mapArray)
|
||||
*/
|
||||
private void displayCellInfo(JLabel label, int x, int y) {
|
||||
String[] array = {"EMPTY", "BLOCK", "INTER", "TRIGGER", "MOVETO", "DOOR", "DOORTO", "CHEST"};
|
||||
@ -264,10 +264,10 @@ public class InfoManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts DOOR cell into correct places in map's cell matrix
|
||||
* @param value is value of cell to ba parsed
|
||||
* @param x is X value of cell
|
||||
* @param y is Y value of cell
|
||||
* Puts DOOR cell into correct places in map's cell matrix
|
||||
*/
|
||||
private void saveDoor(String value, int x, int y) {
|
||||
if (value.split(",")[0].contains("DOOR") && y == 0) {
|
||||
|
||||
@ -128,10 +128,10 @@ public class LevelEditor extends JFrame {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new map and populates it's cell matrix and passes it on
|
||||
* @param name is name of new map
|
||||
* @param width is width of new map
|
||||
* @param height is height of new map
|
||||
* Creates new map and populates it's cell matrix and passes it on
|
||||
*/
|
||||
public void createNewMap(String name, int width, int height) {
|
||||
TypeOfCell[][] mapArray = new TypeOfCell[width][height];
|
||||
@ -316,8 +316,8 @@ public class LevelEditor extends JFrame {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message is text to be displayed
|
||||
* Displays message as an error in the error field
|
||||
* @param message is text to be displayed
|
||||
*/
|
||||
protected void displayError(String message) {
|
||||
errorMessage.setText("<html><span style='color: red'>" + message + "</span></html>");
|
||||
@ -325,8 +325,8 @@ public class LevelEditor extends JFrame {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message is text to be displayed
|
||||
* Displays message as a normal text in the error field
|
||||
* @param message is text to be displayed
|
||||
*/
|
||||
protected void displayMessage(String message) {
|
||||
errorMessage.setText(message);
|
||||
|
||||
@ -184,10 +184,10 @@ public class MapLayersManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets cell a corresponding icon from cellMap dictionary
|
||||
* @param cell is cell to ba updated
|
||||
* @param i is cell's Y value
|
||||
* @param j is cell's X value
|
||||
* Sets cell a corresponding icon from cellMap dictionary
|
||||
*/
|
||||
private void setCellIcon(JLabel cell, int i, int j) {
|
||||
String value;
|
||||
@ -220,9 +220,9 @@ public class MapLayersManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts image to buffered image
|
||||
* @param img is image to be converted
|
||||
* @return converted image
|
||||
* Converts image to buffered image
|
||||
*/
|
||||
private BufferedImage toBufferedImage(Image img) {
|
||||
BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
|
||||
@ -233,10 +233,10 @@ public class MapLayersManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts regulat image (50x50px) to a half block (upper or lower)
|
||||
* @param img is image to be tilified
|
||||
* @param isUp is an upper block
|
||||
* @return tilified image
|
||||
* Converts regulat image (50x50px) to a half block (upper or lower)
|
||||
*/
|
||||
private BufferedImage tilify(BufferedImage img, boolean isUp) {
|
||||
BufferedImage image = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
|
||||
@ -248,9 +248,9 @@ public class MapLayersManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets corresponding image to a door cell (and one cell above/lower)
|
||||
* @param cell is cell to be updated
|
||||
* @param info cell text value
|
||||
* Sets corresponding image to a door cell (and one cell above/lower)
|
||||
*/
|
||||
private void setDoorImage(JLabel cell, String[] info) {
|
||||
if (editor.getCellMap().get("DOOR/DOORTO") == 0) {
|
||||
|
||||
@ -34,8 +34,8 @@ public class TilesetOverview extends JFrame {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param folder is folder with tileset images
|
||||
* Displays menu all possible images to be parsed into tileset
|
||||
* @param folder is folder with tileset images
|
||||
*/
|
||||
public void listFilesForFolder(File folder) {
|
||||
activeTilesets = new LinkedList<>();
|
||||
@ -79,8 +79,8 @@ public class TilesetOverview extends JFrame {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name is image name
|
||||
* Displays name of file with a designated checkbox
|
||||
* @param name is image name
|
||||
*/
|
||||
private void loadTileset(String name) {
|
||||
JLabel text = new JLabel(name);
|
||||
|
||||
@ -51,10 +51,10 @@ public class Map {
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds map by name in a list of loaded maps
|
||||
* @param nameOfMap is map name that is being searched for
|
||||
* @param window is reference for WindowOfFreeMove
|
||||
* @return found map
|
||||
* Finds map by name in a list of loaded maps
|
||||
*/
|
||||
public static Map findMapByName(String nameOfMap, WindowOfFreeMove window) {
|
||||
LinkedList<Map> mapLinkedList = window.getMapLinkedList();
|
||||
@ -66,10 +66,10 @@ public class Map {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates map and prepares all fields, then passes map on loadMap
|
||||
* @param name is map file name
|
||||
* @param window is reference for WindowOfFreeMove
|
||||
* @return loaded map
|
||||
* Creates map and prepares all fields, then passes map on loadMap
|
||||
*/
|
||||
public static Map loadMapFromFile(String name, WindowOfFreeMove window) {
|
||||
try {
|
||||
@ -99,12 +99,12 @@ public class Map {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses line of text into corresponding cells with attributes and populates corresponding lists wit them
|
||||
* @param map is map being loaded
|
||||
* @param data is line of map file to be parsed
|
||||
* @param size is array of map's size in cells
|
||||
* @param y is current Y value of line being parsed
|
||||
* @param window is reference for WindowOfFreeMove
|
||||
* Parses line of text into corresponding cells with attributes and populates corresponding lists wit them
|
||||
*/
|
||||
public static void loadMap(Map map, String data, String[] size, int y, WindowOfFreeMove window) {
|
||||
String[] line = data.split(" ");
|
||||
@ -161,9 +161,9 @@ public class Map {
|
||||
|
||||
|
||||
/**
|
||||
* Parses MOVETO and DOORTO cells, which link different maps together
|
||||
* @param map is map being linked
|
||||
* @param window is reference on WindowOfFreeMove
|
||||
* Parses MOVETO and DOORTO cells, which link different maps together
|
||||
*/
|
||||
public void linkMaps(Map map, WindowOfFreeMove window) {
|
||||
try {
|
||||
@ -204,8 +204,8 @@ public class Map {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param moveToCell is MOVETO cell being added
|
||||
* Updates map's cell matrix and adds cell to corresponding list
|
||||
* @param moveToCell is MOVETO cell being added
|
||||
*/
|
||||
public void addMoveToEvent(EventMoveToCell moveToCell) {
|
||||
mapArray[moveToCell.getX()][moveToCell.getY()] = TypeOfCell.MOVETO;
|
||||
@ -213,8 +213,8 @@ public class Map {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param interactionCell is INTER cell being added
|
||||
* Updates map's cell matrix and adds cell to corresponding list
|
||||
* @param interactionCell is INTER cell being added
|
||||
*/
|
||||
public void addInteractionEvent(InteractionCell interactionCell) {
|
||||
mapArray[interactionCell.getX()][interactionCell.getY()] = TypeOfCell.EVENT;
|
||||
@ -222,8 +222,8 @@ public class Map {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param triggerCell is TRIGGER cell being added
|
||||
* Updates map's cell matrix and adds cell to corresponding list
|
||||
* @param triggerCell is TRIGGER cell being added
|
||||
*/
|
||||
public void addInteractionEvent(TriggerCell triggerCell) {
|
||||
mapArray[triggerCell.getX()][triggerCell.getY()] = TypeOfCell.EVENT;
|
||||
@ -231,8 +231,8 @@ public class Map {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param doorCell is DOOR(TO) cell being added
|
||||
* Updates map's cell matrix and adds cell to corresponding list
|
||||
* @param doorCell is DOOR(TO) cell being added
|
||||
*/
|
||||
public void addInteractionEvent(DoorCell doorCell) {
|
||||
mapArray[doorCell.getX()][doorCell.getY()] = TypeOfCell.EVENT;
|
||||
@ -240,8 +240,8 @@ public class Map {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chestCell is CHEST cell being added
|
||||
* Updates map's cell matrix and adds cell to corresponding list
|
||||
* @param chestCell is CHEST cell being added
|
||||
*/
|
||||
public void addInteractionEvent(ChestCell chestCell) {
|
||||
mapArray[chestCell.getX()][chestCell.getY()] = TypeOfCell.EVENT;
|
||||
@ -489,11 +489,11 @@ public class Map {
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates direction of sight into new coords
|
||||
* @param x is starting X value
|
||||
* @param y is starting Y value
|
||||
* @param directionSight is direction of hero's sight
|
||||
* @return array of new X & Y coordinates
|
||||
* Translates direction of sight into new coords
|
||||
*/
|
||||
public int[] directionSightSwitch(int x, int y, int directionSight) {
|
||||
switch (directionSight) {
|
||||
|
||||
@ -32,8 +32,8 @@ public class MapManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param map is map to be set
|
||||
* Sets map as the one that is currently used, if that map is not present in map list, the map is added
|
||||
* @param map is map to be set
|
||||
*/
|
||||
public void setMap(Map map) {
|
||||
if (maps.contains(map)) {
|
||||
@ -131,8 +131,8 @@ public class MapManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param size is array of new sizes for canvas
|
||||
* Sets canvas size based on current map
|
||||
* @param size is array of new sizes for canvas
|
||||
*/
|
||||
public void resizeCanvas(int[] size) {
|
||||
canvas.setPreferredSize(new Dimension(
|
||||
|
||||
@ -31,8 +31,8 @@ public class LoadManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return are save files empty
|
||||
* Checks if save files are empty (if there is no saved progress)
|
||||
* @return are save files empty
|
||||
*/
|
||||
public static boolean isSaveEmpty() {
|
||||
File personFile = new File("src/main/resources/save/savedGame/person.txt");
|
||||
|
||||
@ -20,12 +20,12 @@ public class PathFinder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds path with A* algorithm and translates it to directions using Direction enumeration
|
||||
* @param startX is starting X value
|
||||
* @param startY is starting Y value
|
||||
* @param endX is ending X value
|
||||
* @param endY is ending Y value
|
||||
* @return list of directions for NPC
|
||||
* Finds path with A* algorithm and translates it to directions using Direction enumeration
|
||||
*/
|
||||
public LinkedList<Direction> getWayWithCollision(int startX, int startY, int endX, int endY) {
|
||||
AStar aStar = new AStar(map.getMapArray().length, map.getMapArray()[0].length, new Node(startX, startY), new Node(endX, endY));
|
||||
|
||||
@ -19,8 +19,8 @@ public class TextParser {
|
||||
private String action;
|
||||
|
||||
/**
|
||||
* @param text is input from player
|
||||
* Separates incoming text into parts and passes them on to be parsed further
|
||||
* @param text is input from player
|
||||
*/
|
||||
public void parseBattleText(String text) {
|
||||
textToParse = text;
|
||||
@ -33,8 +33,8 @@ public class TextParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param personText is name of battle person
|
||||
* Finds battle person based on text input and sets it as actor of action
|
||||
* @param personText is name of battle person
|
||||
*/
|
||||
private void parseBattlePerson(String personText) {
|
||||
switch (personText) {
|
||||
@ -51,8 +51,8 @@ public class TextParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param action is name of action
|
||||
* Calls corresponding action to user input
|
||||
* @param action is name of action
|
||||
*/
|
||||
private void parseBattleAction(String action) {
|
||||
this.action = action;
|
||||
@ -87,8 +87,8 @@ public class TextParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param targetText name of battle person
|
||||
* Finds battle person based on text input and sets it as target of action
|
||||
* @param targetText name of battle person
|
||||
*/
|
||||
private void parseBattleTarget(String targetText) {
|
||||
switch (targetText) {
|
||||
|
||||
@ -63,8 +63,8 @@ public class MusicManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param delay is timer delay in milliseconds
|
||||
* Fades music in (slowly raises volume to maxVolume)
|
||||
* @param delay is timer delay in milliseconds
|
||||
*/
|
||||
public void fadeIn(int delay) {
|
||||
timerIn = new Timer(delay, actionEvent -> {
|
||||
@ -77,8 +77,8 @@ public class MusicManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param delay is timer delay in milliseconds
|
||||
* Fades music out (slowly lowers volume to 'zero')
|
||||
* @param delay is timer delay in milliseconds
|
||||
*/
|
||||
public void fadeOut(int delay) {
|
||||
timerOut = new Timer(delay, actionEvent -> {
|
||||
|
||||
@ -23,8 +23,8 @@ public class SoundManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param file is name of file
|
||||
* Parses sound map for different entities (currently only for doors)
|
||||
* @param file is name of file
|
||||
*/
|
||||
public void loadSoundMap(String file) {
|
||||
try {
|
||||
@ -50,9 +50,9 @@ public class SoundManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays sound once
|
||||
* @param name is sound name
|
||||
* @param volume is designated volume os float
|
||||
* Plays sound once
|
||||
*/
|
||||
public void playSound(String name, float volume){
|
||||
AudioInputStream audioIn;
|
||||
@ -73,10 +73,10 @@ public class SoundManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays sound repeatedly after delay
|
||||
* @param name is sound name
|
||||
* @param delay is timer delay in milliseconds
|
||||
* @param volume is designated volume as float
|
||||
* Plays sound repeatedly after delay
|
||||
*/
|
||||
public void playSoundRepeatedly(String name, int delay, float volume) {
|
||||
if (this.delay == delay) {
|
||||
|
||||
@ -123,8 +123,8 @@ public class WindowOfBattle extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name is battle file name
|
||||
* Starts battle sequence - parses actors & other assets
|
||||
* @param name is battle file name
|
||||
*/
|
||||
public void start(String name) {
|
||||
LinkedList<Hero> heroes = new LinkedList<>();
|
||||
@ -196,8 +196,8 @@ public class WindowOfBattle extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param s is text to be displayed
|
||||
* Displays text in situationText field
|
||||
* @param s is text to be displayed
|
||||
*/
|
||||
public void writeToOutput(String s) {
|
||||
Font f = new Font(Font.SERIF, Font.BOLD, 20);
|
||||
@ -212,9 +212,9 @@ public class WindowOfBattle extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Styles button
|
||||
* @param button is button to be styled
|
||||
* @return styled button
|
||||
* Styles button
|
||||
*/
|
||||
public JButton style(JButton button) {
|
||||
Font f = new Font(Font.SERIF, Font.BOLD, 16);
|
||||
@ -267,8 +267,8 @@ public class WindowOfBattle extends JPanel {
|
||||
private Timer timer;
|
||||
|
||||
/**
|
||||
* @param name is image name
|
||||
* Adds image into list of images to be displayed & sets it as the current image
|
||||
* @param name is image name
|
||||
*/
|
||||
public void addImage(String name) {
|
||||
try {
|
||||
@ -288,8 +288,8 @@ public class WindowOfBattle extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param delay is timer delay in miliseconds
|
||||
* Selects random inmage from list of images to be displayed -creates flickering effect
|
||||
* @param delay is timer delay in miliseconds
|
||||
*/
|
||||
public void flicker(int delay) {
|
||||
timer = new Timer(delay, actionEvent -> {
|
||||
|
||||
@ -27,6 +27,7 @@ public class WindowOfFreeMove extends JLayeredPane {
|
||||
public static int CANVAS_HEIGHT = 50;
|
||||
public static final int WINDOW_WIDTH = 13;
|
||||
public static final int WINDOW_HEIGHT = 13;
|
||||
public static final int REPAINT_DELAY = 20;
|
||||
|
||||
private static boolean canPersonMove;
|
||||
private static int nextMove;
|
||||
@ -181,8 +182,8 @@ public class WindowOfFreeMove extends JLayeredPane {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newGame is a reference to main class Game
|
||||
* Starts the game itself - loads all needed maps, starts a new game or loads saved game and starts timer for repainting
|
||||
* @param newGame is a reference to main class Game
|
||||
*/
|
||||
public void start(boolean newGame) {
|
||||
centerContent();
|
||||
@ -207,7 +208,7 @@ public class WindowOfFreeMove extends JLayeredPane {
|
||||
mapManager.createMap();
|
||||
isReadyToPaint = true;
|
||||
|
||||
Timer timer = new Timer(20, actionEvent -> {
|
||||
Timer timer = new Timer(REPAINT_DELAY, actionEvent -> {
|
||||
mapManager.getActualMap().getPerson().move();
|
||||
camera.moveCamera();
|
||||
canvas.repaint();
|
||||
@ -232,8 +233,8 @@ public class WindowOfFreeMove extends JLayeredPane {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name is name of battle file
|
||||
* Starts new battle sequence
|
||||
* @param name is name of battle file
|
||||
*/
|
||||
public void startBattle(String name) {
|
||||
setVisible(false);
|
||||
@ -291,9 +292,9 @@ public class WindowOfFreeMove extends JLayeredPane {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a cell is being shown in window and has to be repainted
|
||||
* @param cell is cell to be validated
|
||||
* @return is cell in view or near view
|
||||
* Checks if a cell is being shown in window and has to be repainted
|
||||
*/
|
||||
private boolean isinView(Cell cell) {
|
||||
Boolean xValue = (CELL_SIZE * (cell.getX()+1) > -canvas.getLocation().x) && (CELL_SIZE * (cell.getX()-1) < (-canvas.getLocation().x + CELL_SIZE * WINDOW_WIDTH));
|
||||
@ -302,10 +303,10 @@ public class WindowOfFreeMove extends JLayeredPane {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a cell (referenced by X & Y) is being shown in window and has to be repainted
|
||||
* @param x is X value of a cell
|
||||
* @param y is Y value of a cell
|
||||
* @return is cell (referenced by X & Y) in view or near view
|
||||
* Checks if a cell (referenced by X & Y) is being shown in window and has to be repainted
|
||||
*/
|
||||
private boolean isinView(int x, int y) {
|
||||
Boolean xValue = (CELL_SIZE * (x+1) > -canvas.getLocation().x) && (CELL_SIZE * (x-1) < (-canvas.getLocation().x + CELL_SIZE * WINDOW_WIDTH));
|
||||
@ -342,10 +343,10 @@ public class WindowOfFreeMove extends JLayeredPane {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gradually changes alpha value of a displayed color
|
||||
* @param startAlpha is starting alpha value
|
||||
* @param endAlpha is ending alpha value
|
||||
* @param delay is delay for timer
|
||||
* Gradually changes alpha value of a displayed color
|
||||
*/
|
||||
public void fade(int startAlpha, int endAlpha, int delay) {
|
||||
a = startAlpha;
|
||||
@ -375,8 +376,8 @@ public class WindowOfFreeMove extends JLayeredPane {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tm is time in milliseconds
|
||||
* Pauses thread for a designated length of time
|
||||
* @param tm is time in milliseconds
|
||||
*/
|
||||
public static void sleep(long tm) {
|
||||
try {
|
||||
|
||||
@ -1,164 +1,15 @@
|
||||
<map>
|
||||
<mapName>tutorial</mapName>
|
||||
<mapName>m1</mapName>
|
||||
<events>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>m6</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>11</x>
|
||||
<y>6</y>
|
||||
<y>11</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>
|
||||
<door>
|
||||
<x>8</x>
|
||||
<y>4</y>
|
||||
<locked>false</locked>
|
||||
<open>false</open>
|
||||
</dooŕ>
|
||||
<door>
|
||||
<x>2</x>
|
||||
<y>6</y>
|
||||
<locked>true</locked>
|
||||
<open>false</open>
|
||||
</dooŕ>
|
||||
<door>
|
||||
<x>6</x>
|
||||
<y>6</y>
|
||||
<locked>false</locked>
|
||||
<open>false</open>
|
||||
</dooŕ>
|
||||
<door>
|
||||
<x>16</x>
|
||||
<y>10</y>
|
||||
<locked>true</locked>
|
||||
<open>false</open>
|
||||
</dooŕ>
|
||||
<door>
|
||||
<x>8</x>
|
||||
<y>13</y>
|
||||
<locked>false</locked>
|
||||
<open>false</open>
|
||||
</dooŕ>
|
||||
</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>
|
||||
<door>
|
||||
<x>12</x>
|
||||
<y>1</y>
|
||||
<locked>true</locked>
|
||||
<open>false</open>
|
||||
</dooŕ>
|
||||
<door>
|
||||
<x>17</x>
|
||||
<y>1</y>
|
||||
<locked>true</locked>
|
||||
<open>false</open>
|
||||
</dooŕ>
|
||||
<door>
|
||||
<x>7</x>
|
||||
<y>12</y>
|
||||
<locked>true</locked>
|
||||
<open>false</open>
|
||||
</dooŕ>
|
||||
<door>
|
||||
<x>12</x>
|
||||
<y>12</y>
|
||||
<locked>true</locked>
|
||||
<open>false</open>
|
||||
</dooŕ>
|
||||
<door>
|
||||
<x>4</x>
|
||||
<y>1</y>
|
||||
<locked>false</locked>
|
||||
<open>false</open>
|
||||
</dooŕ>
|
||||
<door>
|
||||
<x>2</x>
|
||||
<y>12</y>
|
||||
<locked>false</locked>
|
||||
<open>true</open>
|
||||
</dooŕ>
|
||||
<door>
|
||||
<x>17</x>
|
||||
<y>12</y>
|
||||
<locked>true</locked>
|
||||
<open>false</open>
|
||||
</dooŕ>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>boss</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>4</x>
|
||||
<y>18</y>
|
||||
<active>true</active>
|
||||
</trigger>
|
||||
<door>
|
||||
<x>4</x>
|
||||
<y>19</y>
|
||||
<locked>false</locked>
|
||||
<open>false</open>
|
||||
</dooŕ>
|
||||
</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>
|
||||
<door>
|
||||
<x>6</x>
|
||||
<y>1</y>
|
||||
<locked>false</locked>
|
||||
<open>true</open>
|
||||
</dooŕ>
|
||||
</events>
|
||||
</map>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<location>
|
||||
<map>storageroom</map>
|
||||
<x>6</x>
|
||||
<y>2</y>
|
||||
<direction>0</direction>
|
||||
<map>m1</map>
|
||||
<x>3</x>
|
||||
<y>7</y>
|
||||
<direction>2</direction>
|
||||
</location>
|
||||
@ -78,7 +78,7 @@ public class WindowOfFreeMoveTest {
|
||||
|
||||
//Act
|
||||
final int[] i = {0};
|
||||
timer = new Timer(10, actionEvent -> {
|
||||
timer = new Timer(20, actionEvent -> {
|
||||
if (!person.getIsMoving()) {
|
||||
if (i[0] == directions.length) {
|
||||
stopTimer();
|
||||
@ -114,10 +114,11 @@ public class WindowOfFreeMoveTest {
|
||||
public void moveToMap_CharacterMovesToDifferentMap_CharacterIsOnCorrectMap() {
|
||||
//Arrange
|
||||
int[] directions = {KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN};
|
||||
freeMove.revalidate();
|
||||
|
||||
//Act
|
||||
final int[] i = {0};
|
||||
timer = new Timer(10, actionEvent -> {
|
||||
timer = new Timer(WindowOfFreeMove.REPAINT_DELAY, actionEvent -> {
|
||||
if (!person.getIsMoving()) {
|
||||
if (i[0] == directions.length) {
|
||||
stopTimer();
|
||||
@ -141,7 +142,7 @@ public class WindowOfFreeMoveTest {
|
||||
|
||||
//Act
|
||||
final boolean[] flag = {false};
|
||||
timer = new Timer(10, actionEvent -> {
|
||||
timer = new Timer(WindowOfFreeMove.REPAINT_DELAY, actionEvent -> {
|
||||
if (!freeMove.getMapManager().getActualMap().getPerson().getIsMoving() && WindowOfFreeMove.canPersonMove()) {
|
||||
if (!flag[0]) {
|
||||
freeMove.getMapManager().getActualMap().getPerson().setDirectionMove(KEY_DOWN);
|
||||
@ -169,10 +170,11 @@ public class WindowOfFreeMoveTest {
|
||||
public void startEvent_CharacterEntersEventThenGoesThroughEventThenExitsEvent_CorrectCharacterResponses() {
|
||||
//Arrange
|
||||
int[] directions = {KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP, KEY_UP};
|
||||
freeMove.revalidate();
|
||||
|
||||
//Act
|
||||
final int[] i = {0};
|
||||
timer = new Timer(10, actionEvent -> {
|
||||
timer = new Timer(WindowOfFreeMove.REPAINT_DELAY, actionEvent -> {
|
||||
if (!person.getIsMoving()) {
|
||||
if (i[0] == directions.length) {
|
||||
stopTimer();
|
||||
@ -223,7 +225,7 @@ public class WindowOfFreeMoveTest {
|
||||
}
|
||||
|
||||
final boolean[] flag = {false};
|
||||
timer = new Timer(10, actionEvent -> {
|
||||
timer = new Timer(WindowOfFreeMove.REPAINT_DELAY, actionEvent -> {
|
||||
if (!person.getIsMoving()) {
|
||||
if (!flag[0]) {
|
||||
person.setDirectionMove(KEY_LEFT);
|
||||
@ -252,6 +254,7 @@ public class WindowOfFreeMoveTest {
|
||||
public void saveGame_CharacterInteractsWithTriggerCellThenMovesToDifferentMapThenGameIsSaved_CorrectlySavedProgress() {
|
||||
//Assert
|
||||
SaveManager saveManager;
|
||||
freeMove.revalidate();
|
||||
|
||||
//Act
|
||||
startEvent_CharacterEntersEventThenGoesThroughEventThenExitsEvent_CorrectCharacterResponses();
|
||||
@ -259,7 +262,7 @@ public class WindowOfFreeMoveTest {
|
||||
int[] directions = {KEY_RIGHT, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN, KEY_DOWN};
|
||||
|
||||
final int[] i = {0};
|
||||
timer = new Timer(10, actionEvent -> {
|
||||
timer = new Timer(WindowOfFreeMove.REPAINT_DELAY, actionEvent -> {
|
||||
if (!person.getIsMoving()) {
|
||||
if (i[0] == directions.length) {
|
||||
stopTimer();
|
||||
@ -279,7 +282,7 @@ public class WindowOfFreeMoveTest {
|
||||
moveToMap_CharacterMovesToDifferentMap_CharacterIsOnCorrectMap();
|
||||
|
||||
final boolean[] flag = {false};
|
||||
timer = new Timer(10, actionEvent -> {
|
||||
timer = new Timer(WindowOfFreeMove.REPAINT_DELAY, actionEvent -> {
|
||||
if (!freeMove.getMapManager().getActualMap().getPerson().getIsMoving() && WindowOfFreeMove.canPersonMove()) {
|
||||
if (!flag[0]) {
|
||||
freeMove.getMapManager().getActualMap().getPerson().setDirectionMove(KEY_DOWN);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user