diff --git a/src/main/java/ruscz/game/gameOfProd/Battle/BattlePerson.java b/src/main/java/ruscz/game/gameOfProd/Battle/BattlePerson.java index 0081048..a3b8c96 100644 --- a/src/main/java/ruscz/game/gameOfProd/Battle/BattlePerson.java +++ b/src/main/java/ruscz/game/gameOfProd/Battle/BattlePerson.java @@ -4,11 +4,11 @@ import ruscz.game.gameOfProd.Windows.WindowOfBattle; import java.awt.*; -public class BattlePerson { - private int health; - private int level; - private String name; - private int strength; +public abstract class BattlePerson { + protected int health; + protected int level; + protected String name; + protected int strength; public BattlePerson(int hp, int lvl, String name, int str){ health = hp; @@ -17,6 +17,20 @@ public class BattlePerson { strength = str; } + public abstract void heal(int heal); + + public abstract void attack(BattlePerson enemy); + + public abstract void block(); + + public abstract void addMana(int mana); + + public abstract void addDeffence(int def); + + public abstract void addStrength(int str); + + public abstract void runAway(); + public void paint(Graphics g, int x, int y) { g.fillOval(x,y, WindowOfBattle.CELL_SIZE, WindowOfBattle.CELL_SIZE); } diff --git a/src/main/java/ruscz/game/gameOfProd/Battle/Enemy.java b/src/main/java/ruscz/game/gameOfProd/Battle/Enemy.java index 449419e..eb956e4 100644 --- a/src/main/java/ruscz/game/gameOfProd/Battle/Enemy.java +++ b/src/main/java/ruscz/game/gameOfProd/Battle/Enemy.java @@ -11,4 +11,35 @@ public class Enemy extends BattlePerson { public int getId() { return id; } + + @Override + public void heal(int heal) { + health += heal; + } + + @Override + public void attack(BattlePerson enemy) { + enemy.setHealth(enemy.getHealth() - (strength)); + } + + @Override + public void block() { + } + + @Override + public void addMana(int mana) { + } + + @Override + public void addDeffence(int def) { + } + + @Override + public void addStrength(int str) { + strength += str; + } + + @Override + public void runAway() { + } } diff --git a/src/main/java/ruscz/game/gameOfProd/Battle/Hero.java b/src/main/java/ruscz/game/gameOfProd/Battle/Hero.java index 05d1d8d..f8c6b5a 100644 --- a/src/main/java/ruscz/game/gameOfProd/Battle/Hero.java +++ b/src/main/java/ruscz/game/gameOfProd/Battle/Hero.java @@ -2,9 +2,47 @@ package ruscz.game.gameOfProd.Battle; public class Hero extends BattlePerson { private int mana; + private int deffence; + private boolean isBlocking; - public Hero(int hp, int lvl, String name, int str, int mana){ + public Hero(int hp, int lvl, String name, int str, int mana, int deffence){ super(hp, lvl, name, str); this.mana = mana; + this.deffence = deffence; + isBlocking = false; + } + + @Override + public void heal(int heal) { + health += heal; + } + + @Override + public void attack(BattlePerson enemy) { + enemy.setHealth(enemy.getHealth() - (strength)); + } + + @Override + public void block() { + isBlocking = true; + } + + @Override + public void addMana(int newMana) { + mana += newMana; + } + + @Override + public void addDeffence(int def) { + deffence += def; + } + + @Override + public void addStrength(int str) { + strength += str; + } + + @Override + public void runAway() { } } diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java index cf74930..5574ebe 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java @@ -5,12 +5,15 @@ import ruscz.game.gameOfProd.Image.ImageCell; import ruscz.game.gameOfProd.Image.ImageDialog; import ruscz.game.gameOfProd.Inventory.InventoryManager; import ruscz.game.gameOfProd.Inventory.Item; +import ruscz.game.gameOfProd.Map.Map; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; +import javax.swing.*; import java.awt.*; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; +import java.util.concurrent.TimeUnit; public class InteractionCell extends Cell { protected String message; @@ -19,6 +22,7 @@ public class InteractionCell extends Cell { private ImageCell imageCell; private WindowOfFreeMove window; protected boolean paint; + private Timer timer; public InteractionCell(int x, int y, String message, Dialog dialog, ImageCell imageCell, WindowOfFreeMove window, boolean paint) { super(x, y, WindowOfFreeMove.CELL_SIZE, Color.ORANGE); @@ -37,6 +41,15 @@ public class InteractionCell extends Cell { } public void readDialogFile(String name) { + if (message.equals("error")) { + final int[] i = {0}; + timer = new Timer(1000, actionEvent -> { + errorEvent(i[0] +1); + i[0]++; + }); + timer.start(); + return; + } try { File dialogFile = new File("src/main/resources/dialogs/" + name + ".txt"); scanner = new Scanner(dialogFile); @@ -56,7 +69,11 @@ public class InteractionCell extends Cell { } else if (data.contains("")) { String[] imageName = data.split(" "); - dialog.setImageDialog(new ImageDialog(imageName[1])); + if (!imageName[1].equals("null")) + dialog.setImageDialog(new ImageDialog(imageName[1])); + else { + dialog.unsetImageDialog(); + } readNextLine(); } else if (data.contains("")) { @@ -129,6 +146,18 @@ public class InteractionCell extends Cell { dialog.showText(); } } + else if (data.contains("")) { + String[] imageName = data.split(" "); + if (!imageName[1].equals("null")) { + dialog.hideText(); + window.getForegroundPanel().setImageForeground(imageName[1]); + window.getForegroundPanel().setVisible(true); + } + else { + window.getForegroundPanel().setVisible(false); + } + readNextLine(); + } else { if (data.contains("
")) data = "" + data + ""; @@ -157,6 +186,41 @@ public class InteractionCell extends Cell { } } + private void errorEvent(int i) { + if (i == 1) { + WindowOfFreeMove.setCanPersonMove(false); + window.getForegroundPanel().setImageForeground("error"); + window.getForegroundPanel().setVisible(true); + window.repaintCanvas(); + } + else if (i == 3) { + Map openspace = Map.findMapByName("openspace", window); + window.getMapManager().setMap(openspace); + openspace.getPerson().set(openspace.getSpawnPoint()[0], openspace.getSpawnPoint()[1]); + openspace.getPerson().setDirectionSight(4); + openspace.setIdExit(0); + dialog.hideText(); + dialog.setText("Shit.."); + dialog.showText(); + } + else if (i == 5) { + window.getForegroundPanel().setVisible(false); + dialog.hideText(); + } + else if (i == 6) { + dialog.setText("I have to take a break. It's lunch time anyway."); + dialog.showText(); + } + else if (i == 10) { + dialog.hideText(); + WindowOfFreeMove.setCanPersonMove(true); + } + else if (i == 11) { + window.getMusicManager().playMusic(); + timer.stop(); + } + } + public void useItem(Item item) { InventoryManager.removeItem(item); } diff --git a/src/main/java/ruscz/game/gameOfProd/Dialog/Dialog.java b/src/main/java/ruscz/game/gameOfProd/Dialog/Dialog.java index 9a42cbf..7c1d8e9 100644 --- a/src/main/java/ruscz/game/gameOfProd/Dialog/Dialog.java +++ b/src/main/java/ruscz/game/gameOfProd/Dialog/Dialog.java @@ -118,6 +118,8 @@ public class Dialog { this.imageDialog = imageDialog; } + public void unsetImageDialog() { imageDialog = null; } + public boolean getTimerIsRunning() { return timerIsRunning; } diff --git a/src/main/java/ruscz/game/gameOfProd/Game.java b/src/main/java/ruscz/game/gameOfProd/Game.java index 1e824d0..fd04903 100644 --- a/src/main/java/ruscz/game/gameOfProd/Game.java +++ b/src/main/java/ruscz/game/gameOfProd/Game.java @@ -37,15 +37,17 @@ public class Game extends JFrame { menu = new WindowOfMenu(this); battle = new WindowOfBattle(this); - add(battle); - battle.startBattle(); //tohle spustí na začátku menu -// add(menu); + add(menu); //tohle spustí na začátku hru // add(freeMove); // freeMove.start(true); + //tohle spustí na začátku bitvu +// add(battle); +// battle.startBattle(); + setDefaultCloseOperation(EXIT_ON_CLOSE); setUndecorated(true); setBounds(0, 0, CELL_SIZE * WINDOW_WIDTH, CELL_SIZE * WINDOW_HEIGHT); diff --git a/src/main/java/ruscz/game/gameOfProd/Map/Map.java b/src/main/java/ruscz/game/gameOfProd/Map/Map.java index 79975fb..fa5c5e0 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/Map.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/Map.java @@ -242,6 +242,18 @@ public class Map { mapArray[x][y] = TypeOfCell.SPAWNPOINT; } + public int[] getSpawnPoint() { + for (int i = 0; i < mapArray.length; i++) { + for (int j = 0; j < mapArray.length; j++) { + if (mapArray[i][j] == TypeOfCell.SPAWNPOINT) { + int[] coords = {i, j}; + return coords; + } + } + } + return null; + } + public ImageCell getImageCell() { return imageCell; } diff --git a/src/main/java/ruscz/game/gameOfProd/Scripts/TextParser.java b/src/main/java/ruscz/game/gameOfProd/Scripts/TextParser.java new file mode 100644 index 0000000..aeed835 --- /dev/null +++ b/src/main/java/ruscz/game/gameOfProd/Scripts/TextParser.java @@ -0,0 +1,90 @@ +package ruscz.game.gameOfProd.Scripts; + +import ruscz.game.gameOfProd.Battle.Battle; +import ruscz.game.gameOfProd.Battle.BattlePerson; +import ruscz.game.gameOfProd.Inventory.InventoryManager; +import ruscz.game.gameOfProd.Inventory.Item; +import ruscz.game.gameOfProd.Inventory.ItemAction; + +public class TextParser { + private String textToParse; + private Battle battle; + private BattlePerson person; + private BattlePerson target; + private Item item; + private String action; + + public TextParser() { + } + + public void parseBattleText(String text) { + textToParse = text; + String person = textToParse.toLowerCase().substring(0, textToParse.indexOf(".")); + parseBattlePerson(person); + String target = textToParse.toLowerCase().substring(textToParse.indexOf("(") + 1, textToParse.indexOf(")")); + parseBattleTarget(target); + String action = textToParse.toLowerCase().substring(textToParse.indexOf(".") + 1, textToParse.indexOf("(")); + parseBattleAction(action); + } + + private void parseBattlePerson(String personText) { + switch (personText) { + case "self": + case "hero": + case "me": + person = battle.getHeroes().getFirst(); + break; + case "enemy": + case "monster": + person = battle.getEnemies().getFirst(); + break; + } + } + + private void parseBattleAction(String action) { + this.action = action; + switch (action) { + case "attack": + person.attack(target); + case "use": + ItemAction itemAction = item.getItemAction(); + switch (itemAction) { + case HEAL: + person.heal(item.getMultiplicity()); + break; + case DEFENCE: + person.addDeffence(item.getMultiplicity()); + break; + case STRENGTH: + person.addStrength(item.getMultiplicity()); + break; + case MANA: + person.addMana(item.getMultiplicity()); + break; + } + break; + case "block": + case "deffend": + person.block(); + break; + case "run": + case "runaway": + person.runAway(); + } + } + + private void parseBattleTarget(String targetText) { + switch (targetText) { + case "self": + case "hero": + case "me": + target = battle.getHeroes().getFirst(); + break; + case "enemy": + target = battle.getEnemies().getFirst(); + break; + default: + item = InventoryManager.findItemByName(targetText); + } + } +} diff --git a/src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java b/src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java index afe94c1..a632fb8 100644 --- a/src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java +++ b/src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java @@ -23,7 +23,7 @@ public class MusicManager { if (clip != null) { FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); - gainControl.setValue(-20.0f); + gainControl.setValue(-15.0f); clip.loop(1000); clip.start(); } diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java index 3db6ce8..1ef5b3d 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java @@ -135,7 +135,7 @@ public class WindowOfBattle extends JPanel { } public void startBattle(){ - Hero hero = new Hero(100, 1, "Mark", 1, 100); + Hero hero = new Hero(100, 1, "Mark", 1, 100, 1); Enemy enemy1 = new Enemy(10, 1, "123", 1, 1); Enemy enemy2 = new Enemy(10, 1, "test", 1, 2); diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java index cfaa059..eae4d24 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java @@ -2,21 +2,20 @@ package ruscz.game.gameOfProd.Windows; import ruscz.game.gameOfProd.Cells.*; import ruscz.game.gameOfProd.Dialog.DialogBar; -import ruscz.game.gameOfProd.Inventory.Item; import ruscz.game.gameOfProd.Map.Map; import ruscz.game.gameOfProd.Map.MapManager; import ruscz.game.gameOfProd.Sounds.MusicManager; +import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.WindowEvent; +import java.io.File; +import java.io.IOException; import java.util.LinkedList; -import static java.awt.Frame.MAXIMIZED_BOTH; -import static java.awt.Frame.NORMAL; - public class WindowOfFreeMove extends JLayeredPane { public static final int CELL_SIZE = 50; public static int CANVAS_WIDTH = 50; @@ -43,6 +42,7 @@ public class WindowOfFreeMove extends JLayeredPane { private Camera camera; private Timer inputTimer; private MusicManager musicManager; + private Foreground foreground; private LinkedList mapLinkedList; @@ -53,7 +53,11 @@ public class WindowOfFreeMove extends JLayeredPane { } public void repaintCanvas() { + mapManager.getActualMap().getPerson().move(); + camera.moveCamera(); canvas.repaint(); + foreground.repaint(); + dialogBar.repaint(); } public static void setCanPersonMove(boolean canPersonMove) { @@ -82,6 +86,10 @@ public class WindowOfFreeMove extends JLayeredPane { public Camera getCamera() { return camera; } + public Foreground getForegroundPanel() { return foreground; } + + public MusicManager getMusicManager() { return musicManager; } + public WindowOfFreeMove(JFrame game) { this.game = game; isReadyToPaint = false; @@ -101,6 +109,11 @@ public class WindowOfFreeMove extends JLayeredPane { dialogBar.setVisible(false); dialogBar.setLayout(null); + foreground = new Foreground(); + foreground.setSize(CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_HEIGHT); + foreground.setOpaque(false); + foreground.setVisible(false); + inputTimer = new Timer(10, actionEvent -> { if (!mapManager.getActualMap().getPerson().getIsMoving() && canPersonMove && nextMove != KEY_EVENT) { mapManager.getActualMap().getPerson().setDirectionMove(nextMove); @@ -108,6 +121,7 @@ public class WindowOfFreeMove extends JLayeredPane { }); add(dialogBar, JLayeredPane.MODAL_LAYER); + add(foreground, JLayeredPane.PALETTE_LAYER); add(canvas, JLayeredPane.PALETTE_LAYER); addKeyListener(new KeyAdapter() { @@ -150,7 +164,7 @@ public class WindowOfFreeMove extends JLayeredPane { if (newGame) { mapManager.getLoadManager().clearSave(); mapManager.getLoadManager().loadNewGame(); - Map openspace = Map.findMapByName("openspace", this); + Map openspace = Map.findMapByName("tutorial", this); setMapManager(openspace); } else { @@ -160,13 +174,14 @@ public class WindowOfFreeMove extends JLayeredPane { mapManager.createMap(); isReadyToPaint = true; - musicManager = new MusicManager("Town1.wav"); + musicManager = new MusicManager("Town3.wav"); // musicManager.playMusic(); Timer timer = new Timer(10, actionEvent -> { mapManager.getActualMap().getPerson().move(); camera.moveCamera(); canvas.repaint(); + foreground.repaint(); dialogBar.repaint(); }); timer.start(); @@ -218,6 +233,24 @@ public class WindowOfFreeMove extends JLayeredPane { } } + public class Foreground extends JPanel { + Image imageForeground; + + public void setImageForeground(String name) { + try { + imageForeground = ImageIO.read(new File("src/main/resources/" + name + ".png")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void paint(Graphics g) { + g.drawImage(imageForeground, 0, 0, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_WIDTH, + WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_HEIGHT, this); + } + } + public static void sleep(long tm) { try { Thread.sleep(tm); diff --git a/src/main/resources/1.png b/src/main/resources/1.png new file mode 100644 index 0000000..412ea53 Binary files /dev/null and b/src/main/resources/1.png differ diff --git a/src/main/resources/3.png b/src/main/resources/3.png new file mode 100644 index 0000000..a66318d Binary files /dev/null and b/src/main/resources/3.png differ diff --git a/src/main/resources/Town3.wav b/src/main/resources/Town3.wav new file mode 100644 index 0000000..58fa0a8 Binary files /dev/null and b/src/main/resources/Town3.wav differ diff --git a/src/main/resources/dialogs/minecraft.txt b/src/main/resources/dialogs/minecraft.txt index 009e3aa..ac731fa 100644 --- a/src/main/resources/dialogs/minecraft.txt +++ b/src/main/resources/dialogs/minecraft.txt @@ -1,3 +1,7 @@ boy3-face.png *slaps rack*
this bad boy can fit so many minecraft servers + error + null +Shit.. + null \ No newline at end of file diff --git a/src/main/resources/error.png b/src/main/resources/error.png new file mode 100644 index 0000000..9cef0d5 Binary files /dev/null and b/src/main/resources/error.png differ diff --git a/src/main/resources/maps/tutorial-tileset.txt b/src/main/resources/maps/tutorial-tileset.txt index 9434c54..7867306 100644 --- a/src/main/resources/maps/tutorial-tileset.txt +++ b/src/main/resources/maps/tutorial-tileset.txt @@ -7,7 +7,7 @@ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 448 451 454 457 460 463 466 469 472 1 1 -1 1 449 452 455 458 461 464 467 470 473 1 1 +1 1 449 452 455 458 461 464 467 470 473 277 1 1 1 450 453 456 459 462 465 468 471 474 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 diff --git a/src/main/resources/maps/tutorial.txt b/src/main/resources/maps/tutorial.txt index 5e14033..65a039f 100644 --- a/src/main/resources/maps/tutorial.txt +++ b/src/main/resources/maps/tutorial.txt @@ -1,11 +1,11 @@ 13 13 BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK +BLOCK EMPTY EMPTY EMPTY EMPTY SPAWN EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK -BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK -BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY MOVETO,5,4,m1 BLOCK +BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY TRIGGER,error BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK