This is the error:

Error1 Inconsistent accessibility: field type 'drag_and_lock_grid.Puzzlepiece[]' is less accessible than field 'drag_and_lock_grid.Game1.pieces'


This line is states the error: public Puzzlepiece[] pieces;

This is my puzzle piece class:

class Puzzlepiece
    {
        private int id;
        private Vector2 position;
        private Vector2 previousPosition;
        private Boolean dragging;
        private Vector2 correctPosition;
        private Texture2D texture;
        private Boolean disabled = false;

        private Texture2D plu;
        private Vector2 lightUpPostion;
        private int delay = 3;
        private int delayTimer = 0;
        private int frame = 1;
        private Boolean descending = false;

 public Puzzlepiece(int id, Vector2 position, Texture2D texture, Vector2 correctPosition)
        {
            this.id = id;
            this.position = position;
            this.texture = texture;
            this.correctPosition = correctPosition;


            lightUpPostion = new Vector2(correctPosition.X - 5, correctPosition.Y - 5);
        }

        public void Draw()
        {
            Game1.spriteBatch.Draw(texture, position, Color.White);

            if (disabled)
            {

                if (!stopAnimation)
                {
                    plu = Game1.content.Load<Texture2D>("images/pieceslightup/plu_" + frame);
                    Game1.spriteBatch.Draw(plu, lightUpPostion, Color.White);
                    delayTimer++;

                    if (delayTimer > delay)
                    {
                        if (frame < 3)
                        {
                            if (!descending)
                            {
                                frame++;
                                delayTimer = 0;
                            }
                        }
                        else
                            descending = true;

                        if (descending)
                        {
                            frame--;
                            delayTimer = 0;
                        }

                        if (frame == 0)
                        {
                            stopAnimation = true;
                        }
                    }

                }
            }

        }

        public void Update()
        {

        }

        public void touchDown(float x, float y)
        {
            //Game1.spriteBatch.GraphicsDevice.Clear(Color.White);
        }
        public void touchMove(float x, float y)
        {
            //if(!dragging)
            //{
            //    dragging = true;
            //    previousPosition.X = x;
            //    previousPosition.Y = y;
            //}
            if (!disabled)
            {
                if (isWithinPuzzle(x, y))
                {
                    position.X = x - (texture.Width / 2);
                    position.Y = y - (texture.Height / 2);
                }
            }

        }
        public void touchUp(float x, float y)
        {
            if (isWithinPuzzle(x, y))
            {
                if (isWithinCorrectPosition(x, y))
                {
                    position.X = correctPosition.X;
                    position.Y = correctPosition.Y;
                    disabled = true;
                    
                }
            }
            //dragging = false;
            //position.X = previousPosition.X;
            //position.Y = previousPosition.Y;
        }

        public Boolean isWithinPuzzle(float x, float y)
        {
            if (x > position.X && x < position.X + texture.Width && y > position.Y && y < position.Y + texture.Height)
            {
                return true;
            }
            return false;
        }

        public Boolean isWithinCorrectPosition(float x, float y)
        {
            if (x > correctPosition.X && x < correctPosition.X + texture.Width && y > correctPosition.Y && y < correctPosition.Y + texture.Height)
            {
                return true;
            }
            return false;
        }
    }

I have another class called Layer class that relies on the Puzzlepiece class.

class Layer
    {
        //  private int id;
        //    private int length;
        //      private int order;
        //        private int overlappingg;

        private int numberOfPieces;
        private static Layer instance;
        private int[] layers;
        private int[] tempArray;
        private Boolean isOverlapping;
        private int[] Array;
        private int[] n;
        private int tempNumber = -1;

        /// <summary>
        /// Singleton pattern
        /// </summary>
        public static Layer layerManager
        {
            get
            {
                if (instance == null)
                    instance = new Layer(12);

                return instance;
            }
        }

        public Layer(int numberOfPieces)
        {
            this.numberOfPieces = numberOfPieces;
            layers = new int[numberOfPieces];
            tempArray = new int[numberOfPieces];
            randomise();
        }

        public void Draw()
        {
            //Game1.spriteBatch.Draw(texture, position, Color.White);

        }

        public void Update()
        {

        }

        public void touchDown(float x, float y, Puzzlepiece[] pieces)
        {
          
// Then if you want to call the method use

            if(checkOverlap(x,y,pieces))
            {

           }
        }
        public void touchMove(float x, float y, Puzzlepiece[] pieces)
        {

            
        }

        public void touchUp(float x, float y)
        {

        }

        public void randomise()
        {
            for (int i = 0; i < numberOfPieces; i++)
            {
                layers[i] = -1;

                Boolean success = false;

                while (!success)
                {
                    tempNumber = Game1.random.Next(1, numberOfPieces + 1);

                    if (!repeatNumber(tempNumber))
                    {
                        layers[i] = tempNumber;
                        success = true;
                    }

                }
            }


        }

        public Boolean repeatNumber(int n)
        {
            foreach (int layer in layers)
            {
                if (n == layer)
                {
                    return true;
                }
            }

            return false;
        }

        public void print()
        {
            for (int n = 0; n < numberOfPieces; n++)
            {
                Console.WriteLine(n + "   " + layers[n]);
            }

        }

           public Boolean checkOverlap(float x, float y, Puzzlepiece[] pieces)
        {
            int count = 0;

            for (int i = 0; i < pieces.Length; i++)
            {
                if(pieces[i].isWithinPuzzle(x,y))
                {
                    count++;
                }
            
            }

            if (count > 1)
            {
                return true;
            }
            else
                return false;
        }
        public void moveLayerToTop(int targetPuzzlePieces)
        {
            PuzzleP;
            int tempArrayid;
            int tempArrayitem;
            int n;

            for (int h = 1; h < totalpuzzlepieces; h++)
            {
                if (layers[h] = targetPuzzlePieces)
                    PuzzleP = h;
            }

        }

          public void push(Puzzlepiece puzzlep)
        {
            for (int i = 1; i < PuzzleP; i++)
                tempArray[i] = layers[i];
            id[1] = puzzlep;

            if (tempArray[i] != targetpuzzlepiece)
            {
                tempArray[i] = array[i];
            }
            else
            {
            }

        }
          public void checkHighestLayer()
          {
              for (int i = 1; i < PuzzleP; i++)


                  if (Puzzlep = overlapping)
                  {
                      puzzle p = array[n]; n++;

                      //the first one is to store the overlapping pieces
                  }

              for (int i = 1; i < PuzzleP; i++)

                  if (Array[i] = layersArray[i])
                  {

                    
                  }
                  else
                  {
                      
                  }
          }
    }
}

Thank You So much for spending your precious time with my errors! :)

Recommended Answers

All 6 Replies

Try changing line 1 on the first listing to public class puzzlepiece{ . I believe .NET classes default to internal (meaning things in the same assembly can access it) but the compiler may not be content with that.

You cannot declare some variable of a type that is less accessible than the variable itself.

For example, if I have:

public class MyBigPublicClass
{
    private class MySmallPrivateClass { ... stuff ... }
    
    // Can't do this because instance is more visible than class definition
    public MySmallPrivateClass InstanceOfPrivateClass; 

}

Hope this helps,

Vasiliy Deych

i tried public class puzzle piece, but more errors coming out.
Like:

Error 1 'Microsoft.Xna.Framework.Game' does not contain a definition for 'content'

Not a clue on that one. I haven't used XNA. Check around the area in which you are accessing "content" and then check your Game class to make sure the types match.

This doesn't necessarily mean what you changed was wrong the error checking may have finally caught up after you fixed the first one.

So, in conclusion, by changing the class puzzle piece to public class puzzle piece will solve the error?

Is that error still listed in the box? If not then it probably fixed it. But...it sounds like there are other issues with the code so there is no way to be sure. Knock out some of the simpler ones and see if the others go away.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.