Merge pull request 'hotfixes - so we can at least run it' (#9) from hotfixes into main
Reviewed-on: #9
This commit is contained in:
commit
d425e64fa0
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue