|
|
@@ -26,16 +26,13 @@ public class PlayState extends State {
|
|
|
private NetworkConnection nwc;
|
|
|
private int timeleftpercent, direction, shoot;
|
|
|
private String overlayText;
|
|
|
+ private boolean matchStarted;
|
|
|
|
|
|
public String chatMessage = "";
|
|
|
public boolean typing = false;
|
|
|
|
|
|
public PlayState(GameStateManager gsm) {
|
|
|
super("play", gsm);
|
|
|
- player1 = new Player(Images.getImage(ImageType.PLAYER1), 40, 550, "");
|
|
|
- player2 = new Player(Images.getImage(ImageType.PLAYER2), 90, 550, "");
|
|
|
- infopanel = new InfoPanel(this);
|
|
|
- balls = new ArrayList<Ball>();
|
|
|
}
|
|
|
|
|
|
/* NETWORK CONTROL */
|
|
|
@@ -44,20 +41,32 @@ public class PlayState extends State {
|
|
|
player2 = new Player(Images.getImage(ImageType.PLAYER2), 90, 550, p2);
|
|
|
infopanel = new InfoPanel(this);
|
|
|
balls = new ArrayList<Ball>();
|
|
|
-
|
|
|
typing = false;
|
|
|
chatMessage = "";
|
|
|
infopanel.clearChat();
|
|
|
+ matchStarted = true;
|
|
|
}
|
|
|
|
|
|
/* INIT AND EXIT */
|
|
|
@Override
|
|
|
public void init() {
|
|
|
nwc = MatchMakingState.nwc;
|
|
|
+ matchStarted = false;
|
|
|
+ nwc = new NetworkConnection(this);
|
|
|
+ try {
|
|
|
+ nwc.connect(MenuState.name);
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void exit() {
|
|
|
+ try {
|
|
|
+ matchStarted = false;
|
|
|
+ nwc.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/* UPDATE AND PAINTING */
|
|
|
@@ -90,6 +99,11 @@ public class PlayState extends State {
|
|
|
@Override
|
|
|
public void paint(Graphics2D g2d) {
|
|
|
g2d.drawImage(Images.getImage(ImageType.BACKGROUND), null, 0, 0);
|
|
|
+ g2d.setColor(Color.RED);
|
|
|
+ g2d.drawString(overlayText, 100, 300);
|
|
|
+ g2d.setColor(Color.black);
|
|
|
+ if(!matchStarted)
|
|
|
+ return;
|
|
|
if (line1 != null) {
|
|
|
line1.paint(g2d);
|
|
|
}
|
|
|
@@ -102,8 +116,6 @@ public class PlayState extends State {
|
|
|
player1.paint(g2d);
|
|
|
player2.paint(g2d);
|
|
|
infopanel.paint(g2d);
|
|
|
- g2d.setColor(Color.RED);
|
|
|
- g2d.drawString(overlayText, 100, 300);
|
|
|
}
|
|
|
|
|
|
/* GETTERS AND SETTERS */
|
|
|
@@ -141,6 +153,15 @@ public class PlayState extends State {
|
|
|
this.overlayText = text;
|
|
|
}
|
|
|
|
|
|
+ public void stopMatch(){
|
|
|
+ try {
|
|
|
+ nwc.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ matchStarted = false;
|
|
|
+ }
|
|
|
+
|
|
|
/* EVENTS */
|
|
|
@Override
|
|
|
public void keyPressed(KeyEvent e) {
|