This repository was archived by the owner on Nov 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
68 lines (56 loc) · 1.72 KB
/
Client.java
File metadata and controls
68 lines (56 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.awt.*;
import javax.swing.*;
public class Client {
JFrame window;
GamePanel gamePanel;
Keyboard keyboard;
Mouse mouse;
Messenger messenger;
Server server;
StateMachine stateMachine;
Client() throws Exception {
window = new JFrame("Raider Strike");
gamePanel = new GamePanel();
keyboard = new Keyboard();
mouse = new Mouse();
messenger = new Messenger();
server = new Server(messenger);
messenger.setServer(server);
stateMachine = new StateMachine(keyboard, mouse, messenger);
}
// set up the game window
public void setup() {
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setResizable(false);
gamePanel.addKeyListener(keyboard);
gamePanel.addMouseListener(mouse);
gamePanel.addMouseMotionListener(mouse);
window.add(gamePanel);
window.pack();
window.setLocationRelativeTo(null);
window.setVisible(true);
// Music.play();
}
// main game loop
public void start() {
server.start();
while (true) {
window.repaint();
try {Thread.sleep(Const.FRAME_PERIOD);} catch(Exception e){}
stateMachine.update();
}
}
//draw everything
public class GamePanel extends JPanel {
GamePanel() {
setPreferredSize(new Dimension(Const.WIDTH, Const.HEIGHT));
setFocusable(true);
requestFocusInWindow();
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g); //required
stateMachine.draw(g);
}
}
}