i have a winform, and i added class, but when i added it, i got mistakes on the static classes i have inside. basically, it converts the code automatically to a form once it is located inside WinFormApplication1 and i dont know how to interact between the code and what i have in my original form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{

    public partial class ChessCode : Form
    {

        public static bool MATE;
        Pieces[,] pieces;
        public void ExecuteAll(int rowStart, int columnStart,int rowEnd,int columnEnd)
        {
            pieces = ChessBoard();
            //Castling
            CastlingMeh castle = new CastlingMeh();
            castle.CastlingCheck(pieces, rowStart, columnStart, rowEnd, columnEnd);
            //Promotion
            Promotion(pieces, rowStart, columnStart, rowEnd, columnEnd);
            //CheckManager
            CheckManager.CheckOrMate(pieces, rowStart, columnStart, rowEnd, columnEnd);
            if (MATE)
            {

            }
         
             printChessBoard(pieces);

        }
    


        public static void printChessBoard(Pieces[,] pieces)
        {
            for (int i = 1; i < 9; i++)
            {
                Console.Write("   " + i + "   ");
            }
            Console.WriteLine();
            for (int i = 1; i < 9; i++)
            {
                Console.Write(i + " ");
                for (int j = 1; j < 9; j++)
                {

                    if (pieces[i, j] != null)
                    {
                        pieces[i, j].print();
                    }
                    else
                    {
                        Console.Write("!  N  !");
                    }

                }
                Console.WriteLine();
            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

        }
        /// <summary>
        /// //////////////////////////////////////////////////////////////////////////////////////////////////////
        /// </summary>



        /// <summary>
        /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// </summary>
        /// <returns></returns>
        public  static Pieces[,] ChessBoard()
        {
            Pieces[,] piece = new Pieces[9, 9];

            piece[8, 1] = new Rook("WR");
            piece[8, 2] = new Knight("WKN");
            piece[8, 3] = new Bishop("WB");
            piece[8, 5] = new Queen("WQ");
            piece[8, 4] = new King("WK");
            piece[8, 6] = new Bishop("WB");
            piece[8, 7] = new Knight("WKN");
            piece[8, 8] = new Rook("WR");


            piece[7, 1] = new Pawn("WP");
            piece[7, 2] = new Pawn("WP");
            piece[7, 3] = new Pawn("WP");
            piece[7, 4] = new Pawn("WP");
            piece[7, 5] = new Pawn("WP");
            piece[7, 6] = new Pawn("WP");
            piece[7, 7] = new Pawn("WP");
            piece[7, 8] = new Pawn("WP");

            piece[1, 1] = new Rook("BR");
            piece[1, 2] = new Knight("BKN");
            piece[1, 3] = new Bishop("BB");
            piece[1, 5] = new Queen("BQ");
            piece[1, 4] = new King("BK");
            piece[1, 6] = new Bishop("BB");
            piece[1, 7] = new Knight("BKN");
            piece[1, 8] = new Rook("BR");

            piece[2, 1] = new Pawn("BP");
            piece[2, 2] = new Pawn("BP");
            piece[2, 3] = new Pawn("BP");
            piece[2, 4] = new Pawn("BP");
            piece[2, 5] = new Pawn("BP");
            piece[2, 6] = new Pawn("BP");
            piece[2, 7] = new Pawn("BP");
            piece[2, 8] = new Pawn("BP");

            return piece;

        }




        public static Pieces[,] Promotion(Pieces[,] pieces, int rowStart, int columnStart, int rowEnd, int columnEnd)
        {
            PiecePromotion promotion = new PiecePromotion();
            Object[,] choice2 = new Object[1, 5];
            Object[,] choice = new Object[1, 5];
            bool whitePromo = false;
            bool blackPromo = false;

            if (pieces[rowEnd, columnEnd] != null && pieces[rowEnd, columnEnd].pieceName()[1] == 'P' && (rowEnd == 1 || rowEnd == 8))
            {

                if (pieces[rowEnd, columnEnd].pieceName()[0] == 'B')
                {

                    blackPromo = true;
                }
                else
                {
                    whitePromo = true;
                }

                promotion.promotionPresentation(choice, choice2, blackPromo, whitePromo);

                if (whitePromo)
                {
                    pieces = promotion.promoteWhite(pieces, rowStart, columnStart, columnEnd, rowEnd, choice2);
                }
                else
                {
                    pieces = promotion.promoteBlack(pieces, rowStart, columnStart, columnEnd, rowEnd, choice);
                }
            }
            return pieces;
        }

        //private void InitializeComponent()
        //{
        //    this.SuspendLayout();
        //    // 
        //    // Chess
        //    // 
        //    this.ClientSize = new System.Drawing.Size(292, 266);
        //    this.Name = "Chess";
        //    this.Load += new System.EventHandler(this.Chess_Load);
        //    this.ResumeLayout(false);

        //}

i get the following mistakes:

Error 2 Inconsistent accessibility: parameter type 'Pieces[*,*]' is less accessible than method 'WindowsFormsApplication1.ChessCode.printChessBoard(Pieces[*,*])' D:\Documents and Settings\Dima\My Documents\Visual Studio 2008\Projects\ChessBoardGame\ChessBoardGame\ChessCode.cs 39 28 ChessBoardGame

Error 3 Inconsistent accessibility: return type 'Pieces[*,*]' is less accessible than method 'WindowsFormsApplication1.ChessCode.ChessBoard()' D:\Documents and Settings\Dima\My Documents\Visual Studio 2008\Projects\ChessBoardGame\ChessBoardGame\ChessCode.cs 81 34 ChessBoardGame


Error 4 Inconsistent accessibility: parameter type 'Pieces[*,*]' is less accessible than method 'WindowsFormsApplication1.ChessCode.Promotion(Pieces[*,*], int, int, int, int)' D:\Documents and Settings\Dima\My Documents\Visual Studio 2008\Projects\ChessBoardGame\ChessBoardGame\ChessCode.cs 129 33 ChessBoardGame


Error 5 Inconsistent accessibility: return type 'Pieces[*,*]' is less accessible than method 'WindowsFormsApplication1.ChessCode.Promotion(Pieces[*,*], int, int, int, int)' D:\Documents and Settings\Dima\My Documents\Visual Studio 2008\Projects\ChessBoardGame\ChessBoardGame\ChessCode.cs 129 33 ChessBoardGame

You didn't post your Pieces class that I can see, but I suspect it starts like this:

class Pieces ...

Notice in, say, line 81 you declare the method as returning a Pieces[,] and that the method is public. This means that other code can get at a Pieces object, but your declaration of it (like the one I posted) isn't public. You can't return a non-public object in a public method. That's what the "inconsistent accessibility" means.

So change your class to public class Pieces ... if you really want the value to be publicly available.

i deleted the whole code and started from the beginning. i am sorry, but i havent got a good understanding on what the program does behind the scenes.
what i did was that:
i added a new class, put all the code inside, without the main method.

now i have this in my Solution Explorer:

Properties
References
ChessBoard.cs
ChessBoard.Designer.cs - what does this do?
ChessBoard.resx- and what does this do?
class2.cs
Program.cs

i dont know if there is anything that inhibits me to connect to the class i added.
Thats my new code, Both this class that i added and the form file class are under the same namespace.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    class Class2
    {

        public static bool MATE;
        public static void ExecuteAll(int rowStart,int columnStart,int rowEnd,int columnEnd)
        {
          
            int b = 0;
            Pieces[,] pieces = ChessBoard();
          
                // prints chessboard
                printChessBoard(pieces);

                //Users Answer
                User c = new User(pieces);
                int[] locationMap = c.answerReturned(pieces);

                //Games new board to be printed
                Game g = new Game(pieces, locationMap[0], locationMap[1], locationMap[2], locationMap[3]);
                pieces = g.makeMove();

                //PieceLocation 
                rowStart = locationMap[0];
                columnStart = locationMap[1];
                rowEnd = locationMap[2];
                columnEnd = locationMap[3];

                //Castling
                CastlingMeh castle = new CastlingMeh();
                castle.CastlingCheck(pieces, rowStart, columnStart, rowEnd, columnEnd);

                //Promotion
                Promotion(pieces, rowStart, columnStart, rowEnd, columnEnd);

                //CheckManager
                CheckManager.CheckOrMate(pieces, rowStart, columnStart, rowEnd, columnEnd);

                if (MATE)
                {
            
                }

                b++;

       
        }

am i doing the right thing? i dont see any mistakes yet, .. i want to use the functions in the additional class that i added (Class2)

it still gives me this:

Error 2 Inconsistent accessibility: parameter type 'WindowsFormsApplication1.Pieces[*,*]' is less accessible than method 'WindowsFormsApplication1.ChessBoard.PrintPieces(WindowsFormsApplication1.Pieces[*,*])' D:\Documents and Settings\Dima\My Documents\Visual Studio 2008\Projects\ChessBoardGame\ChessBoardGame\ChessBoard.cs 1135 21 ChessBoardGame

i used one method in my Form class:

public void PrintPieces(Pieces [,] pieces)
{
}

and in the class2 i call it like this

public static void ExecuteAll(int rowStart,int columnStart,int rowEnd,int columnEnd)
        {
                Pieces[,] pieces = ChessBoard();

  



                ChessBoard chessB = new ChessBoard();
                chessB.PrintPieces(ChessBoard());

}


Why is it a mistake?

Still haven't seen the Pieces class, and the error given is referencing a parameter, and I don't see a method that is being called that uses Pieces as an argument in the last code snippet you posted. I'm guessing it's line 10 based on your code.

I do have to ask why the ChessBoard class needs a ChessBoard parameter in line 10.
Also lines 3 and 9 seem contradictory, is ChessBoard() a method or a constructor (used as a method in 3, and constructor in 9).

commented: Thanks , for the winform help +0

ooh, yeah, i noticed what was the mistake, i changed it to public

public abstract class Pieces
{
    public abstract string pieceName();
    public abstract bool pieceCollision(Pieces[,] pieces, int rowStart, int columnStart, int rowEnd, int columnEnd);
    public abstract bool pieceMovement(Pieces[,] pieces, int rowStart, int columnStart, int rowEnd, int columnEnd);
    public abstract void print();
    public abstract bool piecesDevour(Pieces[,] pieces, int rowStart, int columnStart, int rowEnd, int columnEnd);
}

thank you , Momerath, i will give you a rep..

ChessBoard is a method that returns an array of all the pieces.i have corrected the ChessBoard() to ChessBoardDisplay() so there wont be an error. i also broke the code to as many methods as i could to make things organized. i guess , thats the best way to work, isnt it?

One best practice is to have each method do one thing. The method can either control other methods or perform some action. If you find your method doing multiple things (read file, parse data, print data) then those are good candidates for their own methods.

There are times to violate this rule. As you gain experience you'll also figure when it's ok :)

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.