ok, now I got somehing like this:
Code:
private void FormGame_KeyDown(object sender, KeyEventArgs e)
{
key = e.KeyCode;
}
Code:
private void timer1_Tick(object sender, EventArgs e)
{
switch (key)
{
case Keys.Up:
snake.MoveUp(); break;
case Keys.Down:
snake.MoveDown(); break;
case Keys.Left:
snake.MoveLeft(); break;
case Keys.Right:
snake.MoveRight(); break;
}
snake.ReDraw(); // Re-Draws the new head and erases the previous tail
}
I'm trying to think of a way to block the option to move to the opposite direction, because now he can move left and just by a click - move right.
Should I save the previous direction?
I have another problem: When he start a new game, I just do:
Code:
snake = new Snake(this.CreateGraphics());
key = Keys.Left;
snake.Draw();
timer1.Start();
but it leaves the previous snake drawn. How can I create a function that clean the traces which would be called when the snake object is disposed?