예제 #1
0
        public void instantiate_mark_points(List <Vector3> coords)
        {
            foreach (var coord in coords)
            {
                Vector3 newCoord = coord;
                newCoord.z -= 1;

                GameObject          markPoint           = Instantiate(markPointPrefab, newCoord, Quaternion.identity);
                MarkPointController markPointController = markPoint.GetComponent <MarkPointController>();
                markPointController.connectedPieceGameObject = this;
            }
        }
예제 #2
0
        public void handle_castling_rule(Vector3Int oldCell, Vector3Int newCell)
        {
            GameObject[] markPoints = get_mark_points();

            if (gameObject.GetComponentInChildren(typeof(King)) && timesMoved == 0)
            {
                // Left Rook
                if (newCell.x - oldCell.x == -2)
                {
                    foreach (var markPoint in markPoints)
                    {
                        MarkPointController markPointController =
                            (MarkPointController)markPoint.GetComponentInChildren(typeof(MarkPointController));

                        if (leftRookCellDestination ==
                            get_cell_from_coord(markPointController.transform.position))
                        {
                            castlingConnectedLeftRook.move(leftRookCellDestination);
                        }
                    }
                }

                // Right Rook
                if (newCell.x - oldCell.x == 2)
                {
                    foreach (var markPoint in markPoints)
                    {
                        MarkPointController markPointController =
                            (MarkPointController)markPoint.GetComponentInChildren(typeof(MarkPointController));

                        if (rightRookCellDestination ==
                            get_cell_from_coord(markPointController.transform.position))
                        {
                            castlingConnectedRighttRook.move(rightRookCellDestination);
                        }
                    }
                }
            }
        }
예제 #3
0
파일: Pawn.cs 프로젝트: YosufE/chess-unity
        public void link_en_passant_rule_objs_to_mark_points(GameObject[] markPoints)
        {
            if (gameObject.GetComponentInChildren(typeof(Pawn)))
            {
                Pawn pawnComponent = (Pawn)GetComponentInChildren(typeof(Pawn));
                foreach (var markPoint in markPoints)
                {
                    MarkPointController markPointController =
                        (MarkPointController)markPoint.GetComponentInChildren(typeof(MarkPointController));

                    foreach (var killGameObject in pawnComponent.enPassantRuleLinked)
                    {
                        Pawn pawnComp = (Pawn)killGameObject.GetComponentInChildren(typeof(Pawn));
                        if (inverted)
                        {
                            Vector3 killMarkPoint =
                                get_center_of_cell(get_cell_down_times(pawnComp.get_current_cell(), 1));
                            if (markPointController.transform.position.x == killMarkPoint.x &&
                                markPointController.transform.position.y == killMarkPoint.y)
                            {
                                markPointController.connectedKillGameObject = killGameObject;
                            }
                        }
                        else
                        {
                            Vector3 killMarkPoint =
                                get_center_of_cell(get_cell_up_times(pawnComp.get_current_cell(), 1));
                            if (markPointController.transform.position.x == killMarkPoint.x &&
                                markPointController.transform.position.y == killMarkPoint.y)
                            {
                                markPointController.connectedKillGameObject = killGameObject;
                            }
                        }
                    }
                }
            }
        }