diff --git a/client/src/main/java/nl/andrewlalis/aos_client/view/GameFrame.java b/client/src/main/java/nl/andrewlalis/aos_client/view/GameFrame.java index 0c944d5..5a1e76a 100644 --- a/client/src/main/java/nl/andrewlalis/aos_client/view/GameFrame.java +++ b/client/src/main/java/nl/andrewlalis/aos_client/view/GameFrame.java @@ -4,17 +4,29 @@ import nl.andrewlalis.aos_client.Client; import nl.andrewlalis.aos_client.control.PlayerKeyListener; import nl.andrewlalis.aos_client.control.PlayerMouseListener; +import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.io.IOException; +import java.io.InputStream; public class GameFrame extends JFrame { public GameFrame(String title, Client client, GamePanel gamePanel) throws HeadlessException { super(title); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); - + InputStream iconInputStream = GameFrame.class.getClassLoader().getResourceAsStream("icon.png"); + if (iconInputStream != null) { + try { + this.setIconImage(ImageIO.read(iconInputStream)); + iconInputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } this.setResizable(false); + gamePanel.setPreferredSize(new Dimension(800, 800)); this.setContentPane(gamePanel); gamePanel.setFocusable(true); @@ -24,6 +36,7 @@ public class GameFrame extends JFrame { gamePanel.addMouseListener(mouseListener); gamePanel.addMouseMotionListener(mouseListener); gamePanel.addMouseWheelListener(mouseListener); + this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { @@ -31,7 +44,9 @@ public class GameFrame extends JFrame { client.shutdown(); } }); + this.pack(); + gamePanel.requestFocusInWindow(); this.setLocationRelativeTo(null); } diff --git a/client/src/main/resources/icon.png b/client/src/main/resources/icon.png new file mode 100644 index 0000000..7e13cd1 Binary files /dev/null and b/client/src/main/resources/icon.png differ diff --git a/server/src/main/java/nl/andrewlalis/aos_server/Server.java b/server/src/main/java/nl/andrewlalis/aos_server/Server.java index 843ff86..39a7e45 100644 --- a/server/src/main/java/nl/andrewlalis/aos_server/Server.java +++ b/server/src/main/java/nl/andrewlalis/aos_server/Server.java @@ -36,8 +36,12 @@ public class Server { this.clientHandlers = new CopyOnWriteArrayList<>(); this.serverSocket = new ServerSocket(port); this.cli = new ServerCli(this); - this.world = new World(new Vec2(50, 70)); + this.initWorld(); + this.worldUpdater = new WorldUpdater(this, this.world); + } + + private void initWorld() { world.getBarricades().add(new Barricade(10, 10, 30, 5)); world.getBarricades().add(new Barricade(10, 55, 30, 5)); world.getBarricades().add(new Barricade(20, 30, 10, 10)); @@ -58,9 +62,6 @@ public class Server { new Vec2(world.getSize().x() - 15, world.getSize().y() - 3), new Vec2(0, -1) )); - - this.worldUpdater = new WorldUpdater(this, this.world); - System.out.println("Started AOS-Server TCP on port " + port); } public World getWorld() { @@ -208,6 +209,7 @@ public class Server { this.running = true; this.worldUpdater.start(); this.cli.start(); + System.out.println("Started AOS-Server TCP on port " + this.serverSocket.getLocalPort() + "; now accepting connections."); while (this.running) { this.acceptClientConnection(); }