Exemplo n.º 1
0
 private void newGameToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (timer1.Enabled == false)
     {
         timer1.Enabled = true;
     }
     randFood = new Random();
     snake    = new Snake_Class();
     count    = 0;
     //directions
     left             = false;
     right            = false;
     down             = false;
     up               = false;
     gameOver.Visible = false;
 }
Exemplo n.º 2
0
 private void Snake_KeyDown(object sender, KeyEventArgs e)
 {
     //wenn down gedrückt und snake richtung ist nicht up
     if (e.KeyData == Keys.Down && up == false)
     {
         down  = true;
         up    = false;
         right = false;
         left  = false;
     }
     if (e.KeyData == Keys.Up && down == false)
     {
         down  = false;
         up    = true;
         right = false;
         left  = false;
     }
     if (e.KeyData == Keys.Left && right == false)
     {
         down  = false;
         up    = false;
         right = false;
         left  = true;
     }
     if (e.KeyData == Keys.Right && left == false)
     {
         down  = false;
         up    = false;
         right = true;
         left  = false;
     }
     //Pause game
     if (e.KeyData == Keys.P)
     {
         down  = false;
         up    = false;
         right = false;
         left  = false;
     }
     // new game
     if (e.KeyData == Keys.N)
     {
         if (timer1.Enabled == false)
         {
             timer1.Enabled = true;
         }
         randFood = new Random();
         snake    = new Snake_Class();
         count    = 0;
         //directions
         left             = false;
         right            = false;
         down             = false;
         up               = false;
         gameOver.Visible = false;
     }
     // Exit game
     if (e.KeyData == Keys.Escape)
     {
         this.Close();
     }
 }