Ejemplo n.º 1
0
        private void StartGame()
        {
            //Resetting game
            settings.SetGameOver(false);
            labelGameOver.Visible         = false;
            labelGameOverSub.Visible      = false;
            SnakeStartInstruction.Visible = false;
            settings.SetDirection("Down");
            settings.SetScore(0);
            ScoreLabel.Text = "0";
            Snake.Clear();

            //Create head
            SnakeBody head = new SnakeBody(10, 10);

            Snake.Add(head);

            CreateFood();
        }
Ejemplo n.º 2
0
        private void EatFood()  //Runs when snake makes collision with food
        {
            //Takes position of last snake body part and adds a new piece
            SnakeBody x = new SnakeBody(Snake[Snake.Count - 1].GetX(), Snake[Snake.Count - 1].GetY());

            Snake.Add(x);
            //Play sound
            SoundPlayer Eat = new SoundPlayer(Properties.Resources.eatSound);

            if (mute == false)
            {
                Eat.Play();
            }
            //Updating Score
            settings.SetScore(settings.GetScore() + 1);
            ScoreLabel.Text = Convert.ToString(settings.GetScore());
            //updating High Score
            if (settings.GetScore() > Convert.ToInt32(labelHighScore.Text))
            {
                labelHighScore.Text = Convert.ToString(settings.GetScore());
            }

            CreateFood();
        }