예제 #1
0
파일: Snake.cs 프로젝트: hornfezonter/Snake
        public Snake(Vector2 _origin, Point position, Texture2D _head, Texture2D _straightBody, Texture2D _cornerBody, Texture2D _tail)
        {
            origin = _origin;
            headImage = _head;
            straightBodyImage = _straightBody;
            cornerBodyImage = _cornerBody;
            tailImage = _tail;

            Point pos = position;

            head = new SnakeHead(headImage, origin, pos, Direction.Up);
            body = new List<SnakeBody>();
            pos.Y++;
            body.Add(new SnakeBody(straightBodyImage, origin, pos, Direction.Up, Direction.Up));
            pos.Y++;
            tail = new SnakeTail(tailImage, origin, pos, Direction.Up);
        }
예제 #2
0
파일: Snake.cs 프로젝트: hornfezonter/Snake
        //蛇的最短长度为3
        public Snake(Vector2 _origin, Point position, Texture2D _head, Texture2D _straightBody, Texture2D _cornerBody, Texture2D _tail, Direction _direction, int length)
        {
            origin = _origin;
            headImage = _head;
            straightBodyImage = _straightBody;
            cornerBodyImage = _cornerBody;
            tailImage = _tail;

            Point pos = position;

            if (length < 3)
                length = 3;

            int x, y;
            switch (_direction)
            {
                case Direction.Up:
                    x = 0;
                    y = -1;
                    break;
                case Direction.Down:
                    x = 0;
                    y = 1;
                    break;
                case Direction.Left:
                    x = -1;
                    y = 0;
                    break;
                case Direction.Right:
                    x = 1;
                    y = 0;
                    break;
                default:
                    x = 0;
                    y = 0;
                    break;
            }

            head = new SnakeHead(headImage, origin, pos, _direction);
            body = new List<SnakeBody>();
            for (int i = 0; i < length - 2; i++)
            {
                pos.X += x;
                pos.Y += y;
                body.Add(new SnakeBody(straightBodyImage,origin,pos,_direction,_direction));
            }

            pos.X += x;
            pos.Y += y;
            tail = new SnakeTail();
        }