Esempio n. 1
0
        public void addBody()
        {
            int       x   = snake[snake.Count - 1].Location.X;
            int       y   = snake[snake.Count - 1].Location.Y;
            int       dir = snake[snake.Count - 1].Direction;
            SnakeBody b1  = new SnakeBody();

            b1.Direction = dir;

            switch (dir)
            {
            case 0:
                b1.setX(x);
                b1.setY(y + 17);
                break;

            case 1:
                b1.setX(x);
                b1.setY(y - 17);
                break;

            case 2:
                b1.setX(x + 17);
                b1.setY(y);
                break;

            case 3:
                b1.setX(x - 17);
                b1.setY(y);
                break;
            }
            snake.Add(b1);
        }
Esempio n. 2
0
        public void moveBody(SnakeBody s, int speed)
        {
            int x = s.Location.X;
            int y = s.Location.Y;

            switch (s.Direction)
            {
            case 0:
                s.setX(x);
                s.setY(y - speed);
                break;

            case 1:
                s.setX(x);
                s.setY(y + speed);
                break;

            case 2:
                s.setX(x - speed);
                s.setY(y);
                break;

            case 3:
                s.setX(x + speed);
                s.setY(y);
                break;
            }
        }
Esempio n. 3
0
        public void start()
        {
            resetFood();
            SnakeBody head = new SnakeBody();

            head.setX(rnd.Next(0, this.Size.Width - 50));
            head.setY(rnd.Next(0, this.Size.Height - 50));
            head.Direction = rnd.Next(0, 4);
            snake.Add(head);
            addBody();
            addBody();
            reDraw();
        }