Was I misunderstand that TS said?
for example, the snake is in direction 1 (left) but if i press key down and then key right very quickly, the direction becomes 2 (right) instead of becoming 4 (down) and then 2(right)
The behavior works correctly as what TS (and me) experiencing:
1. In less than 1/10 second, press down and then right
2. The snake move right only (ignoring the down)
3. What TS wants, go down and then right.
I said it works correctly, because:
- After the keypressing event, no movement call
- The movement is processed in the Timer1Timer
- That's why I suggest him to call Timer1Timer at the end of keypressing
- The movement only follows the variable "direction"
- The direction (currently) only reads the last key in the interval time given
- That's why the "down" key is ignored.
One possible solution is to use "buffer" to store the keys pressed by user. We should limit the size, I suggested 2 or 3. Using the first-key-only is okay but I don't think that is what TS wants.