Beispiel #1
0
        /// <summary>
        /// Обрабатывает выделение поля пользователем
        /// </summary>
        /// <param name="selected"></param>
        public void Cell_Select(ChessCell selected)
        {
            if (selected.BackColor == WHITE_CELL_AVIABLE_FOR_MOVING || selected.BackColor == BLACK_CELL_AVIABLE_FOR_MOVING)
            {
                ReplaceFigure(selected_cell, selected);
                selected_cell.BackColor = (selected_cell.X + selected_cell.Y) % 2 == 0 ? WHITE_CELL : BLACK_CELL;
                ClearCellsForMovement();
                selected_cell = null;
                NextTurn();
                if (indicatior != null)
                {
                    indicatior.Text = current_turn == ChessColor.white ? "ходят белые" : "ходят чёрные";
                }
                return;
            }
            if (selected_cell != null)
            {
                selected_cell.BackColor = (selected_cell.X + selected_cell.Y) % 2 == 0 ? WHITE_CELL : BLACK_CELL;
            }

            selected_cell = selected;
            ClearCellsForMovement();

            if (selected.IsOccuped && CurrentTurn == selected.CurrentChess.Color)
            {
                selected_cell.BackColor = SELECTED_OCCUPED_CELL;
                GetCellsForMovement(selected.CurrentChess);
                return;
            }
            else
            {
                selected_cell.BackColor = SELECTED_FREE_CELL;
            }
        }
Beispiel #2
0
        public bool ColorCell(int X, int Y)
        {
            try
            {
                ChessCell cell = chess_cells[Y, X];

                if (cell.IsOccuped)
                {
                    if (cell.CurrentChess.Color != current_turn)
                    {
                        movement_cells.Add(cell);
                        cell.BackColor = (cell.X + cell.Y) % 2 == 0 ? WHITE_CELL_AVIABLE_FOR_MOVING : BLACK_CELL_AVIABLE_FOR_MOVING;
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    movement_cells.Add(cell);
                    cell.BackColor = (cell.X + cell.Y) % 2 == 0 ? WHITE_CELL_AVIABLE_FOR_MOVING : BLACK_CELL_AVIABLE_FOR_MOVING;
                    return(false);
                }
            }
            catch { }

            return(true);
        }
Beispiel #3
0
        //=====КОНСТРУКТОРЫ=============================================

        /// <summary>
        /// Создание графического шахматоного поля
        /// </summary>
        /// <param name="FieldBorder"> GroupBox, в котором разместиться поле </param>
        public void CreateField(GroupBox FieldBorder)
        {
            border         = FieldBorder;
            border_ratio_W = (double)border.Size.Width / (double)border.Parent.Size.Width;
            border_ratio_H = (double)border.Size.Height / (double)border.Parent.Size.Height;

            double square_size = Math.Min(FieldBorder.Size.Width, FieldBorder.Size.Height - FieldBorder.Font.Size);
            int    len         = (int)((square_size - border_indent * 2) / 8);

            Size cell_size = new Size(len, len);

            for (int i = 0, i_count = border_indent + (int)FieldBorder.Font.Size; i < 8; i++, i_count += len)
            {
                for (int j = 0, j_count = border_indent; j < 8; j++, j_count += len)
                {
                    ChessCell new_cell = new ChessCell();
                    new_cell.SizeMode  = PictureBoxSizeMode.StretchImage;
                    new_cell.Size      = cell_size;
                    new_cell.Location  = new Point(j_count, i_count);
                    new_cell.BackColor = (i + j) % 2 == 0 ? WHITE_CELL : BLACK_CELL;
                    new_cell.X         = j;
                    new_cell.Y         = i;
                    new_cell.Click    += CellClick;

                    chess_cells[i, j] = new_cell;
                    FieldBorder.Controls.Add(new_cell);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Помечает указанное поле, как доступное для перемещения
        /// </summary>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        /// <param name="occupy_wanted"></param>
        public bool ColorCellPawn(int X, int Y, bool occupy_wanted)
        {
            try
            {
                ChessCell cell   = chess_cells[Y, X];
                bool      answer = cell.IsOccuped;

                if (cell.IsOccuped == occupy_wanted)
                {
                    movement_cells.Add(cell);
                    cell.BackColor = (cell.X + cell.Y) % 2 == 0 ? WHITE_CELL_AVIABLE_FOR_MOVING : BLACK_CELL_AVIABLE_FOR_MOVING;
                }
                return(answer);
            }
            catch { }

            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Обработка нажатия на кдетку доски
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void CellClick(object sender, EventArgs e)
        {
            ChessCell self = (ChessCell)sender;

            Cell_Select(self);
        }
Beispiel #6
0
 /// <summary>
 /// перемещает фигуру на доступное для этого поле
 /// </summary>
 /// <param name="old_cell"> Старое поле </param>
 /// <param name="new_cell"> Нвое поле </param>
 public void ReplaceFigure(ChessCell old_cell, ChessCell new_cell)
 {
     new_cell.CurrentChess           = old_cell.CurrentChess;
     new_cell.CurrentChess.FirstTurn = false;
     old_cell.CurrentChess           = null;
 }