passing info between server/client problem
I am creating the board game diplomacy and I have run into a problem that I can't figure out. It might have to do with my limited knowledge of networking and threads but I will try to only post the relevant info.
I have a Board class which creates all of the Territorys in the game. I have a Player class which creates of all the units for each player. The GameJudge class keeps track of all this information.
When the game starts, the server creates the board and then assigns each client to be a different player. It then stores this information in a class called StartGameVariables and passes this to each client. When the client recieves this information it updates its respective variables in GameJudge.
When its time to process the moves for each player's units, each client sends their player info to the server:
Code:
_output is an ObjectOutputStream
player is the player for this client
public void writeToHostGameJudge(Player player){
try {
_output.writeObject(player);
_output.flush();
}
catch(SocketException e){
System.out.println("Exited16");
}
catch (IOException e){
System.out.println("Exited15");
}
}
When the server recieves this info it updates each clients' player because it keeps track of what each client is doing with their units. Once it has received every clients' info, it then processes the moves and passes each client the now updated Board and the updated Players:
Code:
_numUpdatePlayer is an integer representing how many times this was called
_numPlayers is an integer representing the number of clients
public void updatePlayers(Player clientPlayer){
for(int x=0; x<_gameJudge.getPlayers().length; x++){
if(clientPlayer.Name().equals(_gameJudge.getPlayers()[x].Name())){
_gameJudge.getPlayers()[x] = clientPlayer;
_numUpdatePlayers++;
}
}
if(_numUpdatePlayers == _numPlayers){
_gameJudge.ProcessOrders();
**Writes info back to clients here regarding Players and the Board**
}
}
The problem comes when it is time to process the moves. The server knows all the moves for every unit because each client passed it thier unit's moves when it passed it's player to the server. The clients' units however don't interact because apparently they are refering to a different board.
For example:
player[1] is the server
player[2] is a client
player[1].getUnit(0).getCurrentTerritory() - it will display the name the of the territory unit 0 is in.
So when I loop through every territory in the game and compare territory[x] to a unit's current territory, if they are equal it should output "WORKS":
Code:
for(int x=0; x<_board.getTerritory().length; x++){
if(_board.getTerritory()[x].equals(player[1].getUnit(0).getCurrentTerritory()){
System.out.println("WORKS");
}
}
It works fine for player[1], but if i replace player[1] with player[2] is does not diplay anything even though player[2].getUnit(0).getCurrentTerritory() displays the name of the territory it is currently in. I don't understand how player[2]'s units can be refering to a different territory when I passed each client the same info that the server has.