hotfixes - so we can at least run it #9

Merged
lgc merged 3 commits from hotfixes into main 2024-11-27 12:01:15 +00:00
5 changed files with 28 additions and 7 deletions

View File

@ -7,8 +7,15 @@ public class GameController {
public void startLocalGame(Class<? extends LocalPlayer> localPlayerClass, Class<? extends AiPlayer> enemyClass, int size) throws InstantiationException, IllegalAccessException { public void startLocalGame(Class<? extends LocalPlayer> localPlayerClass, Class<? extends AiPlayer> enemyClass, int size) throws InstantiationException, IllegalAccessException {
LocalPlayer localPlayer = localPlayerClass.newInstance(); LocalPlayer localPlayer;
AiPlayer aiPlayer = enemyClass.newInstance(); AiPlayer aiPlayer;
try {
localPlayer = localPlayerClass.getDeclaredConstructor().newInstance();
aiPlayer = enemyClass.getDeclaredConstructor().newInstance();
} catch (Exception e) {
e.printStackTrace();
return;
}
localPlayer.setEnemy(aiPlayer); localPlayer.setEnemy(aiPlayer);
aiPlayer.setEnemy(localPlayer); aiPlayer.setEnemy(localPlayer);
} }

View File

@ -2,4 +2,10 @@ import java.net.Socket;
public abstract class OnlinePlayer extends Player{ public abstract class OnlinePlayer extends Player{
private Socket socket; private Socket socket;
public OnlinePlayer(int size, Socket socket) {
super(size);
this.socket = socket;
//TODO Auto-generated constructor stub
}
} }

View File

@ -1,7 +1,7 @@
public class SpecificAiPlayer1 extends AiPlayer{ public class SpecificAiPlayerEasy extends AiPlayer{
public SpecificAiPlayer1(int size) { public SpecificAiPlayerEasy(int size) {
super(size); super(size);
} }
} }

View File

@ -1,7 +1,7 @@
public class SpecificAiPlayer1 extends AiPlayer{ public class SpecificAiPlayerHard extends AiPlayer{
public SpecificAiPlayer1(int size) { public SpecificAiPlayerHard(int size) {
super(size); super(size);
} }
} }

View File

@ -1,3 +1,6 @@
import java.util.ArrayList;
import java.util.List;
import java.awt.Point;
public class SpecificAiPlayerMedium extends AiPlayer{ public class SpecificAiPlayerMedium extends AiPlayer{
@ -13,7 +16,7 @@ public class SpecificAiPlayerMedium extends AiPlayer{
// Shoot at the enemy and receive the hit response // Shoot at the enemy and receive the hit response
enemy.receiveShoot(nextShot); enemy.receiveShoot(nextShot);
HitResponse hitResponse = enemy.board.getHitResponsOnPoint(nextShot) HitResponse hitResponse = enemy.board.getHitResponsOnPoint(nextShot);
// If it's a hit or sunk, add adjacent cells to the hitsQueue // If it's a hit or sunk, add adjacent cells to the hitsQueue
if (hitResponse.getHitResponse() == HitResponseType.HIT) { if (hitResponse.getHitResponse() == HitResponseType.HIT) {
addAdjacentPoints(nextShot); addAdjacentPoints(nextShot);
@ -58,6 +61,11 @@ public class SpecificAiPlayerMedium extends AiPlayer{
} }
} }
private boolean alreadyShot(Point p) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'alreadyShot'");
}
private boolean isValidPoint(Point point) { private boolean isValidPoint(Point point) {
return point.x >= 0 && point.x < board.getSize() && return point.x >= 0 && point.x < board.getSize() &&
point.y >= 0 && point.y < board.getSize(); point.y >= 0 && point.y < board.getSize();