Example #1
0
        private void timer1_Tick(object sender, EventArgs e) //whats going to happen when timer begins
        {
            snakeScoreLabel.Text = Convert.ToString(score);  //actual score

            if (down)
            {
                snakes.moveDown(); //checking wich ones are true from above
            }
            if (up)
            {
                snakes.moveRight(); //method from snake.cs to where the snake is going
            }
            if (right)
            {
                snakes.moveLeft();
            }
            if (left)
            {
                snakes.moveLeft();
            }

            this.Invalidate(); //drawing the snake again

            colision();        //if snake crashes if not it grows


            for (int i = 0; i < snakes.SnakeRec.Length; i++)         //actual size of snake
            {
                if (snakes.SnakeRec[i].IntersectsWith(food.foodrec)) //if snake touch food
                {
                    player.SoundLocation = "C:/dev/github/SnakeGame/snake game/snake game\resources/power";
                    player.Play();

                    score += 1;                 //score 1 plus 1
                    snakes.addSnake();
                    food.foodLocation(ranfood); //random food position
                }
            }
        }