some cleanup
This commit is contained in:
parent
fdd2e6d2f1
commit
20732e730c
|
@ -1,4 +1,8 @@
|
|||
|
||||
public class HumanPlayer extends LocalPlayer {
|
||||
|
||||
@Override
|
||||
public void shoot(Point point) {
|
||||
this.myTurn = false;
|
||||
enemy.receiveShoot(point);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ public class LocalPlayer extends Player {
|
|||
|
||||
@Override
|
||||
public synchronized void receiveShoot(Point point) {
|
||||
if (!this.enemy.myTurn) return;
|
||||
|
||||
HitResponse hitResponse = board.getHitResponseOnPoint(point);
|
||||
if (!(hitResponse == null)){
|
||||
enemy.receiveHit(hitResponse);
|
||||
|
@ -46,10 +48,13 @@ public class LocalPlayer extends Player {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sends shot to enemy player.
|
||||
* should ONLY be called on HumanPlayer
|
||||
*/
|
||||
@Override
|
||||
public void shoot(Point point){
|
||||
this.myTurn = false;
|
||||
enemy.receiveShoot(point);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,4 +25,10 @@ public abstract class OnlinePlayer extends Player implements AsyncSocketListener
|
|||
@Override
|
||||
public abstract void receiveCoin(boolean coin);
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
this.socket.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
|||
case "COIN":
|
||||
if(!this.hasReceivedCoinPackage && (p.getData().equals("1") || p.getData().equals("0"))){
|
||||
this.myCoin = p.getData().equals("1");
|
||||
this.ready();
|
||||
this.hasReceivedCoinPackage = true;
|
||||
this.ready();
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -75,6 +75,7 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
|||
|
||||
@Override
|
||||
public synchronized void receiveShoot(Point point){
|
||||
if (!this.enemy.myTurn) return;
|
||||
super.socket.send(new SocketPackage("SHOOT",point.toString()));
|
||||
}
|
||||
|
||||
|
@ -94,6 +95,7 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
|||
|
||||
@Override
|
||||
public synchronized void shoot(Point point) {
|
||||
super.socket.send(new SocketPackage("SHOOT", point.toString()));
|
||||
// SHOULD NEVER BE CALLED ON ONLINE PLAYER. ONLY ON HUMAN PLAYER
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -77,4 +77,11 @@ public abstract class Player {
|
|||
public boolean isReady() {
|
||||
return this.sentCoin;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
this.myTurn = false;
|
||||
this.gameRunning = false;
|
||||
this.board = null;
|
||||
this.enemy = null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue