Exemplo n.º 1
0
        public Board()
        {
            board = new Cell[8, 8];

            var counter = 0;
            for (var row = 0; row < board.GetLength(0); row++)
            {
                for (var column = 0; column < board.GetLength(1); column++)
                {
                    if (counter % (board.GetLength(0) + 1) == 0)
                    {
                        counter++;
                    }

                    board[row, column] = new Cell();

                    if (counter % 2 != 0)
                    {
                        board[row, column].IsUsable = false;
                    }
                    counter++;
                }
            }
        }
Exemplo n.º 2
0
Arquivo: Cell.cs Projeto: jysr/TP
        /* #region Diagonals;
        // A1 - H8
        private bool goldWay;

        public bool GoldWay
        {
        get { return goldWay; }
        set { goldWay = value; }
        }
        // G1 - A7
        private bool doubleWay1;

        public bool DoubleWay1
        {
        get { return doubleWay1; }
        set { doubleWay1 = value; }
        }
        // H2 - B8
        private bool  doubleWay2;

        public bool DoubleWay2
        {
        get { return doubleWay2; }
        set { doubleWay2 = value; }
        }
        #region tripleWay
        // C1 - A3
        private bool tripleWay1;

        public bool TripleWay1
        {
        get { return tripleWay1; }
        set { tripleWay1 = value; }
        }
        // A3 - F8
        private bool tripleWay2;

        public bool TripleWay2
        {
        get { return tripleWay2; }
        set { tripleWay2 = value; }
        }
        // F8 - H6
        private bool tripleWay3;

        public bool TripleWay3
        {
        get { return tripleWay3; }
        set { tripleWay3 = value; }
        }
        // H6 - C1
        private bool tripleWay4;

        public bool TripleWay4
        {
        get { return tripleWay4; }
        set { tripleWay4 = value; }
        }
        #endregion
        #region ultraWay
        // A5 - D8
        private bool ultraWay1;

        public bool UltraWay1
        {
        get { return ultraWay1; }
        set { ultraWay1 = value; }
        }
        // D8 - H4
        private bool ultraWay2;

        public bool UltraWay2
        {
        get { return ultraWay2; }
        set { ultraWay2 = value; }
        }
        // H4 - E1
        private bool ultraWay3;

        public bool UltraWay3
        {
        get { return ultraWay3; }
        set { ultraWay3 = value; }
        }

        // E1 - A5
        private bool ultraWay4;

        public bool UltraWay4
        {
        get { return ultraWay4; }
        set { ultraWay4 = value; }
        }

        #endregion

        #endregion */
        public void Update(Cell[,] Field, string previousCell)
        {
            if (Rect.Contains(new Point(Mouse.GetState().X, Mouse.GetState().Y)) && Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                //This element was clicked
                OnClick(Field, Rect, previousCell);

            }
            //switch (colorOfPl)
            //{
            //    case ColorOfPl.white:
            //        Ocupied = 1;
            //        break;
            //    case ColorOfPl.black:
            //        Ocupied = 2;
            //        break;
            //    case ColorOfPl.none:
            //        Ocupied = 0;
            //        break;
            //}
        }
Exemplo n.º 3
0
Arquivo: Cell.cs Projeto: jysr/TP
        public void OnMove(Cell[,] Field, string previousCell)
        {
            Cell cell;
            cell = Field[0, 0];
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (Field[i,j].name == previousCell)
                    {
                        cell = Field[i, j];
                        break;
                    }
                }
            }

            if (this.name != previousCell && this.border)
            {
                if (this.ocupied == 0)
                {

                    if (cell.Ocupied == 1)
                    {
                        cell.Ocupied = 0;
                        this.ocupied = 1;
                    }
                    if (cell.Ocupied == 2)
                    {
                        cell.Ocupied = 0;
                        this.ocupied = 2;
                    }
                }
            }

                    for (int i = 0; i < 8; i++)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            if ((int.Parse(cell.Name) + int.Parse(this.name))/2 == int.Parse(Field[i,j].name))
                            {
                                Field[i, j].Ocupied = 0;
                            }

                        }

                    }
        }
Exemplo n.º 4
0
Arquivo: Cell.cs Projeto: jysr/TP
        public void OnClick(Cell[,] Field, Rectangle rect, string previousCell)
        {
            if (ocupied == 1 || ocupied == 2)
            {
                Coloring(Field);

            }
            else
            {
                OnMove(Field, previousCell);
            }
        }
Exemplo n.º 5
0
Arquivo: Cell.cs Projeto: jysr/TP
        public void Coloring(Cell[,] Field)
        {
            int line = 0;
            int stolb = 0;
            foreach (Cell c in Field)
            {
                c.border = false;
            }

            border = true;
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (this.name == Field[i, j].name)
                    {
                        line = i;
                        stolb = j;

                        if (this.ocupied == 1)
                        {
                            Field[i, j].border = true;

                            if ((i + 1 < 8)&& (Field[i + 1, j].ocupied != 1 || ((j - 1 > -1) && Field[i + 1, j - 1].ocupied != 1)))
                            {
                                if (Field[i + 1, j].ocupied == 2 || ((j - 1 > -1) && Field[i + 1, j - 1].ocupied == 2))
                                {
                                    if (Field[i + 1, j].ocupied == 2 && (j+2 < 4))
                                        Field[i + 2, j + 1].border = true;
                                  if( (j - 1 > -1) && Field[i + 1, j - 1].ocupied == 2)
                                        Field[i + 2, j - 1].border = true;
                                }
                                else
                                {
                                    Field[i + 1, j].border = true;
                                          if ((j - 1 > -1))
                                        Field[i + 1, j - 1].border = true;
                                }
                                break;
                            }

                            }
                        if (this.ocupied == 2)
                        {
                            Field[i, j].border = true;

                            if ((i -  1 > -1) && (Field[i - 1, j].ocupied != 2 || ((j - 1 > -1) && Field[i - 1, j - 1].ocupied != 2)))
                            {
                                if (Field[i - 1, j].ocupied == 1 || ((j - 1 > -1) && Field[i - 1, j - 1].ocupied == 1))
                                {
                                    if (Field[i - 1, j].ocupied == 1 && (j + 2 < 4))
                                        Field[i - 2, j].border = true;
                                    if ((j - 1 > -1) && Field[i + 1, j - 1].ocupied == 1)
                                        Field[i - 2, j].border = true;
                                }
                                else
                                {
                                    Field[i - 1, j].border = true;
                                    if ((j + 1 < 4))
                                        Field[i - 1, j+1].border = true;
                                }

                                break;
                            }

                        }

                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Выбор целевой ячейки для хода или боя
        /// </summary>
        /// <param name="location"></param>
        public void SelectTargetCell(Address location)
        {
            if (_game.WinPlayer != WinPlayer.Game)
            {
                return;
            }
            Cell cell;

            if (GetCell(location, out cell) && cell.State != State.Prohibited)
            {
                if (_game.Mode == PlayMode.Game || _game.Mode == PlayMode.NetGame)
                {
                    if (_game.Player == Player.Black && !_game.Direction ||
                        _game.Player == Player.White && _game.Direction)
                    {
                        return;
                    }
                }
                if (Selected != null && cell.State == State.Empty) // ранее была выбрана фишка и выбрана пустая клетка
                // пробуем делать ход
                {
                    var startPos   = Selected.Address;
                    var endPos     = cell.Address;
                    var moveResult = MakeMove(startPos, endPos);
                    Selected = null;  // после хода сбрасываем текущую выбранную фишку
                    if (moveResult != MoveResult.Prohibited)
                    {
                        // подсчёт очков
                        if (moveResult == MoveResult.SuccessfullCombat)
                        {
                            if (_game.Direction)
                            {
                                _game.BlackScore++;
                            }
                            else
                            {
                                _game.WhiteScore++;
                            }
                        }
                        _game.CheckWin();
                        // считаем количество непрерывных ходов одной стороной
                        _movedCount++;
                        // определение дамки
                        if (!cell.King &&
                            (!_game.Direction && cell.Address.Row == SideSize ||
                             _game.Direction && cell.Address.Row == 1))
                        {
                            cell.King = true;
                        }
                        var hasCombat = HasCombat(endPos); // есть ли в этой позиции возможность боя
                        // запоминаем очередь хода перед возможной сменой
                        var lastDirection = _game.Direction;
                        // или был бой и далее нет возможности боя
                        if (moveResult == MoveResult.SuccessfullCombat && !hasCombat ||
                            moveResult == MoveResult.SuccessfullMove)
                        {
                            // сообщаем о перемещении фишки
                            OnCheckerMoved(lastDirection, startPos, endPos, moveResult, _movedCount);
                            // сбрасываем количество непрерывных ходов одной стороной
                            _movedCount = 0;
                            // передача очерёдности хода
                            _game.Direction = !_game.Direction;
                            OnActivePlayerChanged();
                            _game.CheckWin();
                            if (_game.WinPlayer == WinPlayer.None)
                            {
                                CheckAvailableGoals();
                            }
                            return;
                        }
                        else if (moveResult == MoveResult.SuccessfullCombat && hasCombat)
                        {
                            // выбрана фишка для продолжения боя
                            SetSelectedCell(cell);
                        }
                        // сообщаем о перемещении фишки
                        OnCheckerMoved(lastDirection, startPos, endPos, moveResult, _movedCount);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public override string ToString()
        {
            var result = string.Empty;
            var counter = 0;

            for (var row = 0; row < board.GetLength(0); row++)
            {
                for (var column = 0; column < board.GetLength(1); column++)
                {
                    if (counter % (board.GetLength(0) + 1) == 0)
                    {
                        counter++;
                    }
                    board[row, column] = new Cell();

                    if (counter % 2 != 0)
                    {
                        board[row, column].IsUsable = false;
                        result += "_";
                    }
                    else
                    {
                        result += "Y";
                    }
                    counter++;
                }
                result += Environment.NewLine;
            }
            return result;
        }