Up Previous Next

Previous stage contains a subtle error.

Explain it, fix it. First:

  int size = -1; 
  public void broadcast(int id, int x, int y, String action) throws RemoteException {
    for (int i = 0; i <= size; i++) {
      clients[i].update(id, x, y, action); 
    } 
  } 
The interface needs to be consistent:
import java.rmi.*;

public interface ClientInterface extends Remote{
  public void update(int player, int x, int y, String action) throws RemoteException;  
} 
And so needs to be the implementation:
  public void update(int player, int x, int y, String action) {
    System.out.println("Player " + this.id + " updated by player " + player + " with action: " + action); 
    if (players[player] == null) {
      players[player] = new Penguin(x, y, 30, 30, "(" + this.id + ", " + player + ")"); 
      players[player].placeIn(this);
      this.repaint(); 
    } else { 
      players[player].perform(action); 
    } 
  }
With this we see the exact nature of the bug:

New clients don't receive existing information about the world from server, earlier clients.

So last picture, with most penguins, is the oldest (first to be created).


Up Previous Next