move board size out of player constructor
This commit is contained in:
parent
3eeb4d25bd
commit
2c6f9adf54
|
@ -17,7 +17,7 @@ public class GameController {
|
|||
"1.1.0", OnlinePlayer_1_1_0.class
|
||||
));
|
||||
|
||||
public void startOnlineGame(Class<? extends LocalPlayer> localPlayerClass, InetSocketAddress address) throws IOException {
|
||||
public void startOnlineGame(Class<? extends LocalPlayer> localPlayerClass, InetSocketAddress address, int size) throws IOException {
|
||||
AsyncSocket clientSocket;
|
||||
|
||||
boolean localPlayerIsServer = address.getHostName() == null;
|
||||
|
@ -34,7 +34,7 @@ public class GameController {
|
|||
serverSocket.close();
|
||||
} else {
|
||||
// CLIENT MODE
|
||||
|
||||
|
||||
Socket socket = new Socket();
|
||||
|
||||
try {
|
||||
|
@ -71,7 +71,7 @@ public class GameController {
|
|||
OnlinePlayer onlinePlayer;
|
||||
try {
|
||||
localPlayer = localPlayerClass.getDeclaredConstructor().newInstance();
|
||||
onlinePlayer = onlinePlayerClass.getDeclaredConstructor().newInstance();
|
||||
onlinePlayer = onlinePlayerClass.getDeclaredConstructor().newInstance((Integer)size, clientSocket);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Unable to instantiate players");
|
||||
|
@ -161,6 +161,10 @@ public class GameController {
|
|||
e.printStackTrace();
|
||||
throw new RuntimeException("Unable to instantiate players");
|
||||
}
|
||||
|
||||
localPlayer.createBoard(size);
|
||||
aiPlayer.createBoard(size);
|
||||
|
||||
startGameWithInstancedPlayers(localPlayer, aiPlayer);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ public abstract class OnlinePlayer extends Player implements AsyncSocketListener
|
|||
private AsyncSocket socket;
|
||||
|
||||
public OnlinePlayer(int size, AsyncSocket socket) {
|
||||
super(size);
|
||||
this.socket = socket;
|
||||
//TODO Auto-generated constructor stub
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Player {
|
||||
protected boolean myTurn;
|
||||
|
@ -9,7 +8,9 @@ public abstract class Player {
|
|||
protected String name;
|
||||
protected Board board;
|
||||
|
||||
public Player(int size) {
|
||||
public Player() {}
|
||||
|
||||
public void createBoard(int size) {
|
||||
this.board = new Board(size);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue