jancoow преди 10 години
родител
ревизия
dddeb73fe4

+ 23 - 12
server/server/match/Match.java

@@ -90,16 +90,27 @@ public class Match implements Runnable {
 
 	/* UPDATE */
 	public void update() {
-		if (p1direction == 1)
-			player1.walkRight();
-		else if (p1direction == -1)
-			player1.walkLeft();
-		player1.update();
-		if (p2direction == 1)
-			player2.walkRight();
-		else if (p2direction == -1)
-			player2.walkLeft();
-		player2.update();
+		if(player1.getHealth()  == 0 && player2.getHealth() == 0){
+			return;
+		}
+		if(player1.getHealth() > 0){
+			if (p1direction == 1)
+				player1.walkRight();
+			else if (p1direction == -1)
+				player1.walkLeft();
+			player1.update();
+		}else{
+			player1.setY(-100);
+		}
+		if(player2.getHealth() > 0){
+			if (p2direction == 1)
+				player2.walkRight();
+			else if (p2direction == -1)
+				player2.walkLeft();
+			player2.update();
+		}else{
+			player2.setY(-100);
+		}
 
 		if (line1 != null) {
 			line1.setLength(line1.getLength() + 1);
@@ -216,10 +227,10 @@ public class Match implements Runnable {
 	}
 
 	public void playerShoot(int pid) {
-		if (pid == 1)
+		if (pid == 1 && player1.getHealth() > 0)
 			if(line1 == null)
 				line1 = new ShootingLine(player1.getX() + player1.getWidth() / 2, player1.getY() + player1.getHeigth());
-		if (pid == 2)
+		if (pid == 2 && player2.getHealth() > 0)
 			if(line2 == null)
 				line2 = new ShootingLine(player2.getX() + player2.getWidth() / 2, player2.getY() + player2.getHeigth());
 	}

+ 0 - 2
src/model/GameStateManager.java

@@ -6,7 +6,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 import model.state.EndState;
-import model.state.MatchMakingState;
 import model.state.MenuState;
 import model.state.PlayState;
 import model.state.State;
@@ -22,7 +21,6 @@ public class GameStateManager {
 		gamestates.add(new MenuState(this));
 		gamestates.add(new PlayState(this));
 		gamestates.add(new EndState(this));
-		gamestates.add(new MatchMakingState(this));
 
 		currentState = gamestates.get(0);
 	}

+ 1 - 2
src/model/objects/Player.java

@@ -6,7 +6,7 @@ import java.awt.image.BufferedImage;
 
 public class Player extends DrawObject {
 
-	private int score, health, speed = 10;
+	private int score, health = 10;
 
 	private long lastMovement;
 	private int lastDirection, frame;
@@ -39,7 +39,6 @@ public class Player extends DrawObject {
 
 	public void reset() {
 		setPosition(beginlocation);
-		speed = 10;
 	}
 
 	// ** Getters and Setters **//

+ 0 - 88
src/model/state/MatchMakingState.java

@@ -1,88 +0,0 @@
-package model.state;
-
-import java.awt.Graphics2D;
-import java.awt.event.KeyEvent;
-import java.io.IOException;
-import java.net.UnknownHostException;
-
-import model.GameStateManager;
-import model.NetworkConnection;
-
-public class MatchMakingState extends State {
-	
-	public static NetworkConnection nwc = null;
-	boolean failed = false;
-	boolean draw = false;
-	String message = "";
-
-	public MatchMakingState(GameStateManager gsm) {
-		super("match", gsm);
-	}
-
-	@Override
-	public void init() {
-		if(!draw)
-			return;
-		
-		nwc = new NetworkConnection((PlayState) gsm.getState("play"));
-			try {
-				nwc.connect(MenuState.name);
-			} catch (UnknownHostException e) {
-				failed = true;
-				message = "Server is offline";
-			} catch (IOException e) {
-				failed = true;
-				message  = "Something went wrong while trying to connect";
-			}
-			failed = false;
-			message = "";
-			
-			if(!failed)
-				gsm.setState("play");
-	}
-
-	@Override
-	public void exit() {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void update() {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void paint(Graphics2D g2) {
-		g2.drawString("Waiting on match", 100, 100);
-		
-		if(failed)
-		{
-			g2.drawString(message, 100, 300);
-			g2.drawString("Press any key to continue", 100, 500);
-		}
-		
-		draw = true;
-		init();
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		if(failed)
-			gsm.setState("menu");
-	}
-
-	@Override
-	public void keyReleased(KeyEvent e) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void keyTyped(KeyEvent e) {
-		// TODO Auto-generated method stub
-
-	}
-
-}

+ 1 - 1
src/model/state/MenuState.java

@@ -58,7 +58,7 @@ public class MenuState extends State {
 	@Override
 	public void keyPressed(KeyEvent e) {
 		if (e.getKeyCode() == KeyEvent.VK_ENTER) {
-			gsm.setState("match");
+			gsm.setState("play");
 		}
 		
 		if(e.getKeyCode() == KeyEvent.VK_BACK_SPACE && name.length() > 0)

+ 3 - 1
src/model/state/PlayState.java

@@ -50,7 +50,6 @@ public class PlayState extends State {
 	/* INIT AND EXIT */
 	@Override
 	public void init() {
-		nwc = MatchMakingState.nwc;
 		matchStarted = false;
 		nwc = new NetworkConnection(this);
 		try {
@@ -92,6 +91,9 @@ public class PlayState extends State {
 
 	@Override
 	public void update() {
+		if(player1.getHealth()  == 0 && player2.getHealth() == 0){
+			setOverlayText("Game over");
+		}
 		player1.update();
 		player2.update();
 	}