Example #1
0
        public int Move(int y, int x, Figures figure_type)
        {
            if (board.IsCheck(this, y, x))
            {
                return(0);
            }
            if (GetColor() != board.GetColor())
            {
                return(-2);
            }
            int CanMove = this.IsCanMove(y, x);

            if (CanMove != 0)
            {
                if ((GetColor() == Colors.BLACK && y != 0) || (GetColor() == Colors.WHITE && y != 7))
                {
                    return(-1);
                }
                board.RemoveFigure(this);
                board.Move(board.CreateNewFigure(this.y, this.x, this.color, figure_type), y, x);
                board.EndMove();
                return(1);
            }
            return(0);
        }
Example #2
0
        //public Tuple<int, int, string> CastlingLoc { get; set; }

        public Player(string name, string positionData, string imageData)
        {
            Name        = name;
            MovesCount  = 0;
            SecondTimer = 0;
            IsInDanger  = false;
            figCount    = 0;
            LostCount   = 0;
            figures     = new Figures[24];
            SetToStartingPositions(positionData, imageData);
            Castle      = new List <Figures>();
            CastlingLoc = new List <Tuple <int, int, string> >();
        }
Example #3
0
        public Figure CreateNewFigure(int y, int x, Colors color, Figures type_figure)
        {
            Figure figure;

            switch (type_figure)
            {
            case Figures.BISHOP:
                figure = new Bishop(y, x, color, this);
                break;

            case Figures.KNIGHT:
                figure = new Knight(y, x, color, this);
                break;

            case Figures.QUEEN:
                figure = new Queen(y, x, color, this);
                break;

            case Figures.ROOK:
                figure = new Rook(y, x, color, this);
                break;

            case Figures.PAWN:
                figure = new Pawn(y, x, color, this);
                break;

            case Figures.KING:
                figure = new King(y, x, color, this);
                if (color == Colors.BLACK)
                {
                    this.black_king = figure;
                }
                else
                {
                    this.white_king = figure;
                }
                break;

            default:
                return(null);
            }
            this.AddFigure(figure);
            return(figure);
        }
Example #4
0
 /// <summary>
 /// metodas sudaro lentele kur figura gali judeti
 /// </summary>
 /// <param name="f"></param>
 /// <param name="table">figuru lentele : 1; 2; 0</param>
 /// <param name="friendly"></param>
 /// <returns></returns>
 public int[,] GetPossibleMoves(Figures f, int[,] table, int friendly, Player enemyPlayer, out bool possible)
 {
     possible     = false;
     int[,] moves = new int[8, 8];
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             if (table[i, j] != friendly)
             {
                 CountDelta(out int x, out int y, j, i, f.Position);
                 if (table[i, j] != 0)
                 {
                     if (f.CanGo(table, x, y, j - x, i - y, friendly, true, enemyPlayer, this, true) == true)
                     {
                         moves[i, j] = 1;
                         possible    = true;
                     }
                     else
                     {
                         moves[i, j] = 0;
                     }
                 }
                 else
                 {
                     if (f.CanGo(table, x, y, j - x, i - y, friendly, false, enemyPlayer, this, true) == true)
                     {
                         moves[i, j] = 1;
                         possible    = true;
                     }
                     else
                     {
                         moves[i, j] = 0;
                     }
                 }
             }
         }
     }
     return(moves);
 }
Example #5
0
 public void SetFig(Figures f)
 {
     figures[figCount] = f;
     figCount++;
 }