Beispiel #1
0
        // place random food game
        private void GenerateFood()
        {
            int maxXpos  = pbcanvas.Size.Width / setting.width;
            int maxYpost = pbcanvas.Size.Height / setting.height;

            Random random = new Random();

            food   = new circle();
            food.x = random.Next(0, maxXpos);
            food.y = random.Next(0, maxYpost);
        }
Beispiel #2
0
        private void Eat()
        {
            //ad ircle body
            circle food = new circle();

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

            // uupdate score
            setting.score += setting.points;
            lblscord.Text  = setting.score.ToString();
            GenerateFood();
        }
Beispiel #3
0
        private void StartGame()
        {
            lblgameOver.Visible = false;
            pickbad.Visible     = false;
            pickcool.Visible    = false;
            pickhappy.Visible   = false;
            //set setting to defaut
            new setting();

            //create new player object
            snake.Clear();
            circle head = new circle();

            head.x = 10;
            head.y = 5;
            snake.Add(head);
            lblscord.Text = setting.score.ToString();
            GenerateFood();
        }