Skip to content

Commit e0bf6c0

Browse files
committed
Fix exceptions and remove unused code
1 parent 3a11fc7 commit e0bf6c0

7 files changed

Lines changed: 34 additions & 77 deletions

File tree

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
# Java-Game-Engine
22
Game Engine Implementation in Java
3+
4+
How to run:
5+
6+
1) Setup running processing in eclipse using this tutorial: https://processing.org/tutorials/eclipse/
7+
8+
2) Import the source code for this project. It is raw source code with no eclipse project information so you will have to import it as such. Eclipse should automagically fix everything the proper way.
9+
10+
2.5) The "Main" part of the code you want to be running is in Rectangles.Java. This is where your run configurations will go.
11+
12+
3) Add two run configurations called "Client" and "Server". The "Server" one needs the command line argument 'server' passed to it.
13+
14+
4) Run the project, selecting "Server" run configuration.
15+
16+
5) Run as many clients as you want with the "Client" run configuration.
17+
18+
6) Now you can play with it like so:
19+
20+
Arrow Keys: move
21+
Space: Jump (Notice the cool gravity and bounce affects? :D)
22+
'q': Iterate the number printed on the screen. This is just a simple way to demonstrate world state between clients.
23+
24+
25+
26+
Note (Untested): If not using eclipse, you will have to compile everything in the terminal, being sure to connect processing. I am not entirely sure how to do that but it should work. Then just manually enter the command line arguments.

rectangles/GameObj.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import processing.core.PShape;
22

3-
import java.util.ArrayList;
43

54
import processing.core.PApplet;
6-
import processing.core.PVector;
75

86
public class GameObj extends PApplet {
97
private Physics py;

rectangles/Rectangles.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import java.io.IOException;
33
import java.net.Socket;
44
import java.util.ArrayList;
5-
import java.util.concurrent.Executor;
65
import java.util.concurrent.ExecutorService;
76
import java.util.concurrent.Executors;
87

@@ -138,7 +137,6 @@ public void keyPressed() {
138137
this.square.getPy().setAccelerationY(-20);
139138
}
140139
if (key == 'q') {
141-
System.out.println("Q Pressed");
142140
this.localClient.iterNumIter();
143141
if (!this.isServer) {
144142
this.localClient.write(this.localClient.getNumIter());

rectangles/networking/Client.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package networking;
2-
import java.io.BufferedInputStream;
3-
import java.io.BufferedOutputStream;
2+
43
import java.io.DataInputStream;
54
import java.io.DataOutputStream;
5+
import java.io.EOFException;
66
import java.io.IOException;
77
import java.net.Socket;
8+
import java.net.SocketException;
89
import java.util.concurrent.ExecutorService;
910

1011
public class Client implements Runnable {
@@ -72,7 +73,11 @@ public void run() {
7273
try {
7374
// TODO: Just keeping track of a number for now
7475
synchronized (this.input) {
75-
this.threadPool.execute(new ClientRead(this.input.readInt(), this.trackClient));
76+
try {
77+
this.threadPool.execute(new ClientRead(this.input.readInt(), this.trackClient));
78+
} catch (EOFException | SocketException e) {
79+
// Ignore, client has just disconnected
80+
}
7681
}
7782
} catch (IOException e) {
7883
System.out.print("Error reading from socket: " + this.socket.toString() + ": " + e.toString());
@@ -132,6 +137,8 @@ public void run() {
132137
synchronized (this.getClient().output) {
133138
try {
134139
this.getClient().output.writeInt(this.data);
140+
} catch (SocketException e) {
141+
// Ignore client has just disconnected
135142
} catch (IOException e) {
136143
System.out.println("Error writing to socket: " + this.getClient().socket.toString());
137144
e.printStackTrace();

rectangles/networking/ThreadPoolClient.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

rectangles/networking/UpdateClients.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

rectangles/networking/WorkerRunnable.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)