Browse Source

Added Synchronized Methods

Kenneth van Ewijk 10 years ago
parent
commit
6596d2dc83

+ 1 - 1
server/server/match/Match.java

@@ -94,7 +94,7 @@ public class Match implements Runnable {
 	}
 
 	/* UPDATE */
-	public void update() {
+	synchronized public void update() {
 		if (player1.getHealth() == 0 && player2.getHealth() == 0) {
 			return;
 		}

+ 1 - 1
src/model/NetworkConnection.java

@@ -64,7 +64,7 @@ public class NetworkConnection {
 	}
 
 	// Receive a message from the server and decode it
-	private void receiveMessage() {
+	synchronized private void receiveMessage() {
 		try {
 			String message = din.readUTF();
 			String[] messagesplit = message.split("\\|"); // 2

+ 1 - 1
src/model/objects/Ball.java

@@ -65,7 +65,7 @@ public class Ball {
 	}
 
 	// Update info based on network data
-	public void updateInfo(int x, int y, Color color, int size) {
+	synchronized public void updateInfo(int x, int y, Color color, int size) {
 		setX(x);
 		setY(y);
 		this.color = color;

+ 4 - 4
src/model/state/PlayState.java

@@ -75,14 +75,14 @@ public class PlayState extends State {
 	}
 
 	/* UPDATE AND PAINTING */
-	public void updatePlayerInfo(int x, int y, int health, int score, Player player) {
+	synchronized public void updatePlayerInfo(int x, int y, int health, int score, Player player) {
 		player.setX(x);
 		player.setY(y);
 		player.setHealth(health);
 		player.setScore(score);
 	}
 
-	public void updateLines(int l1x, int l1y, int l1h, int l2x, int l2y, int l2h) {
+	synchronized public void updateLines(int l1x, int l1y, int l1h, int l2x, int l2y, int l2h) {
 		if (line1 == null)
 			line1 = new ShootingLine(l1x, l1y);
 		line1.setLength(l1h);
@@ -96,7 +96,7 @@ public class PlayState extends State {
 	}
 
 	@Override
-	public void update() {
+	synchronized public void update() {
 		if (player1 != null && player2 != null) {
 			if (player1.getHealth() == 0 && player2.getHealth() == 0) {
 				setOverlayText("Game over");
@@ -107,7 +107,7 @@ public class PlayState extends State {
 	}
 
 	@Override
-	public void paint(Graphics2D g2d) {
+	synchronized public void paint(Graphics2D g2d) {
 		g2d.drawImage(Images.getImage(ImageType.BACKGROUND), null, 0, 0);
 		g2d.setColor(Color.RED);
 		g2d.drawString(overlayText, 100, 300);