public Square(int x, int y, Texture2D texture, Color colour, bool blocking, MapManager manager)
 {
     this.texture = texture;
     this.colour = colour;
     this.blocking = blocking;
     this.food = null;
     xlocation = x;
     ylocation = y;
     wall = blocking;
     this.mapManager = manager;
 }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            MapTextures mapTexs = new MapTextures();
            Texture2D headTexture = Content.Load<Texture2D>("drawing//Cow_Head");
            Texture2D mainTexture = Content.Load<Texture2D>("drawing//Cow_Middle");
            Texture2D tailTexture = Content.Load<Texture2D>("drawing//Cow_Bum");
            mapTexs.grassTexture = Content.Load<Texture2D>("drawing//grass");
            mapTexs.hedgeTexture = Content.Load<Texture2D>("drawing//hedge");
            mapTexs.hedgeVertTexture = Content.Load<Texture2D>("drawing/hedge_v");
            mapTexs.foodTexture = Content.Load<Texture2D>("drawing//food");
            mapTexs.hedgeCornerTexturetl = Content.Load<Texture2D>("drawing//hedge_corner_tl");
            mapTexs.hedgeCornerTexturetr = Content.Load<Texture2D>("drawing//hedge_corner_tr");
            mapTexs.hedgeCornerTexturebl = Content.Load<Texture2D>("drawing//hedge_corner_bl");
            mapTexs.hedgeCornerTexturebr = Content.Load<Texture2D>("drawing//hedge_corner_br");
            mapTexs.hedgeCrossTexture = Content.Load<Texture2D>("drawing//hedge_cross");
            mapTexs.foodTexture = Content.Load<Texture2D>("drawing//mushroom");
            font = Content.Load<SpriteFont>("DefaultFont");

            head = new HeadPiece(headTexture, mainTexture, tailTexture, this);
            CowPiece tail = new CowPiece(mainTexture, tailTexture, this);
            CowPiece a = new CowPiece(mainTexture, tailTexture, this);
            CowPiece b = new CowPiece(mainTexture, tailTexture, this);
            CowPiece c = new CowPiece(mainTexture, tailTexture, this);
            CowPiece d = new CowPiece(mainTexture, tailTexture, this);
            head.AttachPiece(tail);
            /*head.AttachPiece(a);
            head.AttachPiece(b);
            head.AttachPiece(c);
            head.AttachPiece(d);*/

            mapManager = new MapManager(40, mapTexs, head, this);

            // TODO: use this.Content to load your game content here
        }
 public WallPiece(int x, int y, Texture2D texture, Color colour, MapManager manager)
     : base(x,y,texture,colour,true,manager)
 {
 }
        public WallHead(int x, int y, Texture2D texture, Color colour, MapManager manager, int numberOfVertices)
            : base(x,y,texture,colour,manager)
        {
            headPoint = new Point(x, y);
            Point lastPoint = new Point(x, y);
            WallPiece previous = this;
            Nullable<DirectionToMove> lastDirectionMoved = null;
            for (int verticesCreated = 0; verticesCreated <= numberOfVertices; ++verticesCreated)
            {
                //lastMovedDirection - this is the variable that tells the next piece what direction to go when moving
                //lastDirectionMoved - this is used in creation of the original wall only DON'T GET CONFUSED!!!
                DirectionToMove newDirectionToMove;
                do
                {
                    newDirectionToMove = (DirectionToMove)random.Next(4);
                } while (newDirectionToMove == lastDirectionMoved);

                //Reverse direction since if we create the wall upwards then the snake is facing downwards but only for first point
                if (lastDirectionMoved == null)
                {
                    switch (newDirectionToMove)
                    {
                        case DirectionToMove.down:
                            lastMovedDirection = DirectionToMove.up;
                            break;
                        case DirectionToMove.up:
                            lastMovedDirection = DirectionToMove.down;
                            break;
                        case DirectionToMove.left:
                            lastMovedDirection = DirectionToMove.right;
                            break;
                        case DirectionToMove.right:
                            lastMovedDirection = DirectionToMove.left;
                            break;
                    }
                }

                Console.WriteLine("Starting direction: " + lastMovedDirection.ToString());

                MapManager.HedgeType newWallHedgeType;
                if (newDirectionToMove == DirectionToMove.left || newDirectionToMove == DirectionToMove.right)
                {
                    newWallHedgeType = MapManager.HedgeType.horizontal;
                }
                else
                {
                    newWallHedgeType = MapManager.HedgeType.vertical;
                }

                if (lastDirectionMoved != null && lastPoint.X < manager.size && lastPoint.X > 0 && lastPoint.Y < manager.size && lastPoint.Y > 0)
                {
                    //Must create a corner piece
                    MapManager.HedgeType cornerType = newWallHedgeType;
                    switch (lastDirectionMoved)
                    {
                        case DirectionToMove.down:
                            switch (newDirectionToMove)
                            {
                                case DirectionToMove.left:
                                    cornerType = MapManager.HedgeType.corner_topleft;
                                    break;

                                case DirectionToMove.right:
                                    cornerType = MapManager.HedgeType.corner_topright;
                                    break;
                            }
                            break;
                        case DirectionToMove.up:
                            switch (newDirectionToMove)
                            {
                                case DirectionToMove.left:
                                    cornerType = MapManager.HedgeType.corner_bottomleft;
                                    break;

                                case DirectionToMove.right:
                                    cornerType = MapManager.HedgeType.corner_bottomright; //bottomright
                                    break;
                            }
                            break;

                        case DirectionToMove.left:
                            switch (newDirectionToMove)
                            {
                                case DirectionToMove.up:
                                    cornerType = MapManager.HedgeType.corner_topright;
                                    break;

                                case DirectionToMove.down:
                                    cornerType = MapManager.HedgeType.corner_bottomright;
                                    break;
                            }
                            break;

                        case DirectionToMove.right:
                            switch (newDirectionToMove)
                            {
                                case DirectionToMove.up:
                                    cornerType = MapManager.HedgeType.corner_topleft;
                                    break;

                                case DirectionToMove.down:
                                    cornerType = MapManager.HedgeType.corner_bottomleft;
                                    break;
                            }
                            break;
                    }

                    //Now make the relevant corner
                    manager.map[lastPoint.X, lastPoint.Y] = manager.createHedge(lastPoint.X, lastPoint.Y, cornerType);
                    previous.Attach((WallPiece)manager.map[lastPoint.X, lastPoint.Y]);
                    previous = (WallPiece)manager.map[lastPoint.X, lastPoint.Y];
                }

                Point direction = Point.Zero;
                switch (newDirectionToMove)
                {
                    case DirectionToMove.left:
                        direction = new Point(-1, 0);
                        break;

                    case DirectionToMove.right:
                        direction = new Point(1, 0);
                        break;

                    case DirectionToMove.up:
                        direction = new Point(0, -1);
                        break;

                    case DirectionToMove.down:
                        direction = new Point(0, 1);
                        break;
                }
                int length = random.Next(4, 6);
                for (int i = 1; i < length; ++i)
                {
                    Point pointToMakeWall = new Point(lastPoint.X + direction.X * i, lastPoint.Y + direction.Y * i);
                    if (isValid(pointToMakeWall.X,pointToMakeWall.Y) && pointToMakeWall != CowPiece.startPoint)
                    {
                        manager.map[pointToMakeWall.X, pointToMakeWall.Y] = manager.createHedge(pointToMakeWall.X, pointToMakeWall.Y, newWallHedgeType);
                        previous.Attach((WallPiece)manager.map[pointToMakeWall.X, pointToMakeWall.Y]);
                        previous = (WallPiece)manager.map[pointToMakeWall.X, pointToMakeWall.Y];
                    }
                }

                lastPoint = new Point(lastPoint.X + direction.X * length, lastPoint.Y + direction.Y * length);
                lastDirectionMoved = newDirectionToMove;
            }
        }