added tutorial

This commit is contained in:
musilto9 2020-04-20 18:06:38 +02:00
parent bb5af0ac0c
commit 7467490b88
18 changed files with 311 additions and 21 deletions

View File

@ -4,11 +4,11 @@ import ruscz.game.gameOfProd.Windows.WindowOfBattle;
import java.awt.*; import java.awt.*;
public class BattlePerson { public abstract class BattlePerson {
private int health; protected int health;
private int level; protected int level;
private String name; protected String name;
private int strength; protected int strength;
public BattlePerson(int hp, int lvl, String name, int str){ public BattlePerson(int hp, int lvl, String name, int str){
health = hp; health = hp;
@ -17,6 +17,20 @@ public class BattlePerson {
strength = str; 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) { public void paint(Graphics g, int x, int y) {
g.fillOval(x,y, WindowOfBattle.CELL_SIZE, WindowOfBattle.CELL_SIZE); g.fillOval(x,y, WindowOfBattle.CELL_SIZE, WindowOfBattle.CELL_SIZE);
} }

View File

@ -11,4 +11,35 @@ public class Enemy extends BattlePerson {
public int getId() { public int getId() {
return id; 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() {
}
} }

View File

@ -2,9 +2,47 @@ package ruscz.game.gameOfProd.Battle;
public class Hero extends BattlePerson { public class Hero extends BattlePerson {
private int mana; 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); super(hp, lvl, name, str);
this.mana = mana; 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() {
} }
} }

View File

@ -5,12 +5,15 @@ import ruscz.game.gameOfProd.Image.ImageCell;
import ruscz.game.gameOfProd.Image.ImageDialog; import ruscz.game.gameOfProd.Image.ImageDialog;
import ruscz.game.gameOfProd.Inventory.InventoryManager; import ruscz.game.gameOfProd.Inventory.InventoryManager;
import ruscz.game.gameOfProd.Inventory.Item; import ruscz.game.gameOfProd.Inventory.Item;
import ruscz.game.gameOfProd.Map.Map;
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.Scanner; import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public class InteractionCell extends Cell { public class InteractionCell extends Cell {
protected String message; protected String message;
@ -19,6 +22,7 @@ public class InteractionCell extends Cell {
private ImageCell imageCell; private ImageCell imageCell;
private WindowOfFreeMove window; private WindowOfFreeMove window;
protected boolean paint; protected boolean paint;
private Timer timer;
public InteractionCell(int x, int y, String message, Dialog dialog, ImageCell imageCell, WindowOfFreeMove window, boolean paint) { public InteractionCell(int x, int y, String message, Dialog dialog, ImageCell imageCell, WindowOfFreeMove window, boolean paint) {
super(x, y, WindowOfFreeMove.CELL_SIZE, Color.ORANGE); super(x, y, WindowOfFreeMove.CELL_SIZE, Color.ORANGE);
@ -37,6 +41,15 @@ public class InteractionCell extends Cell {
} }
public void readDialogFile(String name) { 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 { try {
File dialogFile = new File("src/main/resources/dialogs/" + name + ".txt"); File dialogFile = new File("src/main/resources/dialogs/" + name + ".txt");
scanner = new Scanner(dialogFile); scanner = new Scanner(dialogFile);
@ -56,7 +69,11 @@ public class InteractionCell extends Cell {
} }
else if (data.contains("<image>")) { else if (data.contains("<image>")) {
String[] imageName = data.split(" "); String[] imageName = data.split(" ");
if (!imageName[1].equals("null"))
dialog.setImageDialog(new ImageDialog(imageName[1])); dialog.setImageDialog(new ImageDialog(imageName[1]));
else {
dialog.unsetImageDialog();
}
readNextLine(); readNextLine();
} }
else if (data.contains("<cameraFree>")) { else if (data.contains("<cameraFree>")) {
@ -129,6 +146,18 @@ public class InteractionCell extends Cell {
dialog.showText(); dialog.showText();
} }
} }
else if (data.contains("<foreground>")) {
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 { else {
if (data.contains("<br/>")) if (data.contains("<br/>"))
data = "<html>" + data + "</html>"; data = "<html>" + data + "</html>";
@ -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) { public void useItem(Item item) {
InventoryManager.removeItem(item); InventoryManager.removeItem(item);
} }

View File

@ -118,6 +118,8 @@ public class Dialog {
this.imageDialog = imageDialog; this.imageDialog = imageDialog;
} }
public void unsetImageDialog() { imageDialog = null; }
public boolean getTimerIsRunning() { public boolean getTimerIsRunning() {
return timerIsRunning; return timerIsRunning;
} }

View File

@ -37,15 +37,17 @@ public class Game extends JFrame {
menu = new WindowOfMenu(this); menu = new WindowOfMenu(this);
battle = new WindowOfBattle(this); battle = new WindowOfBattle(this);
add(battle);
battle.startBattle();
//tohle spustí na začátku menu //tohle spustí na začátku menu
// add(menu); add(menu);
//tohle spustí na začátku hru //tohle spustí na začátku hru
// add(freeMove); // add(freeMove);
// freeMove.start(true); // freeMove.start(true);
//tohle spustí na začátku bitvu
// add(battle);
// battle.startBattle();
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
setUndecorated(true); setUndecorated(true);
setBounds(0, 0, CELL_SIZE * WINDOW_WIDTH, CELL_SIZE * WINDOW_HEIGHT); setBounds(0, 0, CELL_SIZE * WINDOW_WIDTH, CELL_SIZE * WINDOW_HEIGHT);

View File

@ -242,6 +242,18 @@ public class Map {
mapArray[x][y] = TypeOfCell.SPAWNPOINT; 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() { public ImageCell getImageCell() {
return imageCell; return imageCell;
} }

View File

@ -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);
}
}
}

View File

@ -23,7 +23,7 @@ public class MusicManager {
if (clip != null) { if (clip != null) {
FloatControl gainControl = FloatControl gainControl =
(FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(-20.0f); gainControl.setValue(-15.0f);
clip.loop(1000); clip.loop(1000);
clip.start(); clip.start();
} }

View File

@ -135,7 +135,7 @@ public class WindowOfBattle extends JPanel {
} }
public void startBattle(){ 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 enemy1 = new Enemy(10, 1, "123", 1, 1);
Enemy enemy2 = new Enemy(10, 1, "test", 1, 2); Enemy enemy2 = new Enemy(10, 1, "test", 1, 2);

View File

@ -2,21 +2,20 @@ package ruscz.game.gameOfProd.Windows;
import ruscz.game.gameOfProd.Cells.*; import ruscz.game.gameOfProd.Cells.*;
import ruscz.game.gameOfProd.Dialog.DialogBar; import ruscz.game.gameOfProd.Dialog.DialogBar;
import ruscz.game.gameOfProd.Inventory.Item;
import ruscz.game.gameOfProd.Map.Map; import ruscz.game.gameOfProd.Map.Map;
import ruscz.game.gameOfProd.Map.MapManager; import ruscz.game.gameOfProd.Map.MapManager;
import ruscz.game.gameOfProd.Sounds.MusicManager; import ruscz.game.gameOfProd.Sounds.MusicManager;
import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList; import java.util.LinkedList;
import static java.awt.Frame.MAXIMIZED_BOTH;
import static java.awt.Frame.NORMAL;
public class WindowOfFreeMove extends JLayeredPane { public class WindowOfFreeMove extends JLayeredPane {
public static final int CELL_SIZE = 50; public static final int CELL_SIZE = 50;
public static int CANVAS_WIDTH = 50; public static int CANVAS_WIDTH = 50;
@ -43,6 +42,7 @@ public class WindowOfFreeMove extends JLayeredPane {
private Camera camera; private Camera camera;
private Timer inputTimer; private Timer inputTimer;
private MusicManager musicManager; private MusicManager musicManager;
private Foreground foreground;
private LinkedList<Map> mapLinkedList; private LinkedList<Map> mapLinkedList;
@ -53,7 +53,11 @@ public class WindowOfFreeMove extends JLayeredPane {
} }
public void repaintCanvas() { public void repaintCanvas() {
mapManager.getActualMap().getPerson().move();
camera.moveCamera();
canvas.repaint(); canvas.repaint();
foreground.repaint();
dialogBar.repaint();
} }
public static void setCanPersonMove(boolean canPersonMove) { public static void setCanPersonMove(boolean canPersonMove) {
@ -82,6 +86,10 @@ public class WindowOfFreeMove extends JLayeredPane {
public Camera getCamera() { return camera; } public Camera getCamera() { return camera; }
public Foreground getForegroundPanel() { return foreground; }
public MusicManager getMusicManager() { return musicManager; }
public WindowOfFreeMove(JFrame game) { public WindowOfFreeMove(JFrame game) {
this.game = game; this.game = game;
isReadyToPaint = false; isReadyToPaint = false;
@ -101,6 +109,11 @@ public class WindowOfFreeMove extends JLayeredPane {
dialogBar.setVisible(false); dialogBar.setVisible(false);
dialogBar.setLayout(null); 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 -> { inputTimer = new Timer(10, actionEvent -> {
if (!mapManager.getActualMap().getPerson().getIsMoving() && canPersonMove && nextMove != KEY_EVENT) { if (!mapManager.getActualMap().getPerson().getIsMoving() && canPersonMove && nextMove != KEY_EVENT) {
mapManager.getActualMap().getPerson().setDirectionMove(nextMove); mapManager.getActualMap().getPerson().setDirectionMove(nextMove);
@ -108,6 +121,7 @@ public class WindowOfFreeMove extends JLayeredPane {
}); });
add(dialogBar, JLayeredPane.MODAL_LAYER); add(dialogBar, JLayeredPane.MODAL_LAYER);
add(foreground, JLayeredPane.PALETTE_LAYER);
add(canvas, JLayeredPane.PALETTE_LAYER); add(canvas, JLayeredPane.PALETTE_LAYER);
addKeyListener(new KeyAdapter() { addKeyListener(new KeyAdapter() {
@ -150,7 +164,7 @@ public class WindowOfFreeMove extends JLayeredPane {
if (newGame) { if (newGame) {
mapManager.getLoadManager().clearSave(); mapManager.getLoadManager().clearSave();
mapManager.getLoadManager().loadNewGame(); mapManager.getLoadManager().loadNewGame();
Map openspace = Map.findMapByName("openspace", this); Map openspace = Map.findMapByName("tutorial", this);
setMapManager(openspace); setMapManager(openspace);
} }
else { else {
@ -160,13 +174,14 @@ public class WindowOfFreeMove extends JLayeredPane {
mapManager.createMap(); mapManager.createMap();
isReadyToPaint = true; isReadyToPaint = true;
musicManager = new MusicManager("Town1.wav"); musicManager = new MusicManager("Town3.wav");
// musicManager.playMusic(); // musicManager.playMusic();
Timer timer = new Timer(10, actionEvent -> { Timer timer = new Timer(10, actionEvent -> {
mapManager.getActualMap().getPerson().move(); mapManager.getActualMap().getPerson().move();
camera.moveCamera(); camera.moveCamera();
canvas.repaint(); canvas.repaint();
foreground.repaint();
dialogBar.repaint(); dialogBar.repaint();
}); });
timer.start(); 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) { public static void sleep(long tm) {
try { try {
Thread.sleep(tm); Thread.sleep(tm);

BIN
src/main/resources/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

BIN
src/main/resources/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 B

Binary file not shown.

View File

@ -1,3 +1,7 @@
<image> boy3-face.png <image> boy3-face.png
*slaps rack*<br/>this bad boy can fit so many minecraft servers *slaps rack*<br/>this bad boy can fit so many minecraft servers
<foreground> error
<image> null
Shit..
<foreground> null
<end> <end>

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 KiB

View File

@ -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 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 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 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
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

View File

@ -1,11 +1,11 @@
13 13 13 13
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK 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 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 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 TRIGGER,error 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 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 EMPTY BLOCK