Added icon, and some cleaner server behavior.
This commit is contained in:
parent
94f13c0753
commit
54e9ecdb5b
|
@ -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);
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 43 KiB |
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue