Exemplo n.º 1
0
        // Place random food object on the screen
        private void GenerateFood()
        {
            int maxXPos = pbCanvas.Size.Width / Settings.Width;
            int maxYPos = pbCanvas.Size.Height / Settings.Height;

            Random random = new Random();

            food   = new circle();
            food.x = random.Next(0, maxXPos);
            food.y = random.Next(0, maxYPos);
        }
Exemplo n.º 2
0
        private void StartGame()
        {
            lblGameOver.Visible = false;

            new Settings();

            snake.Clear();
            circle head = new circle();

            head.x = 10;
            head.y = 5;
            snake.Add(head);

            lblScore.Text = Settings.Score.ToString();
            GenerateFood();
        }
Exemplo n.º 3
0
        private void Eat()
        {
            // Add circle to body
            circle food = new circle();

            food.x = snake[snake.Count - 1].x;
            food.y = snake[snake.Count - 1].y;

            snake.Add(food);

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

            GenerateFood();
        }