Ejemplo n.º 1
0
  private void drawTileRack(GC gc, Rectangle bounds) {
    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;

    gc.setBackground(tileRackBorder);
    gc.fillRoundRectangle(x, y, w, h, border + 1, border + 1);
    gc.setBackground(tileRackFill);
    gc.fillRectangle(x + border, y + border, w - border * 2, h - border * 2);

    // TileRack tileRack = getLocalTileRack();
    if (tileRack == null) return;
    Tile[] tiles = tileRack.getTiles();

    x += border;
    y += border;
    for (int i = 0; i < tiles.length; i++) {
      Tile tile = tiles[i];
      Rectangle rectangle = new Rectangle(x, y, tileSize, tileSize);

      DragSource source = new DragSource();
      source.rectangle = rectangle;
      source.x = i;
      source.y = -1;
      source.tile = tile;
      dragSources.put(rectangle, source);

      DragTarget target = new DragTarget();
      target.rectangle = rectangle;
      target.x = i;
      target.y = -1;
      dragTargets.add(target);

      drawTile(gc, rectangle, tile);
      x += tileSize;
    }
  }
Ejemplo n.º 2
0
  private void drawTile(IBoard b, GC gc, int x, int y, int xo, int yo, int size) {
    gc.setClipping(xo, yo, size + 1, size + 1);

    Color c = background;
    if (b.getLetterMultiplier(y, x) == 2) c = doubleLetter;
    else if (b.getLetterMultiplier(y, x) == 3) c = tripleLetter;
    else if (b.getLetterMultiplier(y, x) == 4) c = quadLetter;
    else if (b.getWordMultiplier(y, x) == 2) c = doubleWord;
    else if (b.getWordMultiplier(y, x) == 3) c = tripleWord;
    else if (b.getWordMultiplier(y, x) == 4) c = quadWord;
    gc.setBackground(c);
    gc.fillRectangle(xo, yo, size, size);

    c = light;
    if (b.getLetterMultiplier(y, x) == 2) c = doubleLetterLight;
    else if (b.getLetterMultiplier(y, x) == 3) c = tripleLetterLight;
    else if (b.getLetterMultiplier(y, x) == 4) c = quadLetterLight;
    else if (b.getWordMultiplier(y, x) == 2) c = doubleWordLight;
    else if (b.getWordMultiplier(y, x) == 3) c = tripleWordLight;
    else if (b.getWordMultiplier(y, x) == 4) c = quadWordLight;
    gc.setForeground(c);
    gc.drawLine(xo, yo, xo + size, yo);
    gc.drawLine(xo, yo, xo, yo + size);

    gc.setForeground(dark);
    gc.drawLine(xo + size, yo + size, xo + size, yo);
    gc.drawLine(xo + size, yo + size, xo, yo + size);

    Tile tile = b.getTile(y, x);

    if (tile.equals(Tile.NONE)) {
      for (Iterator i = placedTiles.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry entry = (Map.Entry) i.next();
        Point point = (Point) entry.getKey();
        if (point.x == x && point.y == y) {
          tile = (Tile) entry.getValue();

          DragSource source = new DragSource();
          source.rectangle = new Rectangle(xo, yo, size + 1, size + 1);
          source.x = x;
          source.y = y;
          source.tile = tile;
          dragSources.put(source.rectangle, source);
        }
      }
    }

    boolean highlight = false;
    IGameAction action = game.getLastAction();
    if (action != null && action instanceof MoveAction) {
      MoveAction moveAction = (MoveAction) action;
      MoveResult result = moveAction.getMoveResult();
      Tile[] tiles = result.getPreviousBoardState();
      Move move = result.getMove();
      Orientation orientation = move.getOrientation();
      int dx = orientation.getDx();
      int dy = orientation.getDy();
      int mx = move.getColumn();
      int my = move.getRow();
      for (int i = 0; i < tiles.length; i++) {
        Tile t = tiles[i];
        if (mx == x && my == y && t.equals(Tile.NONE)) {
          highlight = true;
        }
        mx += dx;
        my += dy;
      }
    }

    drawTile(gc, new Rectangle(xo, yo, size + 1, size + 1), tile, highlight);

    if (arrow != null && arrow.x == x && arrow.y == y) {
      drawArrow(gc, xo, yo, size);
    }
  }