So when i was running the square game provided and try to move the square around the board. I notice that the square keep moving constantly like a snake game rather than move it by 2 pixel. Is there a reason why that happen and how can I make it only move 2 pixel to a certain direction.
You might also want to look at moveSquare() and see how it handles direction==0.
That suggests the alternate solution of setting direction=0 in the changing size cases.
It's unclear which is the better "bug fix" to the existing game. If the game was being written from scratch with the intention that it would only move the square when an arrow was pressed, then your solution would be a better design, possibly adding a direction parameter to moveBlock() thus eliminating the direction state variable.