added menu bugged
This commit is contained in:
parent
aa07964b4c
commit
00c34e649d
@ -1,10 +1,83 @@
|
|||||||
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfMenu;
|
||||||
|
|
||||||
public class Game {
|
import javax.swing.*;
|
||||||
|
import java.awt.event.KeyAdapter;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
|
public class Game extends JFrame {
|
||||||
|
public static final int WINDOW_WIDTH = 11;
|
||||||
|
public static final int WINDOW_HEIGHT = 11;
|
||||||
|
public static final int CELL_SIZE = 50;
|
||||||
|
|
||||||
|
private static final int KEY_FULLSCREEN = 115;
|
||||||
|
private static final int KEY_ESCAPE = 27;
|
||||||
|
|
||||||
|
private WindowOfMenu menu;
|
||||||
|
private WindowOfFreeMove freeMove;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
WindowOfFreeMove window = new WindowOfFreeMove();
|
new Game();
|
||||||
window.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Game() {
|
||||||
|
freeMove = new WindowOfFreeMove(this);
|
||||||
|
menu = new WindowOfMenu(this, freeMove);
|
||||||
|
|
||||||
|
//tohle spustí na začátku menu, ale nejsem schopen přinutit to menu, aby se vzdalo Listeneru a mohl ho využít Game
|
||||||
|
//add(menu);
|
||||||
|
|
||||||
|
//tohle spustí na začátku hru, vše funguje tak, jak má
|
||||||
|
add(freeMove);
|
||||||
|
freeMove.start(true);
|
||||||
|
|
||||||
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
setUndecorated(true);
|
||||||
|
setBounds(0, 0, CELL_SIZE * WINDOW_WIDTH, CELL_SIZE * WINDOW_HEIGHT);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
setResizable(false);
|
||||||
|
setVisible(true);
|
||||||
|
|
||||||
|
addKeyListener(new KeyAdapter() {
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e) {
|
||||||
|
if (e.getKeyCode() == KEY_ESCAPE){
|
||||||
|
dispatchEvent(new WindowEvent(game(), WindowEvent.WINDOW_CLOSING));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.getKeyCode() == KEY_FULLSCREEN){
|
||||||
|
|
||||||
|
if (getExtendedState() == MAXIMIZED_BOTH)
|
||||||
|
setExtendedState(NORMAL);
|
||||||
|
else
|
||||||
|
setExtendedState(MAXIMIZED_BOTH);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
freeMove.keyPressed(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addKeyListener(new KeyAdapter() {
|
||||||
|
@Override
|
||||||
|
public void keyTyped(KeyEvent e) {
|
||||||
|
freeMove.keyTyped(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addKeyListener(new KeyAdapter() {
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent e) {
|
||||||
|
freeMove.keyReleased(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game game() {return this; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,10 @@ import java.awt.event.KeyEvent;
|
|||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class WindowOfFreeMove extends JFrame {
|
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 final int CELL_SIZE = 50;
|
||||||
public static int CANVAS_WIDTH = 50;
|
public static int CANVAS_WIDTH = 50;
|
||||||
public static int CANVAS_HEIGHT = 50;
|
public static int CANVAS_HEIGHT = 50;
|
||||||
@ -33,6 +36,7 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
private static final int KEY_FULLSCREEN = 115;
|
private static final int KEY_FULLSCREEN = 115;
|
||||||
private static final int KEY_ESCAPE = 27;
|
private static final int KEY_ESCAPE = 27;
|
||||||
|
|
||||||
|
private JFrame game;
|
||||||
private Canvas canvas;
|
private Canvas canvas;
|
||||||
private DialogBar dialogBar;
|
private DialogBar dialogBar;
|
||||||
private MapManager mapManager;
|
private MapManager mapManager;
|
||||||
@ -80,10 +84,11 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
|
|
||||||
public Camera getCamera() { return camera; }
|
public Camera getCamera() { return camera; }
|
||||||
|
|
||||||
public WindowOfFreeMove() {
|
public WindowOfFreeMove(JFrame game) {
|
||||||
|
this.game = game;
|
||||||
isReadyToPaint = false;
|
isReadyToPaint = false;
|
||||||
canPersonMove = true;
|
canPersonMove = true;
|
||||||
JLayeredPane lp = getLayeredPane();
|
|
||||||
JPanel background = new JPanel();
|
JPanel background = new JPanel();
|
||||||
background.setBounds(-WINDOW_WIDTH/2, -WINDOW_HEIGHT/2, (CANVAS_WIDTH + WINDOW_WIDTH)*CELL_SIZE, (CANVAS_HEIGHT + WINDOW_HEIGHT)*CELL_SIZE);
|
background.setBounds(-WINDOW_WIDTH/2, -WINDOW_HEIGHT/2, (CANVAS_WIDTH + WINDOW_WIDTH)*CELL_SIZE, (CANVAS_HEIGHT + WINDOW_HEIGHT)*CELL_SIZE);
|
||||||
background.setBackground(Color.BLACK);
|
background.setBackground(Color.BLACK);
|
||||||
@ -108,72 +113,26 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addKeyListener(new KeyAdapter() {
|
add(dialogBar, JLayeredPane.MODAL_LAYER);
|
||||||
@Override
|
add(canvas, JLayeredPane.PALETTE_LAYER);
|
||||||
public void keyTyped(KeyEvent e) {
|
add(background, JLayeredPane.DEFAULT_LAYER);
|
||||||
if (!mapManager.getActualMap().getPerson().getIsMoving() && canPersonMove || nextMove == KEY_EVENT) {
|
|
||||||
mapManager.getActualMap().getPerson().setDirectionMove(nextMove);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addKeyListener(new KeyAdapter() {
|
|
||||||
@Override
|
|
||||||
public void keyPressed(KeyEvent e) {
|
|
||||||
if (e.getKeyCode() == KEY_ESCAPE){
|
|
||||||
dispatchEvent(new WindowEvent(windowOfFreeMove(), WindowEvent.WINDOW_CLOSING));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.getKeyCode() == KEY_FULLSCREEN){
|
|
||||||
|
|
||||||
if (getExtendedState() == MAXIMIZED_BOTH)
|
|
||||||
setExtendedState(NORMAL);
|
|
||||||
else
|
|
||||||
setExtendedState(MAXIMIZED_BOTH);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (canPersonMove) {
|
|
||||||
nextMove = e.getKeyCode();
|
|
||||||
inputTimer.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addKeyListener(new KeyAdapter() {
|
|
||||||
@Override
|
|
||||||
public void keyReleased(KeyEvent e) {
|
|
||||||
inputTimer.stop();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
lp.add(dialogBar, JLayeredPane.MODAL_LAYER);
|
|
||||||
lp.add(canvas, JLayeredPane.PALETTE_LAYER);
|
|
||||||
lp.add(background, JLayeredPane.DEFAULT_LAYER);
|
|
||||||
|
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
|
||||||
setUndecorated(true);
|
|
||||||
setBounds(0, 0, CELL_SIZE * WINDOW_WIDTH, CELL_SIZE * WINDOW_HEIGHT);
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
setResizable(false);
|
|
||||||
setVisible(true);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start(boolean newGame) {
|
||||||
|
|
||||||
mapLinkedList = new LinkedList<>();
|
mapLinkedList = new LinkedList<>();
|
||||||
mapManager = new MapManager(mapLinkedList, canvas, this);
|
mapManager = new MapManager(mapLinkedList, canvas, this);
|
||||||
|
|
||||||
// to load a new game
|
if (newGame) {
|
||||||
mapManager.getLoadManager().clearSave();
|
mapManager.getLoadManager().clearSave();
|
||||||
mapManager.getLoadManager().loadNewGame();
|
mapManager.getLoadManager().loadNewGame();
|
||||||
Map m5 = Map.findMapByName("m5", this);
|
Map m5 = Map.findMapByName("m5", this);
|
||||||
setMapManager(m5);
|
setMapManager(m5);
|
||||||
|
}
|
||||||
//to load a saved game
|
else {
|
||||||
//mapManager.getLoadManager().loadSavedGame();
|
mapManager.getLoadManager().loadSavedGame();
|
||||||
|
}
|
||||||
|
|
||||||
Map m6 = Map.findMapByName("m6", this);
|
Map m6 = Map.findMapByName("m6", this);
|
||||||
|
|
||||||
@ -199,11 +158,23 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
dialogBar.repaint();
|
dialogBar.repaint();
|
||||||
});
|
});
|
||||||
timer.start();
|
timer.start();
|
||||||
while (true) {
|
|
||||||
npc2.move(endX, endY);
|
|
||||||
npc2.move(startX, startY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void keyTyped(KeyEvent e) {
|
||||||
|
if (!mapManager.getActualMap().getPerson().getIsMoving() && canPersonMove || nextMove == KEY_EVENT) {
|
||||||
|
mapManager.getActualMap().getPerson().setDirectionMove(nextMove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyPressed(KeyEvent e) {
|
||||||
|
if (canPersonMove) {
|
||||||
|
nextMove = e.getKeyCode();
|
||||||
|
inputTimer.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyReleased(KeyEvent e) {
|
||||||
|
inputTimer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Canvas extends JPanel {
|
public class Canvas extends JPanel {
|
||||||
|
|||||||
@ -0,0 +1,77 @@
|
|||||||
|
package ruscz.game.gameOfProd.Windows;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
|
public class WindowOfMenu extends JLayeredPane {
|
||||||
|
public static final int WINDOW_WIDTH = 11;
|
||||||
|
public static final int WINDOW_HEIGHT = 11;
|
||||||
|
public static final int CELL_SIZE = 50;
|
||||||
|
|
||||||
|
private JFrame game;
|
||||||
|
private WindowOfFreeMove freeMove;
|
||||||
|
private JButton startNewGame;
|
||||||
|
private JButton loadSavedGame;
|
||||||
|
private JButton exitGame;
|
||||||
|
|
||||||
|
public WindowOfMenu(JFrame game, WindowOfFreeMove freeMove) {
|
||||||
|
this.game = game;
|
||||||
|
this.freeMove = freeMove;
|
||||||
|
|
||||||
|
JPanel background = new JPanel();
|
||||||
|
background.setBounds(0, 0, WINDOW_WIDTH*CELL_SIZE, WINDOW_HEIGHT*CELL_SIZE);
|
||||||
|
background.setBackground(Color.BLACK);
|
||||||
|
|
||||||
|
startNewGame = new JButton("START NEW GAME");
|
||||||
|
startNewGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 -70,200,30);
|
||||||
|
startNewGame.setActionCommand("startNewGame");
|
||||||
|
startNewGame.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
cleanUp();
|
||||||
|
game.add(freeMove);
|
||||||
|
freeMove.start(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
loadSavedGame = new JButton("LOAD SAVED GAME");
|
||||||
|
loadSavedGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2,200,30);
|
||||||
|
loadSavedGame.setActionCommand("loadSavedGame");
|
||||||
|
loadSavedGame.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
cleanUp();
|
||||||
|
game.add(freeMove);
|
||||||
|
freeMove.start(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
exitGame = new JButton("EXIT GAME");
|
||||||
|
exitGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 + 70,200,30);
|
||||||
|
exitGame.setActionCommand("exitGame");
|
||||||
|
exitGame.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
add(startNewGame);
|
||||||
|
add(loadSavedGame);
|
||||||
|
add(exitGame);
|
||||||
|
add(background);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanUp() {
|
||||||
|
setVisible(false);
|
||||||
|
game.remove(this);
|
||||||
|
// startNewGame.removeAll();
|
||||||
|
// loadSavedGame.removeAll();
|
||||||
|
// exitGame.removeAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowOfMenu menu() { return this; }
|
||||||
|
}
|
||||||
@ -1,50 +0,0 @@
|
|||||||
<map>
|
|
||||||
<mapName>m1</mapName>
|
|
||||||
<events>
|
|
||||||
</events>
|
|
||||||
</map>
|
|
||||||
<map>
|
|
||||||
<mapName>m2</mapName>
|
|
||||||
<events>
|
|
||||||
<event>
|
|
||||||
<x>7</x>
|
|
||||||
<y>2</y>
|
|
||||||
<active>true</active>
|
|
||||||
</event>
|
|
||||||
</events>
|
|
||||||
</map>
|
|
||||||
<map>
|
|
||||||
<mapName>m3</mapName>
|
|
||||||
<events>
|
|
||||||
<event>
|
|
||||||
<x>2</x>
|
|
||||||
<y>5</y>
|
|
||||||
<active>true</active>
|
|
||||||
</event>
|
|
||||||
</events>
|
|
||||||
</map>
|
|
||||||
<map>
|
|
||||||
<mapName>m4</mapName>
|
|
||||||
<events>
|
|
||||||
<event>
|
|
||||||
<x>3</x>
|
|
||||||
<y>3</y>
|
|
||||||
<active>true</active>
|
|
||||||
</event>
|
|
||||||
</events>
|
|
||||||
</map>
|
|
||||||
<map>
|
|
||||||
<mapName>m5</mapName>
|
|
||||||
<events>
|
|
||||||
</events>
|
|
||||||
</map>
|
|
||||||
<map>
|
|
||||||
<mapName>m6</mapName>
|
|
||||||
<events>
|
|
||||||
<event>
|
|
||||||
<x>11</x>
|
|
||||||
<y>11</y>
|
|
||||||
<active>true</active>
|
|
||||||
</event>
|
|
||||||
</events>
|
|
||||||
</map>
|
|
||||||
@ -1 +0,0 @@
|
|||||||
TODO: Inventory
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
<location>
|
|
||||||
<map>m5</map>
|
|
||||||
<x>4</x>
|
|
||||||
<y>3</y>
|
|
||||||
</location>
|
|
||||||
@ -1 +0,0 @@
|
|||||||
TODO: Village
|
|
||||||
Loading…
x
Reference in New Issue
Block a user