Esempio n. 1
0
  @Override
  public void focusGained(FocusEvent e) {

    Game game = this.app.getGame();

    if (game != null) {

      if (game.getRack().getTiles() != null
          && game.getRack().getTiles().size() > 0
          && game.getRack().getTiles().get(0) != null) {
        this.app.getGame().setHighlightedTile(game.getRack().getTiles().get(0));

      } else {
        Cell srcCell = new Cell(new BoardLocation(0, -1), CellColor.White);
        Cell nextCell = this.app.getGame().getBoard().getNextCell(srcCell, Board.RIGHT, true);

        if (nextCell != null) {

          this.app.getGame().setHighlightedTile(nextCell.getTile());
        }
      }

      this.app.repaintBoardAndRack();
    }
  }
Esempio n. 2
0
  /** Called when user presses the space bar or tile if force-dropped */
  private void handleGrabOrReleaseTile() {

    Game game = this.app.getGame();
    Tile tile = game.getHighlightedTile();

    if (this.isHighlightedGrabbed) {

      ITileLocation srcLocation = game.getGrabbedTileSrcLocation();
      ITileLocation destLocation;
      game.setGrabbedTileSrcLocation(null);

      if (game.getRack().getTiles().contains(tile)) {

        destLocation =
            new RackTileLocation(game.getRack().getTiles().indexOf(tile), game.getRack());
      } else {

        destLocation = new BoardTileLocation(game.getBoard().getCellFromTile(tile));
      }

      game.getUndoManager().pushMovement(new TileMovement(srcLocation, destLocation));

    } else {

      if (game.getRack().getTiles().contains(tile)) {

        game.setGrabbedTileSrcLocation(
            new RackTileLocation(game.getRack().getTiles().indexOf(tile), game.getRack()));
      } else {

        game.setGrabbedTileSrcLocation(
            new BoardTileLocation(game.getBoard().getCellFromTile(tile)));
      }
    }

    // Toggle whether or not the tile is grabbed
    this.isHighlightedGrabbed = !this.isHighlightedGrabbed;
  }