Beispiel #1
0
        public ChessBoard()
        {
            chessBoard = new ChessBox[8, 8];

            //Fill The Board with Boxes;
            bool isWhite = true;
            int arrArgX = 0;
            for (int i = 1; (i < 9); i++)
            {
                int arrArgY = 0;

                for (char a = 'A'; a < 'I'; a++)
                {
                    chessBoard[arrArgX, arrArgY] = new ChessBox(a, i, isWhite);
                    if(a!='A')
                    {
                        isWhite = !isWhite;
                    }
                    
                    arrArgY++;
                }
                arrArgX++;
                
            }

          //inTheMatrix 
          //X->0-'A' ,1-->'B'..
          //Y->0-1, 1-2..
        }
Beispiel #2
0
        public bool PathBetweenBoxesFree(ChessBox start, ChessBox end)
        {
                if(start.Figure.Xpositon==end.Figure.Xpositon)
                {
                    
                    char sameX=start.Figure.Xpositon;
                    
                    if(start.Ycoord<end.Ycoord)
                    {
                        
                        for (int i = start.Ycoord+1; i <end.Ycoord ; i++)
                        {
                            
                            if(getChessBoxByCoordinates(sameX,i).isFigureOn())
                            {
                                return false;
                            }
                            
                        }
                        return true;
                    }
                    else if(start.Ycoord>end.Ycoord)
                    {
                        for (int i = end.Ycoord + 1; i < start.Ycoord; i++)
                        {
                            if (getChessBoxByCoordinates(sameX, i).isFigureOn())
                            {
                                return false;
                            }
                            
                        }
                        return true;
                    }
                }
                else if(start.Figure.Ypositon==end.Figure.Ypositon)
                {
                    int sameY = start.Figure.Ypositon;

                    if (start.Xcoord < end.Xcoord)
                    {
                        for (int i = start.Xcoord + 1; i < end.Xcoord; i++)
                        {
                            if (getChessBoxByCoordinates(Convert.ToChar(i), sameY).isFigureOn())
                            {
                                return false;
                            }
                            
                        }
                        return true;
                    }
                    else if (start.Xcoord > end.Xcoord)
                    {
                        for (int i = end.Xcoord + 1; i < start.Xcoord; i++)
                        {
                            if (getChessBoxByCoordinates(Convert.ToChar(i), sameY).isFigureOn())
                            {
                                return false;
                            }
                            
                        }
                        return true;
                    }
                }
                else if (((end.Xcoord > end.Ycoord) && (end.Ycoord > start.Ycoord)) && (((end.Xcoord - start.Xcoord) == (end.Ycoord - start.Ycoord))))
                {/// down right
                    Console.WriteLine("agd");
                    char indexX = Convert.ToChar(start.Xcoord + 1);
                    int indexY = start.Ycoord + 1;
                   while(indexY<end.Ycoord)
                   {
                       if(getChessBoxByCoordinates(indexX,indexY).isFigureOn())
                       {
                           return false;
                       }
                       indexX++;
                       indexY++;
                   }
                   return true;
                }
            else if (((end.Xcoord>start.Xcoord)&&(start.Ycoord>end.Ycoord))&&((end.Xcoord-start.Xcoord)==(start.Ycoord-end.Ycoord)))
                {/// up right
                    Console.WriteLine("ssss");
                    char indexX = Convert.ToChar(start.Xcoord + 1);
                    int indexY = start.Ycoord - 1;
                    while (indexX < end.Xcoord)
                    {
                        if (getChessBoxByCoordinates(indexX, indexY).isFigureOn())
                        {
                            return false;
                        }
                        indexX++;
                        indexY--;
                    }
                    return true;
                }
                else if ((((start.Xcoord>end.Xcoord)&&(end.Ycoord>start.Ycoord)))&&((start.Xcoord - end.Xcoord) == (end.Ycoord - start.Ycoord)))
                {/// down left
                    Console.WriteLine("ASD");
                    char indexX = Convert.ToChar(start.Xcoord - 1);
                    int indexY = start.Ycoord + 1;
                    while (indexY < end.Ycoord)
                    {
                        if (getChessBoxByCoordinates(indexX, indexY).isFigureOn())
                        {
                            return false;
                        }
                        indexX--;
                        indexY++;
                    }
                    return true;
                }
                else if ((((start.Xcoord > end.Xcoord) && (start.Ycoord > end.Ycoord))) && ((start.Xcoord - end.Xcoord) == (start.Ycoord - end.Ycoord)))
                {/// up left
                    Console.WriteLine("ddd");
                    char indexX = Convert.ToChar(start.Xcoord - 1);
                    int indexY = start.Ycoord - 1;
                    while (indexY < end.Ycoord)
                    {
                        if (getChessBoxByCoordinates(indexX, indexY).isFigureOn())
                        {
                            return false;
                        }
                        indexX--;
                        indexY--;
                    }
                    return true;
                }
                Console.WriteLine("BAH");
                return true;
                  
                    
                   
            
            
        }