Tetris - Hard drop Logic
<p>I'm building tetris and am confused as to how I can make a piece hard drop.</p>

<p>I tried adding a <code>hardDrop()</code> method to Board class which would iterate from the bottom row and check for open spaces... </p>

<p>Board class:</p>

<pre><code>public int hardDrop() {
    int hardDropRow = 0;
    for(int row = totalRows-1; row &gt; 0; row--) {
        for(int col = 0; col &lt; grid[row].length; col++) {
            if (grid[row][col] != null) {
                hardDropRow = row;
                return hardDropRow;
            }
        }       
    }
    return hardDropRow;
}
</code></pre>

<p>Piece class:</p>

<p>Then here, for each piece I would add the valid <code>dropRow</code> to the <code>getRow()</code>: </p>

<pre><code>        //Hard drop
        if (keycode == KeyEvent.VK_UP) {
            //get next valid coordinates nearest to bottom 
            //hard drop needs to which row the piece needs to drop to
            int dropRow;
            dropRow = board.hardDrop();
            for (int i = 0; i &lt; tile.length; i++) {
                calcNewPosition(tile[i].getRow()+dropRow, tile[i].getCol(), i);
            }
</code></pre>

<p>When I press up, the piece just seems to skip down a few rows even though the whole bottom is null... so it should just move to that spot.</p>

<p>Any suggestions?</p>

<p>Thanks!</p>

<p><strong>EDIT --</strong> </p>

<p>I've updated my timer so it accepts a value... if <code>val == 1</code>, that means instant drop was hit... so it sets the interval = 10 milliseconds...</p>

<p>If <code>val != 1</code>, it goes through the case statement.</p>

<p>For some reason, once <code>timer(1)</code> is set, the interval won't change back even if I change it...</p>

<p><strong>Board class:</strong></p>

<pre><code>public void timer (int val) {
    int interval;
    if (val == 1) {
        interval = 1;       
    }
    else {
        switch (level) {
        //each level increases drop speed by .10 seconds
            case 1: interval = 700;
                    break;
            case 2: interval = 600;
                    break;
            case 3: interval = 500;
                    break;
            case 4: interval = 400;
                    break;
            case 5: interval = 300;
                    break;
            default: interval = 800;
                    break;
        }
    }
    Timer t = new Timer(interval, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (pause &amp;&amp; gameWon){
                message = "You've won!";
            }
            else if (pause) {               
                seconds++;
            }
            else {
                seconds = 0;
                newPiece.autoMove();
                repaint(); 
            }
        }
     });
    t.start();  
}    
</code></pre>

<p><strong>Piece class:</strong> You see that I send <code>1</code> as a parameter to <code>timer()</code> for the hard drop...
Then set it back with something other than <code>1</code>...</p>

<pre><code>    //hard drop
    if (keycode == KeyEvent.VK_UP) {
        board.timer(1);
        for (int i = 0; i &lt; tile.length; i++) {
            calcNewPosition(tile[i].getRow()+1, tile[i].getCol(), i);
        }
        clearCurrPosition();
        for (int i = 0; i &lt; tile.length; i++) {
            board.checkEndGame(tile[i].getRow(), tile[i].getCol());
        }
        board.timer(0);
        board.checkBottomFull();
        if (isCollision()) board.createNewPiece();
        move();
</code></pre>
