Ejemplo n.º 1
0
 private void SecondClick(Checker checker)
 {
     if (jump)
     {
         if (battleCheckers.Contains(new Cell(checker.x, checker.y)))
         {
             MoveChecker(currentChecker, checker);
             DeleteCheckers();
             FirstClick(checker);
         }
     }
     else
     {
         if (moves.Contains(new Cell(checker.x, checker.y)))
         {
             MoveChecker(currentChecker, checker);
         }
     }
     if (!jump) ChangePlayer();
     DeleteHighlight();
     IsChecked = false;
 }
Ejemplo n.º 2
0
 public void Step(Checker checker)
 {
     if (IsChecked && checker.IsChecker == 0)
     {
         SecondClick(checker);
     }
     else
     {
         if (checker.IsChecker != 0 && checker.CheckerColor == currentPlayer)
         {
             FirstClick(checker);
         }
     }
 }
Ejemplo n.º 3
0
        private void FirstClick(Checker checker)
        {
            //ResetFieldColor();
            DeleteHighlight();
            moves.Clear();
            battleCheckers.Clear();
            CheckAllFields();
            if (battleCheckers.Count != 0) jump = true;
            else jump = false;

            if (jump)
            {
                //if (checker.needBattle)
                JumpArray(checker);
                Highlight(battleCheckers, 2);
            }
            else
            {
                MoveArray(checker);
                Highlight(moves, 1);
            }
            if (moves.Count != 0 || battleCheckers.Count != 0) IsChecked = true;
            currentChecker = ArrayField[checker.x, checker.y];
        }
Ejemplo n.º 4
0
        public void MoveChecker(Checker checker_start, Checker checker_end)
        {
            if (isEmptySpace(checker_end.x, checker_end.y) && checker_end.FieldIsBlack)
            {
                checker_end.IsChecker = 1;
                checker_end.CheckerColor = checker_start.CheckerColor;
                checker_end.fieldIsHighlight = 0;

                checker_start.IsChecker = 0;
                checker_start.CheckerColor = 0;

                ArrayField[checker_end.x, checker_end.y] = checker_end;
                ArrayField[checker_start.x, checker_start.y] = checker_start;
            }
            //DeleteCheckers();
            //if (!jump) ChangePlayer();
        }
Ejemplo n.º 5
0
        public void MoveArray(Checker checker)
        {
            //List<Cell> result = new List<Cell>(); // список клеток доступных для хода
            int x, y;

            if (checkBorders(checker.x - 1, checker.y - 1))
            {
                x = checker.x - 1;
                y = checker.y - 1;
                if (ArrayField[x, y].IsChecker == 0)
                {
                    if (checker.CheckerColor == 1) // шашки ходят только вперед
                        moves.Add(new Cell(x, y));
                }

            }
            if (checkBorders(checker.x + 1, checker.y - 1))
            {
                x = checker.x + 1;
                y = checker.y - 1;
                if (ArrayField[x, y].IsChecker == 0)
                {
                    if (checker.CheckerColor == 1)
                        moves.Add(new Cell(x, y));
                }

            }
            if (checkBorders(checker.x + 1, checker.y + 1))
            {
                x = checker.x + 1;
                y = checker.y + 1;
                if (ArrayField[x, y].IsChecker == 0)
                {
                    if (checker.CheckerColor == 2)
                        moves.Add(new Cell(x, y));
                }

            }
            if (checkBorders(checker.x - 1, checker.y + 1))
            {
                x = checker.x - 1;
                y = checker.y + 1;
                if (ArrayField[x, y].IsChecker == 0)
                {
                    if (checker.CheckerColor == 2)
                        moves.Add(new Cell(x, y));
                }

            }
            //if (checkersToDelete.Count == 0) jump = false;
            //return result;
        }
Ejemplo n.º 6
0
 public void JumpArray(Checker checker)
 {
     //List<Cell> result = new List<Cell>();
     if (checker.FieldIsBlack && checker.IsChecker == 1 && checker.CheckerColor == currentPlayer)
     {
         if (checkBorders(checker.x - 1, checker.y - 1))
         {
             if (ArrayField[checker.x - 1, checker.y - 1].CheckerColor != checker.CheckerColor)
             {
                 if (checkBorders(checker.x - 2, checker.y - 2))
                     if (isEmptySpace(checker.x - 2, checker.y - 2))
                     {
                         //result.Add(new Cell(checker.x - 2, checker.y - 2));
                         checkersToDelete.Add(new Cell(checker.x - 1, checker.y - 1));
                     }
             }
         }
         if (checkBorders(checker.x + 1, checker.y - 1))
         {
             if (ArrayField[checker.x + 1, checker.y - 1].CheckerColor != checker.CheckerColor)
             {
                 if (checkBorders(checker.x + 2, checker.y - 2))
                     if (isEmptySpace(checker.x + 2, checker.y - 2))
                     {
                         //result.Add(new Cell(checker.x + 2, checker.y - 2));
                         checkersToDelete.Add(new Cell(checker.x + 1, checker.y - 1));
                     }
             }
         }
         if (checkBorders(checker.x + 1, checker.y + 1))
         {
             if (ArrayField[checker.x + 1, checker.y + 1].CheckerColor != checker.CheckerColor)
             {
                 if (checkBorders(checker.x + 2, checker.y + 2))
                     if (isEmptySpace(checker.x + 2, checker.y + 2))
                     {
                         //result.Add(new Cell(checker.x + 2, checker.y + 2));
                         checkersToDelete.Add(new Cell(checker.x + 1, checker.y + 1));
                     }
             }
         }
         if (checkBorders(checker.x - 1, checker.y + 1))
         {
             if (ArrayField[checker.x - 1, checker.y + 1].CheckerColor != checker.CheckerColor)
             {
                 if (checkBorders(checker.x - 2, checker.y + 2))
                     if (isEmptySpace(checker.x - 2, checker.y + 2))
                     {
                         //result.Add(new Cell(checker.x - 2, checker.y + 2));
                         checkersToDelete.Add(new Cell(checker.x - 1, checker.y + 1));
                     }
             }
         }
     }
     //return result;
 }
Ejemplo n.º 7
0
        public void InitGame()
        {
            this.size = 8;
            ArrayField = new Checker [this.size, this.size];
            bool isBlack = false;
            checkersToDelete = new List<Cell>(); // возможные бои для выбранной шашки
            battleCheckers = new List<Cell>(); // все возможные бои на доске
            moves = new List<Cell>(); // возможные ходы для выбранной шашки
            jump = false;
            currentPlayer = 1; // 1 - white, 2 - black
            IsChecked = false;
            countWhiteChecker = countBlackChecker = 12;

            for (int x = 0; x < this.size; x++)
            {
                for (int y = 0; y < this.size; y++)
                {
                    if (isBlack && y < 3)
                        ArrayField[x, y] = new Checker(x, y, 1, 2, true, false, 0);
                    else if (isBlack && y > 4)
                        ArrayField[x, y] = new Checker(x, y, 1, 1, true, false, 0);
                    else if (isBlack)
                        ArrayField[x, y] = new Checker(x, y, 0, 0, true, false, 0);
                    else
                        ArrayField[x, y] = new Checker(x, y, 0, 0, false, false, 0);
                    isBlack = !isBlack;
                }
                isBlack = !isBlack;
            }
        }
Ejemplo n.º 8
0
        private byte TranslateChecker(Checker checker)
        {
            byte n = 0;

            for (int x = 0; x < game.size; x++)
            {
                for (int y = 0; y < game.size; y++)
                {
                    n++;
                    if (checker.x == x && checker.y == y)
                        return n;
                }
            }
            return 0;
        }