diff --git a/.gitignore b/.gitignore index 643d32d..533eadd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,15 @@ .idea /target +BattleLog.log +BattleLog.log.lck +doorimage.log +doorimage.log.lck +imagecell.log +imagecell.log.lck +imageperson.log +imageperson.log.lck +imagedialog.log +imagedialog.log.lck +gameOfProd.iml +Game_of_Prod.zip diff --git a/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java b/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java index a3096d3..f49b1be 100644 --- a/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java +++ b/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java @@ -2,6 +2,8 @@ package ruscz.game.gameOfProd.Battle; import ruscz.game.gameOfProd.Cells.InteractionCell; import ruscz.game.gameOfProd.Dialog.Dialog; +import ruscz.game.gameOfProd.Image.ImageCell; +import ruscz.game.gameOfProd.Scripts.Utils; import ruscz.game.gameOfProd.Sounds.SoundManager; import ruscz.game.gameOfProd.Windows.WindowOfBattle; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; @@ -11,6 +13,7 @@ import java.awt.*; import java.util.Collections; import java.util.LinkedList; import java.util.Random; +import java.util.logging.Logger; /** * Class for Battle with graphic implementation @@ -28,10 +31,12 @@ public class Battle { private boolean playerAttack; private boolean timerStopped; + private static final Logger LOG = Utils.setSettingsToLogger(Logger.getLogger(Battle.class.getName()), "BattleLog"); + /** * Hide Menu and Enemy Description * Set Attack of Player - * @param playerAttack + * @param playerAttack true if attacks */ public void setPlayerAttack(boolean playerAttack) { windowOfBattle.getMenuOfActions().setVisible(false); @@ -127,6 +132,7 @@ public class Battle { windowOfBattle.getGame().remove(windowOfBattle); if (windowOfBattle.getMusicManager() != null) windowOfBattle.getMusicManager().stopMusic(); } + LOG.fine("End of Battle"); // SaveManager saveManager = game.getFreeMove().getMapManager().getSaveManager(); // saveManager.saveGame(); } @@ -141,6 +147,8 @@ public class Battle { for (Component e: windowOfBattle.getMenuOfActions().getComponents()) e.setEnabled(true); windowOfBattle.getEnemyDescription().updateDescription(); windowOfBattle.getSituationText().hideText(); + + LOG.fine("Control returned to player"); } /** @@ -154,6 +162,7 @@ public class Battle { turnBelongTo.setImageEffect("attack"); if (windowOfBattle.getHitSound() != null) soundManager.playSound(windowOfBattle.getHitSound(), -10.0f); windowOfBattle.writeToOutput(turnBelongTo.getName() + " deals " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " damage to " + e.getName()+"!"); + LOG.fine(turnBelongTo.getName() + " deals " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " damage to " + e.getName()+"! HERO"); if (e.health <= 0) { if (e.getImage()!= null) e.getKilled(this); else enemies.remove(e); @@ -189,6 +198,8 @@ public class Battle { Collections.shuffle(turns); turnBelongTo = turns.getFirst(); } + + LOG.fine("Next Person to Attack is " + turnBelongTo); } /** @@ -202,6 +213,7 @@ public class Battle { if (windowOfBattle.getHitSound() != null) soundManager.playSound(windowOfBattle.getHitSound(), -10.0f); windowOfBattle.writeToOutput(turnBelongTo.getName() + " deals " + turnBelongTo.getLevel() + " damage to " + e.getName()+"!"); + LOG.fine(turnBelongTo.getName() + " deals " + turnBelongTo.getLevel() + " damage to " + e.getName()+"! MONSTER"); if (e.health <= 0) { if (e.getImage()!= null) e.getKilled(this); else heroes.remove(e); @@ -252,6 +264,7 @@ public class Battle { * @param person Person to delete */ public void removePersonFromList(BattlePerson person) { + LOG.fine("Removing " + person); if (person.getClass().getName().equals("ruscz.game.gameOfProd.Battle.Hero")) heroes.remove(person); else enemies.remove(person); } diff --git a/src/main/java/ruscz/game/gameOfProd/Battle/BattlePerson.java b/src/main/java/ruscz/game/gameOfProd/Battle/BattlePerson.java index 8b8be6d..414489c 100644 --- a/src/main/java/ruscz/game/gameOfProd/Battle/BattlePerson.java +++ b/src/main/java/ruscz/game/gameOfProd/Battle/BattlePerson.java @@ -268,4 +268,15 @@ public abstract class BattlePerson { public int getMaxHealth() { return maxHealth; } + + @Override + public String toString() { + return "BattlePerson{" + + "maxHealth=" + maxHealth + + ", health=" + health + + ", level=" + level + + ", name='" + name + '\'' + + ", strength=" + strength + + '}'; + } } diff --git a/src/main/java/ruscz/game/gameOfProd/BattleUI/ItemsInventory.java b/src/main/java/ruscz/game/gameOfProd/BattleUI/ItemsInventory.java index 0d04499..544354e 100644 --- a/src/main/java/ruscz/game/gameOfProd/BattleUI/ItemsInventory.java +++ b/src/main/java/ruscz/game/gameOfProd/BattleUI/ItemsInventory.java @@ -1,14 +1,17 @@ package ruscz.game.gameOfProd.BattleUI; +import ruscz.game.gameOfProd.Battle.Battle; import ruscz.game.gameOfProd.Image.ImageCell; import ruscz.game.gameOfProd.Inventory.InventoryManager; import ruscz.game.gameOfProd.Inventory.Item; import ruscz.game.gameOfProd.Inventory.ItemAction; import ruscz.game.gameOfProd.Inventory.ItemPanel; +import ruscz.game.gameOfProd.Scripts.Utils; import ruscz.game.gameOfProd.Windows.WindowOfBattle; import javax.swing.*; import java.awt.*; +import java.util.logging.Logger; import static ruscz.game.gameOfProd.Windows.WindowOfBattle.CELL_SIZE; @@ -20,6 +23,8 @@ public class ItemsInventory extends JPanel { private final ImageCell imageCell; private final WindowOfBattle windowOfBattle; + private static final Logger LOG = Utils.setSettingsToLogger(Logger.getLogger(Battle.class.getName()), "BattleLog"); + public ItemsInventory(WindowOfBattle window){ imageCell = new ImageCell(); imageCell.imageItem("TransparentIcons.png"); @@ -75,8 +80,14 @@ public class ItemsInventory extends JPanel { windowOfBattle.getMenuOfActions().setVisible(false); windowOfBattle.getEnemyDescription().setVisible(false); windowOfBattle.getSituationText().setVisible(true); + + int realHeal = windowOfBattle.getBattle().getHeroes().getFirst().heal(100); + windowOfBattle.writeToOutput(windowOfBattle.getBattle().getHeroes().getFirst().getName() + " heals " - + windowOfBattle.getBattle().getHeroes().getFirst().heal(100) + " HP"); + + realHeal + " HP"); + LOG.fine(windowOfBattle.getBattle().getHeroes().getFirst().getName() + " heals " + + realHeal + " HP"); + InventoryManager.removeItem(item, 1); windowOfBattle.getBattle().addToTurnOrder(windowOfBattle.getBattle().getHeroes().getFirst()); windowOfBattle.getBattle().setTurnBelongTo(null); diff --git a/src/main/java/ruscz/game/gameOfProd/BattleUI/MenuOfActions.java b/src/main/java/ruscz/game/gameOfProd/BattleUI/MenuOfActions.java index 7836a07..4b46ddf 100644 --- a/src/main/java/ruscz/game/gameOfProd/BattleUI/MenuOfActions.java +++ b/src/main/java/ruscz/game/gameOfProd/BattleUI/MenuOfActions.java @@ -1,10 +1,13 @@ package ruscz.game.gameOfProd.BattleUI; +import ruscz.game.gameOfProd.Battle.Battle; +import ruscz.game.gameOfProd.Scripts.Utils; import ruscz.game.gameOfProd.Windows.WindowOfBattle; import javax.swing.*; import java.awt.*; import java.util.Random; +import java.util.logging.Logger; import static ruscz.game.gameOfProd.Windows.WindowOfBattle.*; @@ -17,6 +20,8 @@ public class MenuOfActions extends JPanel { private final JButton inventory; private final JButton escape; + private static final Logger LOG = Utils.setSettingsToLogger(Logger.getLogger(Battle.class.getName()), "BattleLog"); + public MenuOfActions(WindowOfBattle window) { setLayout(new GridLayout(4,1)); @@ -66,13 +71,19 @@ public class MenuOfActions extends JPanel { escape.setEnabled(false); if (window.isRunAwayPossible()) { + LOG.fine("Try to escape"); + Random r = new Random(); - if (r.nextBoolean()) window.getBattle().endBattle(true); + if (r.nextBoolean()) { + window.getBattle().endBattle(true); + LOG.fine("RunAway is successful"); + } else { window.getMenuOfActions().setVisible(false); window.getEnemyDescription().setVisible(false); window.getSituationText().setVisible(true); window.writeToOutput("Runaway was not successful."); + LOG.fine("Runaway was not successful."); window.getBattle().addToTurnOrder(window.getBattle().getHeroes().getFirst()); window.getBattle().setTurnBelongTo(null); window.getBattle().setDelay(2); @@ -84,6 +95,7 @@ public class MenuOfActions extends JPanel { window.getEnemyDescription().setVisible(false); window.getSituationText().setVisible(true); window.writeToOutput("Runaway is not possible."); + LOG.fine("Runaway is not possible."); window.getBattle().addToTurnOrder(window.getBattle().getHeroes().getFirst()); window.getBattle().setTurnBelongTo(null); window.getBattle().setDelay(2); diff --git a/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java b/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java index 433d19c..e4c4f63 100644 --- a/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Image/ImageCell.java @@ -1,5 +1,6 @@ package ruscz.game.gameOfProd.Image; +import ruscz.game.gameOfProd.Scripts.Utils; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import javax.imageio.ImageIO; @@ -11,6 +12,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.LinkedList; import java.util.Scanner; +import java.util.logging.Logger; /** * This class manages and holds tileset and all matrices of images to be pained @@ -24,8 +26,10 @@ public class ImageCell { private int[][] mapBackground; private int[][] mapForeground; + private static final Logger LOG = Utils.setSettingsToLogger(Logger.getLogger(ImageCell.class.getName()), "imagecell"); + /** - * Creates new matrices based on winth and height values + * Creates new matrices based on width and height values * @param width is width of new map * @param height is height of new map */ @@ -68,8 +72,9 @@ public class ImageCell { } } imageObjectset(name); + LOG.fine("Map's tileset and objectset successfully parsed"); } catch (FileNotFoundException e) { - System.out.println("An error occurred."); + LOG.severe(name + "-tileset file doesn't exist in chapter " + WindowOfFreeMove.getCHAPTER()); e.printStackTrace(); } } @@ -82,6 +87,7 @@ public class ImageCell { try { image = ImageIO.read(new File("src/main/resources/tilesets/" + tilesetInfo[1])); } catch (IOException e) { + LOG.severe("Tileset image with name " + tilesetInfo[1] + " doesn't exist"); e.printStackTrace(); } @@ -96,7 +102,7 @@ public class ImageCell { int tiles = Xtiles * Ytiles; if (imagesOfTiles == null) - imagesOfTiles = new LinkedList(); + imagesOfTiles = new LinkedList<>(); Rectangle[] rectangles = new Rectangle[tiles]; int count = 0; @@ -110,6 +116,7 @@ public class ImageCell { for (int i = 0; i < tiles; i++) { imagesOfTiles.add(image.getSubimage(rectangles[i].x, rectangles[i].y, rectangles[i].height, rectangles[i].width)); } + LOG.fine("Map's tileset successfully parsed"); } /** @@ -128,7 +135,9 @@ public class ImageCell { } j++; } + LOG.fine("Map's objectset successfully parsed"); } catch (FileNotFoundException e) { + LOG.severe(file + "-objectset file doesn't exist in chapter " + WindowOfFreeMove.getCHAPTER()); e.printStackTrace(); } } @@ -155,6 +164,7 @@ public class ImageCell { } else cellMap.put(cellInfo[1], Integer.parseInt(cellInfo[2])); + LOG.fine("Map's cellset successfully parsed"); } /** @@ -171,6 +181,7 @@ public class ImageCell { imageHeight = image.getHeight(); size = 32; } catch (IOException e) { + LOG.severe("Item image with name " + itemInfo + " doesn't exist"); e.printStackTrace(); } @@ -187,6 +198,8 @@ public class ImageCell { imagesOfItems.add(img); } } + + LOG.fine("Image of Item successfully parsed"); } public LinkedList getImagesOfItems() { diff --git a/src/main/java/ruscz/game/gameOfProd/Image/ImageDialog.java b/src/main/java/ruscz/game/gameOfProd/Image/ImageDialog.java index e496e0e..84243a0 100644 --- a/src/main/java/ruscz/game/gameOfProd/Image/ImageDialog.java +++ b/src/main/java/ruscz/game/gameOfProd/Image/ImageDialog.java @@ -1,23 +1,28 @@ package ruscz.game.gameOfProd.Image; +import ruscz.game.gameOfProd.Scripts.Utils; + import javax.imageio.ImageIO; import java.awt.*; import java.io.File; import java.io.IOException; +import java.util.logging.Logger; /** * This class holds images to be painted in dialog */ public class ImageDialog { - private String name; + private final String name; private Image image; private static Image dialogBack; + private static final Logger LOG = Utils.setSettingsToLogger(Logger.getLogger(ImageDialog.class.getName()), "imagedialog"); + public Image getImage() { return image; } - public static Image getDialogBack() {return dialogBack;} + public static Image getDialogBack() { return dialogBack;} public ImageDialog(String name){ this.name = name; @@ -31,6 +36,7 @@ public class ImageDialog { try { dialogBack = ImageIO.read(new File("src/main/resources/dialogs/DialogBox.png")); } catch (IOException e) { + LOG.severe("Background for dialog doesn't exist"); e.printStackTrace(); } } @@ -42,6 +48,7 @@ public class ImageDialog { try { image = ImageIO.read(new File("src/main/resources/characters/" + name.substring(0, name.indexOf("-face.png")) + "/" + name)); } catch (IOException e) { + LOG.severe("Image for dialog (face expression) with name " + name + " doesn't exist"); e.printStackTrace(); } } diff --git a/src/main/java/ruscz/game/gameOfProd/Image/ImageDoor.java b/src/main/java/ruscz/game/gameOfProd/Image/ImageDoor.java index 443d5e4..44e7e6b 100644 --- a/src/main/java/ruscz/game/gameOfProd/Image/ImageDoor.java +++ b/src/main/java/ruscz/game/gameOfProd/Image/ImageDoor.java @@ -1,10 +1,13 @@ package ruscz.game.gameOfProd.Image; +import ruscz.game.gameOfProd.Scripts.Utils; + import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.util.logging.Logger; /** * This class images of doors to be painted @@ -14,6 +17,8 @@ public class ImageDoor { private BufferedImage[] imagesOfDoor; private int size; + private static final Logger LOG = Utils.setSettingsToLogger(Logger.getLogger(ImageDoor.class.getName()), "doorimage"); + /** * Parses images of door into an array * @param rectangles is array of door images @@ -28,6 +33,8 @@ public class ImageDoor { BufferedImage img = image.getSubimage(0, size * j * 2, size * 2, size * 2); imagesOfDoor[j] = img; } + + LOG.fine("All images for door successfully parsed"); } public ImageDoor(String door, Rectangle[] rectangles) { @@ -36,6 +43,7 @@ public class ImageDoor { image = ImageIO.read(new File("src/main/resources/tilesets/" + doorInfo[0])); size = Integer.parseInt(doorInfo[1]); } catch (IOException e) { + LOG.severe("Door image with name " + door.split(",")[0] + " doesn't exist"); e.printStackTrace(); } diff --git a/src/main/java/ruscz/game/gameOfProd/Image/ImagePerson.java b/src/main/java/ruscz/game/gameOfProd/Image/ImagePerson.java index 2e1084d..93f66a8 100644 --- a/src/main/java/ruscz/game/gameOfProd/Image/ImagePerson.java +++ b/src/main/java/ruscz/game/gameOfProd/Image/ImagePerson.java @@ -1,5 +1,6 @@ package ruscz.game.gameOfProd.Image; +import ruscz.game.gameOfProd.Scripts.Utils; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import javax.imageio.ImageIO; @@ -8,6 +9,7 @@ import java.awt.image.*; import java.io.File; import java.io.IOException; import java.util.Scanner; +import java.util.logging.Logger; /** * This class holds image of hero to be painted @@ -18,6 +20,9 @@ public class ImagePerson { private int subimageWidth; private int subimageHeight; + private static final Logger LOG = Utils.setSettingsToLogger(Logger.getLogger(ImagePerson.class.getName()), "imageperson"); + + /** * Parses images of hero into an array * @param rectangles is array of hero images @@ -36,6 +41,8 @@ public class ImagePerson { count++; } } + + LOG.fine("All Person Images parsed successfully"); } public ImagePerson(String name, Rectangle[] rectangles) { @@ -47,6 +54,7 @@ public class ImagePerson { subimageHeight = Integer.parseInt(subimageSize[1]); image = ImageIO.read(new File("src/main/resources/characters/main/" + scanner.nextLine())); } catch (IOException e) { + LOG.severe("Image or text description of Person " + name + " doesn't exist"); e.printStackTrace(); } diff --git a/src/main/java/ruscz/game/gameOfProd/Scripts/Utils.java b/src/main/java/ruscz/game/gameOfProd/Scripts/Utils.java new file mode 100644 index 0000000..0d68515 --- /dev/null +++ b/src/main/java/ruscz/game/gameOfProd/Scripts/Utils.java @@ -0,0 +1,20 @@ +package ruscz.game.gameOfProd.Scripts; + +import java.io.IOException; +import java.util.logging.*; + +public class Utils { + public static Logger setSettingsToLogger(Logger log, String nameOfLog) { + log.setUseParentHandlers(true); + + try { + log.addHandler(new FileHandler(nameOfLog + ".log")); + } catch (IOException e) { + e.printStackTrace(); + } + + log.setLevel(Level.ALL); + + return log; + } +} diff --git a/src/main/resources/save/savedGame/events.txt b/src/main/resources/save/savedGame/events.txt index 86e28da..bffc5e3 100644 --- a/src/main/resources/save/savedGame/events.txt +++ b/src/main/resources/save/savedGame/events.txt @@ -1,15 +1,164 @@ - m1 - - - - - m6 + tutorial 11 - 11 + 6 false + + openspace + + + 6 + 4 + true + + + 14 + 16 + false + + + 1 + 2 + true + + + 15 + 7 + true + + + 8 + 4 + false + false + + + 2 + 6 + true + false + + + 6 + 6 + false + false + + + 16 + 10 + true + false + + + 8 + 13 + false + false + + + + + office + + + 4 + 2 + false + + + 1 + 9 + true + + + 12 + 1 + true + false + + + 17 + 1 + true + false + + + 7 + 12 + true + false + + + 12 + 12 + true + false + + + 4 + 1 + false + false + + + 2 + 12 + false + true + + + 17 + 12 + true + false + + + + + boss + + + 4 + 18 + true + + + 4 + 19 + false + false + + + + + treasure + + + 6 + 1 + true + + + + + storageroom + + + 6 + 2 + true + + + 6 + 1 + false + true + + + diff --git a/src/main/resources/save/savedGame/person.txt b/src/main/resources/save/savedGame/person.txt index 43cfc91..ec0fcae 100644 --- a/src/main/resources/save/savedGame/person.txt +++ b/src/main/resources/save/savedGame/person.txt @@ -1,6 +1,6 @@ - m1 - 3 - 7 - 2 + storageroom + 6 + 2 + 0 \ No newline at end of file