예제 #1
0
        private void Eat()
        {
            //Add circle to body
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.bite_sound;
            player.Play();
            circle circle = new circle
            {
                x = Snake[Snake.Count - 1].x,
                y = Snake[Snake.Count - 1].y
            };
            Snake.Add(circle);

            //Update Score
            Settings.Score += Settings.Points;
            label_points.Text = Settings.Score.ToString();

            GenerateFood();
        }
예제 #2
0
 private void StartGame()
 {
     label_gameOver.Visible = false;
     label_pause.Visible = false;
     System.Media.SoundPlayer player = new System.Media.SoundPlayer();
     player.Stop();
     //Set settings to default
     new Settings();
     //Create new player object
     Snake.Clear();
     circle head = new circle { x = 10, y = 5 };
     Snake.Add(head);
     for (int i = 0; i < 3; i++)
     {
         circle body = new circle { x = 10, y = 4 - i };
         Snake.Add(body);
     }
     label_points.Text = Settings.Score.ToString();
     GenerateFood();
 }
예제 #3
0
 //Place food object
 private void GenerateFood()
 {
     bool food_over_body = false;
     int max_x_pos = game_canvas.Size.Width / Settings.Width;
     int max_y_pos = game_canvas.Size.Height / Settings.Height;
     int x1, y1;
     Random random = new Random();
     x1 = random.Next(0, max_x_pos);
     y1 = random.Next(0, max_y_pos);
     //Exclude snake coordinates
     for (int i = 0; i < Snake.Count; i++)
     {
         if (Snake[i].x == x1 &&
            Snake[i].y == y1)
         {
             food_over_body = true;
         }
     }
     if (food_over_body == false)
     {
         food = new circle { x = x1, y = y1 };
     }
     else
         GenerateFood();
 }