Beispiel #1
0
    /// <summary>
    /// вызывается если активны уже 2 фигуры и проверяется что с ними делать
    /// </summary>
    /// <param name="name"> Имя фигуры </param>
    /// <param name="color"> Цвет фигуры </param>
    public void isMoveCanBe(string name, int color)
    {
        if (State == 0)
        {
            if (name == "pawn")
            {
                // Debug.Log("nameCorrect");
                if (color == 0)
                {
                    //  Debug.Log("colorCorrect");
                    pawn pn = new pawn();
                    if (board[z, x].first_move == false)
                    {
                        pn.first_move = false;
                    }

                    pn.PossibleMoves(z, x);

                    for (int i = 0; i < pn.P_Moves.Count; i++)
                    {
                        if (pn.P_Moves[i].z == second_z & pn.P_Moves[i].x == second_x)
                        {
                            board[z, x].first_move = false;
                            MoveFigure();
                        }
                    }
                }
                else // color == 1
                {
                    pawn pn = new pawn();
                    pn.PossibleMoves(z, x);

                    for (int i = 0; i < pn.Attack_Moves.Count; i++)
                    {
                        if (pn.Attack_Moves[i].z == second_z & pn.Attack_Moves[i].x == second_x)
                        {
                            AttackFigure();
                        }
                    }
                }
            }


            if (name == "queen")
            {
                // Debug.Log("nameCorrect");


                //  Debug.Log("colorCorrect");
                queen q = new queen();

                q.PossibleMoves(z, x);

                for (int i = 0; i < q.P_Moves_Up.Count; i++)
                {
                    if (q.P_Moves_Up[i].z == second_z & q.P_Moves_Up[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_Down.Count; i++)
                {
                    if (q.P_Moves_Down[i].z == second_z & q.P_Moves_Down[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_Left.Count; i++)
                {
                    if (q.P_Moves_Left[i].z == second_z & q.P_Moves_Left[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_Right.Count; i++)
                {
                    if (q.P_Moves_Right[i].z == second_z & q.P_Moves_Right[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_LeftUp.Count; i++)
                {
                    if (q.P_Moves_LeftUp[i].z == second_z & q.P_Moves_LeftUp[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_RightUp.Count; i++)
                {
                    if (q.P_Moves_RightUp[i].z == second_z & q.P_Moves_RightUp[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }


                for (int i = 0; i < q.P_Moves_RightDown.Count; i++)
                {
                    if (q.P_Moves_RightDown[i].z == second_z & q.P_Moves_RightDown[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_LeftDown.Count; i++)
                {
                    if (q.P_Moves_LeftDown[i].z == second_z & q.P_Moves_LeftDown[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }
            }

            if (name == "king")
            {
                king k = new king();

                k.PossibleMoves(z, x);

                for (int i = 0; i < k.P_Moves.Count; i++)
                {
                    if (k.P_Moves[i].z == second_z & k.P_Moves[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < k.P_Moves_r.Count; i++)
                {
                    if (k.P_Moves_r[i].z == second_z & k.P_Moves_r[i].x == second_x)
                    {
                        RokirovkaMove();
                        MoveFigure();
                    }
                }
            }


            if (name == "rook")
            {
                rook rk = new rook();

                rk.PossibleMoves(z, x);

                for (int i = 0; i < rk.P_Moves_Up.Count; i++)
                {
                    if (rk.P_Moves_Up[i].z == second_z & rk.P_Moves_Up[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < rk.P_Moves_Down.Count; i++)
                {
                    if (rk.P_Moves_Down[i].z == second_z & rk.P_Moves_Down[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < rk.P_Moves_Left.Count; i++)
                {
                    if (rk.P_Moves_Left[i].z == second_z & rk.P_Moves_Left[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < rk.P_Moves_Right.Count; i++)
                {
                    if (rk.P_Moves_Right[i].z == second_z & rk.P_Moves_Right[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }
            }


            if (name == "bishop")
            {
                bishop q = new bishop();

                q.PossibleMoves(z, x);

                for (int i = 0; i < q.P_Moves_LeftUp.Count; i++)
                {
                    if (q.P_Moves_LeftUp[i].z == second_z & q.P_Moves_LeftUp[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_RightUp.Count; i++)
                {
                    if (q.P_Moves_RightUp[i].z == second_z & q.P_Moves_RightUp[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }


                for (int i = 0; i < q.P_Moves_RightDown.Count; i++)
                {
                    if (q.P_Moves_RightDown[i].z == second_z & q.P_Moves_RightDown[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_LeftDown.Count; i++)
                {
                    if (q.P_Moves_LeftDown[i].z == second_z & q.P_Moves_LeftDown[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }
            }


            if (name == "knight")
            {
                knight q = new knight();

                q.PossibleMoves(z, x);

                for (int i = 0; i < q.P_Moves.Count; i++)
                {
                    if (q.P_Moves[i].z == second_z & q.P_Moves[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            if (color == 0)
                            {
                                MoveFigure();
                            }
                            else
                            {
                                AttackFigure();
                            }
                        }
                        else
                        {
                            if (color == 0)
                            {
                                MoveFigure();
                            }
                            else
                            {
                                AttackFigure();
                            }
                        }
                    }
                }
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Сборка всех ходов
    /// </summary>
    public void checkForMovement()      // собирает все возможные ходы
    {
        Core scriptToAccess = Core_object.GetComponent <Core>();

        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                if (scriptToAccess.board[i, j].figure_name == "bishop")
                {
                    if (scriptToAccess.board[i, j].colors_of_figure == 1)
                    {
                        bishop b = new bishop();
                        b.colors_of_figure = 1;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.All_moves.Count; x++)
                        {
                            Debug.Log("bishops");

                            All_mv.Add(b.All_moves[x]);
                        }
                    }
                    else // иначе мы смотрим ход для игрока
                    {
                        bishop b = new bishop();
                        b.colors_of_figure = 0;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.All_moves.Count; x++)
                        {
                            //    Debug.Log("bishops");

                            //       P_All_mv.Add(b.All_moves[x]);
                        }
                    }
                }

                if (scriptToAccess.board[i, j].figure_name == "king")
                {
                    if (scriptToAccess.board[i, j].colors_of_figure == 1)
                    {
                        king b = new king();
                        b.colors_of_figure = 1;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.P_Moves.Count; x++)
                        {
                            Debug.Log("king");

                            All_mv.Add(b.P_Moves[x]);
                        }
                    }
                    else // иначе мы смотрим ход для игрока
                    {
                        king b = new king();
                        b.colors_of_figure = 1;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.P_Moves.Count; x++)
                        {
                            //        P_All_mv.Add(b.P_Moves[x]);
                        }
                    }
                }

                if (scriptToAccess.board[i, j].figure_name == "knight")
                {
                    if (scriptToAccess.board[i, j].colors_of_figure == 1)
                    {
                        knight b = new knight();
                        b.colors_of_figure = 1;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.P_Moves.Count; x++)
                        {
                            Debug.Log("knight");
                            Debug.Log(b.P_Moves[x].z);
                            Debug.Log(b.P_Moves[x].x);

                            All_mv.Add(b.P_Moves[x]);

                            //  Debug.Log(All_mv.Count);
                            //  Debug.Log(scriptToAccess.board[0, 6].colors_of_figure);
                        }
                    }
                    else
                    {
                        knight b = new knight();
                        b.colors_of_figure = 0;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.P_Moves.Count; x++)
                        {
                            //       Debug.Log("knight");
                            //         P_All_mv.Add(b.P_Moves[x]);
                            //     //  Debug.Log(scriptToAccess.board[0, 6].colors_of_figure);
                        }
                    }
                }

                if (scriptToAccess.board[i, j].figure_name == "pawn")
                {
                    if (scriptToAccess.board[i, j].colors_of_figure == 1)
                    {
                        pawn b = new pawn();
                        b.colors_of_figure = 1;
                        b.PossibleMovesAI(i, j);
                        for (int x = 0; x < b.P_Moves.Count; x++)
                        {
                            Debug.Log("pawn");
                            All_mv.Add(b.P_Moves[x]);
                        }

                        for (int x = 0; x < b.Attack_Moves.Count; x++)
                        {
                            Debug.Log("pawn");
                            All_mv.Add(b.Attack_Moves[x]);
                        }
                    }
                    else
                    {
                        pawn b = new pawn();
                        b.colors_of_figure = 0;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.P_Moves.Count; x++)
                        {
                            //    P_All_mv.Add(b.P_Moves[x]);
                        }

                        for (int x = 0; x < b.Attack_Moves.Count; x++)
                        {
                            //     P_All_mv.Add(b.Attack_Moves[x]);
                        }
                    }
                }

                if (scriptToAccess.board[i, j].figure_name == "queen")
                {
                    if (scriptToAccess.board[i, j].colors_of_figure == 1)
                    {
                        queen b = new queen();
                        b.colors_of_figure = 1;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.All_moves.Count; x++)
                        {
                            Debug.Log("queen");

                            All_mv.Add(b.All_moves[x]);
                        }
                    }
                    else // иначе мы смотрим ход для игрока
                    {
                        queen b = new queen();
                        b.colors_of_figure = 0;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.All_moves.Count; x++)
                        {
                            //       Debug.Log("queen");

                            //    P_All_mv.Add(b.All_moves[x]);
                        }
                    }
                }


                if (scriptToAccess.board[i, j].figure_name == "rook")
                {
                    if (scriptToAccess.board[i, j].colors_of_figure == 1)
                    {
                        rook b = new rook();
                        b.colors_of_figure = 1;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.All_moves.Count; x++)
                        {
                            Debug.Log("rook");

                            All_mv.Add(b.All_moves[x]);
                        }
                    }
                    else // иначе мы смотрим ход для игрока
                    {
                        rook b = new rook();
                        b.colors_of_figure = 0;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.All_moves.Count; x++)
                        {
                            //       Debug.Log("rook");

                            //   P_All_mv.Add(b.All_moves[x]);
                        }
                    }
                }
            }
        }
    }