cleanup-work #22

Merged
lgc merged 12 commits from cleanup-work into main 2024-12-22 23:06:00 +00:00
5 changed files with 29 additions and 5 deletions
Showing only changes of commit 20732e730c - Show all commits

View File

@ -1,4 +1,8 @@
public class HumanPlayer extends LocalPlayer {
@Override
public void shoot(Point point) {
this.myTurn = false;
enemy.receiveShoot(point);
}
}

View File

@ -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

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}