Ejemplo n.º 1
0
        //Place random food object
        private void RandomFoodGeneration()
        {
            //Map size for prevent out map generation
            //CAN BE GLOBAL BECAUSE WE USE IT FREQUENTLY
            int max_XPosition = Gcanvas.Size.Width / Settings.width;
            int max_YPosition = Gcanvas.Size.Height / Settings.height;

            Random random = new Random();//Declaration of a Random object

            food = new CircleFood {
                X = random.Next(0, max_XPosition), Y = random.Next(0, max_YPosition)
            };
        }
Ejemplo n.º 2
0
        private void StartGame()
        {
            lblgameover.Visible = false;//Hide the game over message

            //New snake Object
            Snake.Clear();
            CircleFood head = new CircleFood {
                X = 10, Y = 5
            };                                         //Middle of the screen

            Snake.Add(head);                           //Create the head of the circle

            lblscore.Text = Settings.score.ToString(); //0
            RandomFoodGeneration();
        }
Ejemplo n.º 3
0
        private void EatFood()
        {
            //Add a new circle to the snake body
            CircleFood circle = new CircleFood
            {
                X = Snake[Snake.Count - 1].X,
                Y = Snake[Snake.Count - 1].Y
            };

            Snake.Add(circle);
            //Update and show the score
            Settings.score += Settings.points;
            lblscore.Text   = Settings.score.ToString();

            //Generate a new random food on the map
            RandomFoodGeneration();
        }