diff --git a/src/main/java/Game.java b/src/main/java/Game.java index aea8036..e73eea6 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -2,10 +2,12 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import ruscz.game.gameOfProd.Windows.WindowOfMenu; import javax.swing.*; +import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.WindowEvent; +import java.awt.image.BufferedImage; public class Game extends JFrame { private static final int WINDOW_WIDTH = 13; @@ -23,10 +25,10 @@ public class Game extends JFrame { 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 + //tohle spustí na začátku menu add(menu); - //tohle spustí na začátku hru, vše funguje tak, jak má + //tohle spustí na začátku hru // add(freeMove); // freeMove.start(true); @@ -36,9 +38,19 @@ public class Game extends JFrame { setLocationRelativeTo(null); setResizable(false); setVisible(true); - + setLayout(new BorderLayout()); + getContentPane().setBackground(Color.BLACK); + setExtendedState(game().MAXIMIZED_BOTH); + centerContent(); } + + public Game game() {return this;} + + public void centerContent() { + getContentPane().getComponent(0).setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - (WINDOW_WIDTH * CELL_SIZE)) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - (WINDOW_HEIGHT * CELL_SIZE)) / 2); + getContentPane().getComponent(0).setSize(WINDOW_WIDTH * CELL_SIZE, WINDOW_HEIGHT * CELL_SIZE); + } } diff --git a/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java b/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java index 8967fb3..a35b89f 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/MapManager.java @@ -117,6 +117,6 @@ public class MapManager { canvas.setPreferredSize(new Dimension( CELL_SIZE * size[0], CELL_SIZE * size[1])); - canvas.setBounds(0, 0, CELL_SIZE * size[0], CELL_SIZE * size[1]); + canvas.setSize(CELL_SIZE * size[0], CELL_SIZE * size[1]); } } diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java index 1a59b91..9a81a1b 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java @@ -33,7 +33,6 @@ public class WindowOfFreeMove extends JLayeredPane { public static final int KEY_DOWN = 40; public static final int KEY_EVENT = 69; - private static final int KEY_FULLSCREEN = 115; private static final int KEY_ESCAPE = 27; private JFrame game; @@ -46,6 +45,8 @@ public class WindowOfFreeMove extends JLayeredPane { private LinkedList mapLinkedList; + public WindowOfFreeMove windowOfFreeMove() { return this;} + public MapManager getMapManager() { return mapManager; } @@ -81,24 +82,21 @@ public class WindowOfFreeMove extends JLayeredPane { public Camera getCamera() { return camera; } public WindowOfFreeMove(JFrame game) { + this.game = game; isReadyToPaint = false; canPersonMove = true; - 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.setBackground(Color.BLACK); - canvas = new Canvas(); camera = new Camera(this, canvas); canvas.setBackground(Color.BLACK); canvas.setPreferredSize(new Dimension( CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_HEIGHT)); - canvas.setBounds(0, 0, CELL_SIZE * CANVAS_HEIGHT, CELL_SIZE * CANVAS_WIDTH); + canvas.setSize(CELL_SIZE * CANVAS_HEIGHT, CELL_SIZE * CANVAS_WIDTH); dialogBar = new DialogBar(); - dialogBar.setBounds(0, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_HEIGHT * 3 / 4, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_WIDTH, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_HEIGHT / 4); + dialogBar.setBounds(0, CELL_SIZE * WINDOW_HEIGHT * 3/4, CELL_SIZE * WINDOW_WIDTH, CELL_SIZE * WINDOW_HEIGHT / 4); dialogBar.setOpaque(false); dialogBar.setVisible(false); dialogBar.setLayout(null); @@ -111,7 +109,6 @@ public class WindowOfFreeMove extends JLayeredPane { add(dialogBar, JLayeredPane.MODAL_LAYER); add(canvas, JLayeredPane.PALETTE_LAYER); - add(background, JLayeredPane.DEFAULT_LAYER); addKeyListener(new KeyAdapter() { @Override @@ -121,12 +118,6 @@ public class WindowOfFreeMove extends JLayeredPane { game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING)); return; } - if (e.getKeyCode() == KEY_FULLSCREEN){ - if (game.getExtendedState() == game.MAXIMIZED_BOTH) - game.setExtendedState(game.NORMAL); - else - game.setExtendedState(game.MAXIMIZED_BOTH); - } else { if (canPersonMove) { nextMove = e.getKeyCode(); @@ -151,10 +142,10 @@ public class WindowOfFreeMove extends JLayeredPane { inputTimer.stop(); } }); - } public void start(boolean newGame) { + mapLinkedList = new LinkedList<>(); mapManager = new MapManager(mapLinkedList, canvas, this); @@ -183,6 +174,12 @@ public class WindowOfFreeMove extends JLayeredPane { musicManager = new MusicManager("Town1.wav"); // musicManager.playMusic(); + + Timer center = new Timer(1, actionEvent -> { + centerContent(); + }); + center.start(); + Timer timer = new Timer(10, actionEvent -> { mapManager.getActualMap().getPerson().move(); camera.moveCamera(); @@ -243,4 +240,8 @@ public class WindowOfFreeMove extends JLayeredPane { CANVAS_HEIGHT = size[1]; } + public void centerContent() { + game.getContentPane().getComponent(0).setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - (WINDOW_WIDTH * CELL_SIZE)) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - (WINDOW_HEIGHT * CELL_SIZE)) / 2); + game.getContentPane().getComponent(0).setSize(WINDOW_WIDTH * CELL_SIZE, WINDOW_HEIGHT * CELL_SIZE); + } } \ No newline at end of file diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java index ac9b6ce..ad1f619 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java @@ -3,6 +3,7 @@ package ruscz.game.gameOfProd.Windows; import javax.swing.*; import java.awt.*; import java.awt.event.*; +import java.awt.image.BufferedImage; public class WindowOfMenu extends JLayeredPane { public static final int WINDOW_WIDTH = 13; @@ -22,10 +23,6 @@ public class WindowOfMenu extends JLayeredPane { 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.setFocusable(false); startNewGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 -70,200,30); @@ -49,7 +46,6 @@ public class WindowOfMenu extends JLayeredPane { }); exitGame = new JButton("EXIT GAME"); - //exitGame.setFocusable(false); exitGame.setBounds((WINDOW_WIDTH*CELL_SIZE - 200) / 2,(WINDOW_HEIGHT*CELL_SIZE - 30) / 2 + 70,200,30); exitGame.setActionCommand("exitGame"); exitGame.addActionListener(actionEvent -> game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING))); @@ -57,24 +53,6 @@ public class WindowOfMenu extends JLayeredPane { add(startNewGame); add(loadSavedGame); add(exitGame); - add(background); - - addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KEY_ESCAPE){ - game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING)); - return; - } - if (e.getKeyCode() == KEY_FULLSCREEN){ - - if (game.getExtendedState() == game.MAXIMIZED_BOTH) - game.setExtendedState(game.NORMAL); - else - game.setExtendedState(game.MAXIMIZED_BOTH); - } - } - }); } private void cleanUp() { @@ -86,6 +64,10 @@ public class WindowOfMenu extends JLayeredPane { game.remove(this); menu().revalidate(); menu().repaint(); + freeMove.setCursor(freeMove.getToolkit().createCustomCursor( + new BufferedImage( 1, 1, BufferedImage.TYPE_INT_ARGB ), + new Point(), + null ) ); } public WindowOfMenu menu() { return this; } diff --git a/src/main/resources/maps/office.txt b/src/main/resources/maps/office.txt index 1c31a2f..e53998e 100644 --- a/src/main/resources/maps/office.txt +++ b/src/main/resources/maps/office.txt @@ -10,4 +10,4 @@ BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BL BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK -BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK block BLOCK BLOCK \ No newline at end of file +BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,locked,false BLOCK BLOCK \ No newline at end of file diff --git a/src/main/resources/save/savedGame/events-DESKTOP-TL25DTN-2.txt b/src/main/resources/save/savedGame/events-DESKTOP-TL25DTN-2.txt new file mode 100644 index 0000000..245388a --- /dev/null +++ b/src/main/resources/save/savedGame/events-DESKTOP-TL25DTN-2.txt @@ -0,0 +1,70 @@ + + m1 + + + + + m2 + + + 7 + 2 + true + + + + + m3 + + + 2 + 5 + true + + + + + m4 + + + 3 + 3 + true + + + + + m5 + + + + + m6 + + + 11 + 11 + true + + + + + openspace + + + + + office + + + + + boss + + + 4 + 18 + true + + + diff --git a/src/main/resources/save/savedGame/events-DESKTOP-TL25DTN-3.txt b/src/main/resources/save/savedGame/events-DESKTOP-TL25DTN-3.txt new file mode 100644 index 0000000..245388a --- /dev/null +++ b/src/main/resources/save/savedGame/events-DESKTOP-TL25DTN-3.txt @@ -0,0 +1,70 @@ + + m1 + + + + + m2 + + + 7 + 2 + true + + + + + m3 + + + 2 + 5 + true + + + + + m4 + + + 3 + 3 + true + + + + + m5 + + + + + m6 + + + 11 + 11 + true + + + + + openspace + + + + + office + + + + + boss + + + 4 + 18 + true + + + diff --git a/src/main/resources/save/savedGame/events-DESKTOP-TL25DTN.txt b/src/main/resources/save/savedGame/events-DESKTOP-TL25DTN.txt new file mode 100644 index 0000000..245388a --- /dev/null +++ b/src/main/resources/save/savedGame/events-DESKTOP-TL25DTN.txt @@ -0,0 +1,70 @@ + + m1 + + + + + m2 + + + 7 + 2 + true + + + + + m3 + + + 2 + 5 + true + + + + + m4 + + + 3 + 3 + true + + + + + m5 + + + + + m6 + + + 11 + 11 + true + + + + + openspace + + + + + office + + + + + boss + + + 4 + 18 + true + + + diff --git a/src/main/resources/save/savedGame/events.txt b/src/main/resources/save/savedGame/events.txt index f79dde1..245388a 100644 --- a/src/main/resources/save/savedGame/events.txt +++ b/src/main/resources/save/savedGame/events.txt @@ -64,7 +64,7 @@ 4 18 - false + true diff --git a/src/main/resources/save/savedGame/inventory-DESKTOP-TL25DTN-2.txt b/src/main/resources/save/savedGame/inventory-DESKTOP-TL25DTN-2.txt new file mode 100644 index 0000000..7082420 --- /dev/null +++ b/src/main/resources/save/savedGame/inventory-DESKTOP-TL25DTN-2.txt @@ -0,0 +1 @@ +TODO: Inventory \ No newline at end of file diff --git a/src/main/resources/save/savedGame/inventory-DESKTOP-TL25DTN-3.txt b/src/main/resources/save/savedGame/inventory-DESKTOP-TL25DTN-3.txt new file mode 100644 index 0000000..7082420 --- /dev/null +++ b/src/main/resources/save/savedGame/inventory-DESKTOP-TL25DTN-3.txt @@ -0,0 +1 @@ +TODO: Inventory \ No newline at end of file diff --git a/src/main/resources/save/savedGame/inventory-DESKTOP-TL25DTN.txt b/src/main/resources/save/savedGame/inventory-DESKTOP-TL25DTN.txt new file mode 100644 index 0000000..7082420 --- /dev/null +++ b/src/main/resources/save/savedGame/inventory-DESKTOP-TL25DTN.txt @@ -0,0 +1 @@ +TODO: Inventory \ No newline at end of file diff --git a/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN-2.txt b/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN-2.txt new file mode 100644 index 0000000..ee5b150 --- /dev/null +++ b/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN-2.txt @@ -0,0 +1,5 @@ + + m1 + 1 + 7 + \ No newline at end of file diff --git a/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN-3.txt b/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN-3.txt new file mode 100644 index 0000000..ee5b150 --- /dev/null +++ b/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN-3.txt @@ -0,0 +1,5 @@ + + m1 + 1 + 7 + \ No newline at end of file diff --git a/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN-4.txt b/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN-4.txt new file mode 100644 index 0000000..ee5b150 --- /dev/null +++ b/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN-4.txt @@ -0,0 +1,5 @@ + + m1 + 1 + 7 + \ No newline at end of file diff --git a/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN-5.txt b/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN-5.txt new file mode 100644 index 0000000..ee5b150 --- /dev/null +++ b/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN-5.txt @@ -0,0 +1,5 @@ + + m1 + 1 + 7 + \ No newline at end of file diff --git a/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN.txt b/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN.txt new file mode 100644 index 0000000..ee5b150 --- /dev/null +++ b/src/main/resources/save/savedGame/person-DESKTOP-TL25DTN.txt @@ -0,0 +1,5 @@ + + m1 + 1 + 7 + \ No newline at end of file diff --git a/src/main/resources/save/savedGame/person.txt b/src/main/resources/save/savedGame/person.txt index e33ef6b..77eed58 100644 --- a/src/main/resources/save/savedGame/person.txt +++ b/src/main/resources/save/savedGame/person.txt @@ -1,5 +1,5 @@ - office - 4 - 1 + m1 + 8 + 4 \ No newline at end of file diff --git a/src/main/resources/save/savedGame/village-DESKTOP-TL25DTN-2.txt b/src/main/resources/save/savedGame/village-DESKTOP-TL25DTN-2.txt new file mode 100644 index 0000000..1b4bc7b --- /dev/null +++ b/src/main/resources/save/savedGame/village-DESKTOP-TL25DTN-2.txt @@ -0,0 +1 @@ +TODO: Village \ No newline at end of file diff --git a/src/main/resources/save/savedGame/village-DESKTOP-TL25DTN-3.txt b/src/main/resources/save/savedGame/village-DESKTOP-TL25DTN-3.txt new file mode 100644 index 0000000..1b4bc7b --- /dev/null +++ b/src/main/resources/save/savedGame/village-DESKTOP-TL25DTN-3.txt @@ -0,0 +1 @@ +TODO: Village \ No newline at end of file diff --git a/src/main/resources/save/savedGame/village-DESKTOP-TL25DTN.txt b/src/main/resources/save/savedGame/village-DESKTOP-TL25DTN.txt new file mode 100644 index 0000000..1b4bc7b --- /dev/null +++ b/src/main/resources/save/savedGame/village-DESKTOP-TL25DTN.txt @@ -0,0 +1 @@ +TODO: Village \ No newline at end of file