Added icon, and some cleaner server behavior.

This commit is contained in:
Andrew Lalis 2021-06-20 16:04:30 +02:00
parent 94f13c0753
commit 54e9ecdb5b
3 changed files with 22 additions and 5 deletions

View File

@ -4,17 +4,29 @@ import nl.andrewlalis.aos_client.Client;
import nl.andrewlalis.aos_client.control.PlayerKeyListener; import nl.andrewlalis.aos_client.control.PlayerKeyListener;
import nl.andrewlalis.aos_client.control.PlayerMouseListener; import nl.andrewlalis.aos_client.control.PlayerMouseListener;
import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.io.IOException;
import java.io.InputStream;
public class GameFrame extends JFrame { public class GameFrame extends JFrame {
public GameFrame(String title, Client client, GamePanel gamePanel) throws HeadlessException { public GameFrame(String title, Client client, GamePanel gamePanel) throws HeadlessException {
super(title); super(title);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); 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); this.setResizable(false);
gamePanel.setPreferredSize(new Dimension(800, 800)); gamePanel.setPreferredSize(new Dimension(800, 800));
this.setContentPane(gamePanel); this.setContentPane(gamePanel);
gamePanel.setFocusable(true); gamePanel.setFocusable(true);
@ -24,6 +36,7 @@ public class GameFrame extends JFrame {
gamePanel.addMouseListener(mouseListener); gamePanel.addMouseListener(mouseListener);
gamePanel.addMouseMotionListener(mouseListener); gamePanel.addMouseMotionListener(mouseListener);
gamePanel.addMouseWheelListener(mouseListener); gamePanel.addMouseWheelListener(mouseListener);
this.addWindowListener(new WindowAdapter() { this.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
@ -31,7 +44,9 @@ public class GameFrame extends JFrame {
client.shutdown(); client.shutdown();
} }
}); });
this.pack(); this.pack();
gamePanel.requestFocusInWindow(); gamePanel.requestFocusInWindow();
this.setLocationRelativeTo(null); this.setLocationRelativeTo(null);
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View File

@ -36,8 +36,12 @@ public class Server {
this.clientHandlers = new CopyOnWriteArrayList<>(); this.clientHandlers = new CopyOnWriteArrayList<>();
this.serverSocket = new ServerSocket(port); this.serverSocket = new ServerSocket(port);
this.cli = new ServerCli(this); this.cli = new ServerCli(this);
this.world = new World(new Vec2(50, 70)); 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, 10, 30, 5));
world.getBarricades().add(new Barricade(10, 55, 30, 5)); world.getBarricades().add(new Barricade(10, 55, 30, 5));
world.getBarricades().add(new Barricade(20, 30, 10, 10)); 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(world.getSize().x() - 15, world.getSize().y() - 3),
new Vec2(0, -1) new Vec2(0, -1)
)); ));
this.worldUpdater = new WorldUpdater(this, this.world);
System.out.println("Started AOS-Server TCP on port " + port);
} }
public World getWorld() { public World getWorld() {
@ -208,6 +209,7 @@ public class Server {
this.running = true; this.running = true;
this.worldUpdater.start(); this.worldUpdater.start();
this.cli.start(); this.cli.start();
System.out.println("Started AOS-Server TCP on port " + this.serverSocket.getLocalPort() + "; now accepting connections.");
while (this.running) { while (this.running) {
this.acceptClientConnection(); this.acceptClientConnection();
} }