Network and Frontend #10
|
@ -13,7 +13,7 @@ public class Board {
|
|||
this.createShip(size - 13);
|
||||
}
|
||||
|
||||
public HitResponse hit (Point point){
|
||||
public synchronized HitResponse hit (Point point){
|
||||
HitResponse response = new HitResponse(HitResponseType.MISS,point);
|
||||
for (int i = 0; i < this.ships.size(); i++) {
|
||||
HitResponseType type = this.ships.get(i).shootOnShip(point);
|
||||
|
@ -50,7 +50,7 @@ public class Board {
|
|||
return ships;
|
||||
}
|
||||
|
||||
public boolean addHits(HitResponse hitResponse) {
|
||||
public synchronized boolean addHits(HitResponse hitResponse) {
|
||||
if (this.getHitResponsOnPoint(hitResponse.getPoint()) == null){
|
||||
this.hits.add(hitResponse);
|
||||
return true;
|
||||
|
@ -58,7 +58,7 @@ public class Board {
|
|||
return false;
|
||||
}
|
||||
|
||||
public HitResponse getHitResponsOnPoint(Point point) {
|
||||
public synchronized HitResponse getHitResponsOnPoint(Point point) {
|
||||
for (int i = 0; i < this.hits.size(); i++){
|
||||
if (this.hits.get(i).getPoint().equals(point)){
|
||||
return this.hits.get(i);
|
||||
|
|
|
@ -13,7 +13,7 @@ public abstract class Player {
|
|||
this.board = new Board(size);
|
||||
}
|
||||
|
||||
public void receiveShoot(Point point) {
|
||||
public synchronized void receiveShoot(Point point) {
|
||||
HitResponse hitResponse = board.getHitResponsOnPoint(point);
|
||||
if (!(hitResponse == null)){
|
||||
enemy.receiveHit(hitResponse);
|
||||
|
@ -22,7 +22,7 @@ public abstract class Player {
|
|||
}
|
||||
}
|
||||
|
||||
public void receiveHit(HitResponse hitResponse) {
|
||||
public synchronized void receiveHit(HitResponse hitResponse) {
|
||||
enemy.board.addHits(hitResponse);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue