We also need a method which reacts when a key is pressed. This will be the method handleInput. Each key that we can press during the game should be treated here. When the down arrow key is pressed, you should first check if this movement is even possible. If so, then the block must be moved down and a sound must be played. Like this:
if(Kb.bp(KB_DOWN))
{
if(canMove(currentBlock, D_DOWN))
{
5 currentBlock.move(D_DOWN);
SoundManager.blip();
}
}
The code to move a block to the left and to the right is similar. Or at least similar enough to do by yourself!
The ‘UP’ key is used to rotate a block in tetris. Add code to check if this key is pressed. This time you just need to call the method canRotate with the current block. If the result of that method is true, you rotate the block and play a sound.
And finally there is the space bar. When pressing the space bar the current block should move all the way down. To do that, ‘toBottom’ will be assigned true and ‘toBottomTimer’ gets a value of 0. And here, too, a sound is played.