コード例 #1
0
ファイル: Client.java プロジェクト: rudolf1/JCloisterZone
 public void handleLoad() {
     JFileChooser fc = new JFileChooser(System.getProperty("user.dir") + System.getProperty("file.separator") + "saves");
     fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
     fc.setDialogTitle(_("Load game"));
     fc.setDialogType(JFileChooser.OPEN_DIALOG);
     fc.setFileFilter(new SavegameFileFilter());
     fc.setLocale(getLocale());
     int returnVal = fc.showOpenDialog(this);
     if (returnVal == JFileChooser.APPROVE_OPTION) {
         File file = fc.getSelectedFile();
         if (file != null) {
             if (!closeGame()) return;
             try {
                 localServer = new Server(new Snapshot(file));
                 localServer.start(config.getPort());
                 connect(InetAddress.getLocalHost(), config.getPort());
             } catch (SnapshotVersionException ex1) {
                 //do not create error.log
                 JOptionPane.showMessageDialog(this, ex1.getLocalizedMessage(), _("Error"), JOptionPane.ERROR_MESSAGE);
             } catch (Exception ex) {
                 logger.error(ex.getMessage(), ex);
                 JOptionPane.showMessageDialog(this, ex.getLocalizedMessage(), _("Error"), JOptionPane.ERROR_MESSAGE);
             }
         }
     }
 }
コード例 #2
0
ファイル: Client.java プロジェクト: rudolf1/JCloisterZone
 public void createGame() {
     if (!closeGame()) return;
     try {
         localServer = new Server(config);
         localServer.start(config.getPort());
         connect(InetAddress.getLocalHost(), config.getPort());
     } catch (IOException e) {
         logger.error(e.getMessage(), e);
         JOptionPane.showMessageDialog(this, e.getMessage(), _("Error"), JOptionPane.ERROR_MESSAGE);
         closeGame(true);
     }
 }
コード例 #3
0
ファイル: Client.java プロジェクト: rudolf1/JCloisterZone
    public boolean closeGame(boolean force) {
        boolean isGameRunning = getJMenuBar().isGameRunning();
        if (config.getConfirm().getGame_close() && isGameRunning && !(game.getPhase() instanceof GameOverPhase)) {
            if (localServer != null) {
                String options[] = {_("Close game"), _("Cancel") };
                int result = JOptionPane.showOptionDialog(this,
                        _("Game is running. Do you really want to quit game and also disconnect all other players?"),
                        _("Close game"),
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
                if (JOptionPane.OK_OPTION != result) return false;
            } else {
                String options[] = {_("Close game"), _("Cancel") };
                int result = JOptionPane.showOptionDialog(this,
                        _("Game is running. Do you really want to leave it?"),
                        _("Close game"),
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
                if (JOptionPane.OK_OPTION != result) return false;
            }
        }

        setTitle(BASE_TITLE);
        resetWindowIcon();
        if (localServer != null) {
            localServer.stop();
            localServer = null;
        } else if (server != null) {
             getClientStub().stop();
        }
        server = null;
        activePlayer = null;
        getJMenuBar().setIsGameRunning(false);
        if (controlPanel != null) {
            controlPanel.closeGame();
            mainPanel.closeGame();
        }
        if (discardedTilesDialog != null) {
            discardedTilesDialog.dispose();
            discardedTilesDialog = null;
            getJMenuBar().setShowDiscardedEnabled(false);
        }
        return true;
    }