Exemplo n.º 1
0
  public void setGame(IGame game) {
    if (this.game != null) {
      this.game.removeGameListener(gameListener);
    }
    this.game = game;
    if (game != null) {
      game.addGameListener(gameListener);

      StringBuffer b = new StringBuffer();
      IPlayer[] players = game.getPlayers();
      for (int i = 0; i < players.length; i++) {
        IPlayer player = players[i];
        if (i > 0) b.append(" vs ");
        b.append(player.getName());
      }
      final String title = b.toString();

      // TODO unnecessary thread sync?
      exec(
          new Runnable() {
            public void run() {
              setPartName(title);
            };
          });
    }
    updateTileRack();

    MoveListView moveListView = (MoveListView) getSite().getPage().findView(MoveListView.ID);
    if (moveListView != null) {
      moveListView.setGame(game);
    }

    TilePoolView tilePoolView = (TilePoolView) getSite().getPage().findView(TilePoolView.ID);
    if (tilePoolView != null) {
      tilePoolView.setGame(game);
    }

    AnalysisView analysisView = (AnalysisView) getSite().getPage().findView(AnalysisView.ID);
    if (analysisView != null) {
      analysisView.setGame(game);
    }
  }
Exemplo n.º 2
0
 private ITileRack getLocalTileRack() {
   IPlayer player = game.getLocalPlayer();
   if (player == null) return null;
   return player.getTileRack();
 }
Exemplo n.º 3
0
  private void drawPlayerStats(GC gc, Rectangle bounds, IPlayer player, int align) {
    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;
    int p = w / 32;

    Color fillColor = null;
    Color handleColor = null;
    Color scoreColor = null;
    Color clockColor = null;

    if (game.getGameState() == GameState.ENDED) {
      if (player == game.getWinner()) {
        fillColor = new Color(null, 0, 164, 0);
        handleColor = new Color(null, 255, 255, 255);
        scoreColor = new Color(null, 255, 255, 255);
        clockColor = new Color(null, 255, 255, 255);
      } else {
        fillColor = new Color(null, 164, 0, 0);
        handleColor = new Color(null, 255, 255, 255);
        scoreColor = new Color(null, 255, 255, 255);
        clockColor = new Color(null, 255, 255, 255);
      }
    } else {
      if (player == game.getCurrentPlayer()) {
        fillColor = new Color(null, 0, 0, 192);
        handleColor = new Color(null, 205, 205, 255);
        scoreColor = new Color(null, 255, 255, 255);
        clockColor = new Color(null, 215, 215, 215);
      } else {
        fillColor = new Color(null, 153, 153, 153);
        handleColor = new Color(null, 0, 0, 128);
        scoreColor = new Color(null, 0, 0, 0);
        clockColor = new Color(null, 0, 0, 0);
      }
    }

    // fill
    gc.setBackground(fillColor);
    gc.fillRoundRectangle(x, y, w, h, border + 1, border + 1);

    // draw handle
    int n = h / 4;
    Font font = new Font(null, "Arial", n, SWT.BOLD);
    String s = player.getName();
    gc.setFont(font);
    gc.setForeground(handleColor);
    Point extent = gc.stringExtent(s);
    if (align == SWT.LEFT) {
      gc.drawString(s, x + p, y, true);
    } else {
      gc.drawString(s, x + w - p - extent.x, y, true);
    }
    font.dispose();

    // save width
    int i = extent.x + p;

    // draw clock
    font = new Font(null, "Courier New", n, SWT.BOLD);
    s = player.getClock().toString();
    gc.setFont(font);
    gc.setForeground(clockColor);
    extent = gc.stringExtent(s);
    if (align == SWT.LEFT) {
      gc.drawString(s, x + p, y + h - extent.y, true);
    } else {
      gc.drawString(s, x + w - p - extent.x, y + h - extent.y, true);
    }
    font.dispose();

    // draw score
    font = new Font(null, "Arial", h / 2, SWT.BOLD);
    s = Integer.toString(player.getScore());
    gc.setFont(font);
    gc.setForeground(scoreColor);
    extent = gc.stringExtent(s);
    if (align == SWT.LEFT) {
      gc.drawString(s, x + i + (w - i) / 2 - extent.x / 2, y + h / 2 - extent.y / 2, true);
    } else {
      gc.drawString(s, x + (w - i) / 2 - extent.x / 2, y + h / 2 - extent.y / 2, true);
    }
    font.dispose();

    fillColor.dispose();
    handleColor.dispose();
    scoreColor.dispose();
    clockColor.dispose();
  }