cleanup-work #22
|
@ -1,4 +1,8 @@
|
||||||
|
|
||||||
public class HumanPlayer extends LocalPlayer {
|
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
|
@Override
|
||||||
public synchronized void receiveShoot(Point point) {
|
public synchronized void receiveShoot(Point point) {
|
||||||
|
if (!this.enemy.myTurn) return;
|
||||||
|
|
||||||
HitResponse hitResponse = board.getHitResponseOnPoint(point);
|
HitResponse hitResponse = board.getHitResponseOnPoint(point);
|
||||||
if (!(hitResponse == null)){
|
if (!(hitResponse == null)){
|
||||||
enemy.receiveHit(hitResponse);
|
enemy.receiveHit(hitResponse);
|
||||||
|
@ -46,10 +48,13 @@ public class LocalPlayer extends Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sends shot to enemy player.
|
||||||
|
* should ONLY be called on HumanPlayer
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void shoot(Point point){
|
public void shoot(Point point){
|
||||||
this.myTurn = false;
|
return;
|
||||||
enemy.receiveShoot(point);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,4 +25,10 @@ public abstract class OnlinePlayer extends Player implements AsyncSocketListener
|
||||||
@Override
|
@Override
|
||||||
public abstract void receiveCoin(boolean coin);
|
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":
|
case "COIN":
|
||||||
if(!this.hasReceivedCoinPackage && (p.getData().equals("1") || p.getData().equals("0"))){
|
if(!this.hasReceivedCoinPackage && (p.getData().equals("1") || p.getData().equals("0"))){
|
||||||
this.myCoin = p.getData().equals("1");
|
this.myCoin = p.getData().equals("1");
|
||||||
this.ready();
|
|
||||||
this.hasReceivedCoinPackage = true;
|
this.hasReceivedCoinPackage = true;
|
||||||
|
this.ready();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -75,6 +75,7 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void receiveShoot(Point point){
|
public synchronized void receiveShoot(Point point){
|
||||||
|
if (!this.enemy.myTurn) return;
|
||||||
super.socket.send(new SocketPackage("SHOOT",point.toString()));
|
super.socket.send(new SocketPackage("SHOOT",point.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +95,7 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void shoot(Point point) {
|
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() {
|
public boolean isReady() {
|
||||||
return this.sentCoin;
|
return this.sentCoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void destroy() {
|
||||||
|
this.myTurn = false;
|
||||||
|
this.gameRunning = false;
|
||||||
|
this.board = null;
|
||||||
|
this.enemy = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue