this.server.sendReadyMulti(this.player.getID());
}
public void launchGameMulti() throws RemoteException, InterruptedException {
final PlayerPanel ppanel = this.mainFrame.getPlayerPanel();
this.panel.getButton("Ready").setText(getGameLang("Launched"));
ppanel.getButton("Help").setEnabled(true);
ppanel.getButton("Game Over").setEnabled(true);
ppanel.getButton("Reset").setEnabled(true);
ppanel.getScorePanel().setVisible(false);
this.game.board().setDictionary(this.game.dictionary());
if (this.client != null) {
this.game.board().addObserver((ClientImpl) this.client);
}
for (int i = 0; i < Rack.MAX_RACK_LETTERS; i++) {
this.player.getRack().addLetter(this.server.pickLetter());
}
// If server creator, start playing or wait for turn
if (this.serverCreator) {
this.server.setPlayertable(
this.player.getID(), null, getGameLang("Playing"), -1);
this.isMyTurn = true;
}
else {
this.server.setPlayertable(
this.player.getID(), null, getGameLang("Thinking"), -1);
this.isMyTurn = false;
ppanel.lock();
}
this.mainFrame.setPlayerPanelPlayer(this.player);
ppanel.getButton("Game Over").addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (mainFrame.getGameSelection() == 2) {
try {
mainFrame.getMultiplayerPanel().getAction().disconnect();
}
catch (RemoteException ex) {
Display.error("Server", "Error while disconnecting !");
}
catch (MalformedURLException ex) {
Display.error("Server", "Error while disconnecting !");
}
}
}
});
// Change turn when pick
ppanel.getButton("Validate").addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (mainFrame.getGameSelection() == 2) {
try {
try {
player.validate();
player.endTurn(true);
}
catch (BoardWrongWordPlace ex) {
Display.error(
"Multiplayer", "This word doesn't exists !");
return;
}
int len = Rack.MAX_RACK_LETTERS - player.getRack().getLetters().length();
for (int i = 0; i < len; i++) {
Letter letter = server.pickLetter();
if (letter != null) {
player.getRack().addLetter(letter);
}
}
ppanel.getButton("Validate").setEnabled(false);
ppanel.getButton("Cancel").setEnabled(false);
ppanel.getButton("Reset").setEnabled(false);
ppanel.getButton("Game Over").setEnabled(true);
panel.endTurn();
server.setPlayertable(player.getID(), player.getName(),
null, player.getScore());
}
catch (RemoteException ex) {
Display.error(
"Multiplayer", "Error while changing player turn !");
}
}
}
});
ppanel.getButton("Reset").addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (mainFrame.getGameSelection() == 2) {
List<Integer> selectedLetters = ppanel.action().getLettersToReset();
Iterator<Integer> itr = selectedLetters.iterator();
while (itr.hasNext()) {
int letterToReset = itr.next();
Letter letter = player.getRack().getLetter(letterToReset);
if (letter != null) {
try {
Letter let = server.exchangeLetter(letter);
player.getRack().changeLetter(letterToReset, let);
}
catch (RemoteException ex) {
Display.error("Reset", "Error while reseting letter.");
}
}
}
ppanel.action().clearLettersToReset();
}
}
});
this.panel.repaint();