예제 #1
0
  public void clickCreateIdea() {

    if (display.isDisposed()) return;

    GuiCreateIdea guiCreateIdea = new GuiCreateIdea(getPlayerId(), display, clientCore.getGame());

    guiCreateIdea.init(
        clientWhiteboard.getSelectionControl().getSelectedIdeas(),
        clientWhiteboard.getSelectionControl().getSelectedItems());

    guiCreateIdea.run();

    if (guiCreateIdea.getResultName() == null) return; // user probably cancelled

    try {
      clientCore
          .getGame()
          .addIdea(
              getPlayerId(),
              guiCreateIdea.getResultName(),
              guiCreateIdea.getResultDesc(),
              guiCreateIdea.getResultItemIds(),
              guiCreateIdea.getResultParentIds());
    } catch (Exception e) {
      displayError("error while creating the idea", e);
    }
  }
예제 #2
0
  public void clickVoteOnIdea() {

    if (display.isDisposed()) return;

    if ((clientWhiteboard.getSelectionControl().getSelectedIdeas().size()
            + clientWhiteboard.getSelectionControl().getSelectedIdeas().size())
        == 0) return;

    GuiCreateComment guicomment =
        new GuiCreateComment(getPlayerId(), display, clientCore.getGame(), clientCore);

    guicomment.init(
        clientWhiteboard.getSelectionControl().getSelectedIdeas(),
        clientWhiteboard.getSelectionControl().getSelectedComments());

    guicomment.run();

    if (guicomment.getResultName() == null) return; // user cancelled

    /*		try {
    	clientCore.getGame().addIdea(
    			getPlayerId(),
    			guiCreateIdea.getResultName(),
    			guiCreateIdea.getResultItemIds(),
    			guiCreateIdea.getResultParentIds()
    			);
    } catch (Exception e) {
    	displayError("error while creating the idea", e);
    }*/

  }
예제 #3
0
  /**
   * Connects to this game.
   *
   * @param gameBindName
   * @throws MalformedURLException
   * @throws RemoteException
   * @throws NotBoundException
   * @throws UnknownHostException
   */
  public void connectToGame(String gameBindName)
      throws MalformedURLException, RemoteException, NotBoundException, UnknownHostException {

    try {
      clientCore.connectToGame(gameBindName);

      clientWhiteboard.setGame(clientCore.getGame());

      clientCore.getGame().addListener(this);

      setClientMode(GuiClientMode.MONITOR);
      this.gameBindName = gameBindName;

    } catch (RuntimeException e) {

      // update info relative to the game.
      setClientMode(GuiClientMode.DISCONNECTED);
      this.gameBindName = null;

      throw e;
    }
  }
예제 #4
0
  private void clickJoin() {

    GuiCreatePlayer guiConnect = new GuiCreatePlayer(this.clientCore, display);
    guiConnect.init();
    guiConnect.run();

    String name = guiConnect.getName();
    String avatar = guiConnect.getAvatarFile();

    if ((name == null) || (avatar == null)) return;

    try {
      Integer id = clientCore.getGame().addPlayer(name, avatar);
      setPlayerId(id);
      setClientMode(GuiClientMode.PLAYING);

    } catch (Exception e) {
      displayError("Error while adding this player, sorry", e);
    }
  }
예제 #5
0
        @Override
        public void work(DefaultMutableTreeNode node, int depth) {
          if (depth != 0) {
            IComment com = (IComment) node.getUserObject();

            StringBuilder sb = new StringBuilder();
            try {
              sb.append(clientCore.getGame().getPlayer(com.getPlayerId()).getShortName());
              sb.append(": ");
            } catch (RemoteException e) {
              sb.append("???: ");
            }

            int tokens = com.getTokensCount();
            if (tokens > 0) {
              sb.append(" [+");
              sb.append(tokens);
              sb.append("] ");
            } else if (tokens < 0) {
              sb.append(" [");
              sb.append(tokens);
              sb.append("] ");
            }
            sb.append(com.getText());

            TreeItem item = new TreeItem(treeItems.peek(), SWT.NONE);
            item.setText(sb.toString());
            // System.out.println("build tree item: "+sb.toString());
            treeItems.push(item);
          }

          @SuppressWarnings("unchecked")
          Enumeration<DefaultMutableTreeNode> children = node.children();
          while (children.hasMoreElements()) {
            work(children.nextElement(), depth + 1);
          }

          treeItems.pop().setExpanded(true);
        }
예제 #6
0
  private void clickCreateItem() {

    if (display.isDisposed()) return;

    GuiCreateItem.manageCreateItem(display, clientCore.getGame(), getPlayerId());
  }
예제 #7
0
  private void clickDisconnect() {

    clientCore.disconnectFromGame();

    setClientMode(GuiClientMode.DISCONNECTED);
  }
예제 #8
0
  /** NB: should always be called from the SWT thread. */
  public void majScores() {
    if (modeClient != GuiClientMode.PLAYING) // quick exit
    return;

    try {
      if (clientCore.getGame().getPlayer(getPlayerId()) != null) {
        int i = 0;
        @SuppressWarnings("unused")
        Map<Integer, Double> sctab, sccop;
        for (TypeScore sc : TypeScore.values()) {
          sctab = sc.calculer(clientCore.getGame());

          double scval = sctab.get(getPlayerId());
          // ArrayList val=new ArrayList(sctab.values());
          // Collections.sort(val);

          SortedSet<PlayersScores> sortedScores = PlayersScores.calculer(sctab);

          int rgval = PlayersScores.computeRank(sortedScores, getPlayerId());
          StringBuilder sb = new StringBuilder(sc.nom + '\n');
          @SuppressWarnings("unused")
          int idj;
          int rankCurrent = 1;
          for (PlayersScores currentScore : sortedScores) {
            sb.append(rankCurrent);
            sb.append(": ");
            sb.append(clientCore.getGame().getPlayer(currentScore.idplayer).getShortName());
            sb.append(" (");
            sb.append(currentScore.score);
            sb.append(")\n");
            rankCurrent++;
          }
          TXT_TOOLTIP_HIGH_SCORE.set(i, sb.toString());

          scoreslab[i].setText(sc.nom + "");
          scores[i].setText(" " + (int) scval);
          //				scoreevo[i].setText(" (=)");
          if (scvalprec.get(i) > scval) {
            scoreevo[i].setText("(" + ((int) (scval - scvalprec.get(i))) + ")");
            scoreevo[i].setForeground(display.getSystemColor(SWT.COLOR_RED));
          }
          /*				if (scvalprec.get(i)==scval)
          {
          	scoreevo[i].setText(" (=)");
          	scoreevo[i].setForeground(display.getSystemColor(SWT.COLOR_DARK_GRAY));

          }*/
          if (scvalprec.get(i) < scval) {
            scoreevo[i].setText("(+" + ((int) (scval - scvalprec.get(i))) + ")");
            scoreevo[i].setForeground(display.getSystemColor(SWT.COLOR_BLUE));
          }
          rglab[i].setText(" Rg ");
          rg[i].setText("" + rgval);
          if (scrgprec.get(i) > rgval) {
            rgevo[i].setText("(" + ((int) (rgval - scrgprec.get(i))) + ")");
            rgevo[i].setForeground(display.getSystemColor(SWT.COLOR_BLUE));
          }
          /*				if (scrgprec.get(i)==rgval)
          {
          	rgevo[i].setText(" (=)");
          	rgevo[i].setForeground(display.getSystemColor(SWT.COLOR_DARK_GRAY));

          }*/
          if (scrgprec.get(i) < rgval) {
            rgevo[i].setText("(+" + ((int) (rgval - scrgprec.get(i))) + ")");
            rgevo[i].setForeground(display.getSystemColor(SWT.COLOR_RED));
          }
          scvalprec.put(i, scval);
          scrgprec.put(i, (double) rgval);
          scores[i].setToolTipText(TXT_TOOLTIP_HIGH_SCORE.get(i));
          scoreslab[i].setToolTipText(sc.tooltip);
          i++;
        }
      }
    } catch (RemoteException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }