Exemplo n.º 1
0
        /// <summary>
        /// Конструктор класса
        /// </summary>
        /// <param name="parGame"></param>
        public LaserGameSolver(LasersGame parGame)
            : base(parGame)
        {
            _Task = parGame;
            _Mirrors = _Task.Mirrors;
            _Holes = _Task.Holes;
            _Goals = _Task.Goals;
            _Laser = _Task.Laser;
            _FieldHeight = _Task.FieldHeight;
            _FieldWidth = _Task.FieldWidth;

            MaxAlowableDepth = _Task.Mirrors.Count;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Конструктор класса
        /// </summary>
        /// <param name="parFieldWidth">Ширина поля</param>
        /// <param name="parFieldHeight">Выста поля</param>
        /// <param name="parLaser">Лазер</param>
        /// <param name="parGoal">Целевая точка</param>
        /// <param name="parMirrors">Зеркала</param>
        public LasersGame(int parFieldWidth, int parFieldHeight, LaserSource parLaser, List<Goal> parGoals, List<Square> parMirrors, List<Square> parHoles)
        {
            _FieldHeight = parFieldHeight;
            _FieldWidth = parFieldWidth;

            parLaser.Vector = new Point(parLaser.Vector.X * COORDINATE_RATIO / (2 * Math.Abs(parLaser.Vector.X)) ,
                                        parLaser.Vector.Y * COORDINATE_RATIO / (2 * Math.Abs(parLaser.Vector.Y)));

            _Laser = new Laser(parLaser);

            _Goals = parGoals;

            _Mirrors = parMirrors;

            _Holes = parHoles;
        }
Exemplo n.º 3
0
        void LaserProjection()
        {
            direction = initDirection.position - transform.position;

            Ray ray = new Ray();

            ray.origin    = this.transform.position;
            ray.direction = direction;

            RaycastHit hit;

            if (Physics.Raycast(ray.origin, ray.direction, out hit, 150, layermask))
            {
                ObjectInfo hitInfo = hit.transform.gameObject.GetComponentInParent <ObjectInfo>();

                if (hitInfo != null)
                {
                    ObjectType hitType = hitInfo.objectType;
                    lineRenderer.SetPosition(0, this.transform.position);
                    lineRenderer.SetPosition(1, hit.point);


                    if (hitType == ObjectType.Reflector)
                    {
                        if (!recreate)
                        {
                            RotateAngle angle    = hitInfo.rotateAngle;
                            GameObject  newLight = Instantiate(transform.parent.gameObject, hit.point, Quaternion.identity);
                            newLight.transform.parent = this.transform;
                            LaserSource.laserList.Add(newLight);
                            Laser newLaser = newLight.gameObject.GetComponentInChildren <Laser>();
                            newLaser.initDirection.localPosition = SetDirection(angle);
                            this.recreate = true;
                        }
                    }

                    if (hitType == ObjectType.Dispersant)
                    {
                        if (!recreate)
                        {
                            int          hitKey   = hit.transform.gameObject.GetComponent <ObjectPart>().key;
                            GameObject[] newLight = new GameObject[4];
                            for (int i = 0; i < 4; i++)
                            {
                                if (i == hitKey)
                                {
                                    continue;
                                }
                                ObjectPart  hitPart = hitInfo.objectParts[i];
                                RotateAngle angle   = hitPart.rotateAngle;
                                Vector3     newPos  = hitPart.Position;
                                newLight[i] = Instantiate(transform.parent.gameObject, newPos, Quaternion.identity);
                                Laser newLaser = newLight[i].gameObject.GetComponentInChildren <Laser>();
                                newLaser.initDirection.localPosition = SetDirection(angle);
                            }

                            for (int i = 0; i < 4; i++)
                            {
                                if (newLight[i] == null)
                                {
                                    continue;
                                }
                                newLight[i].transform.parent = this.transform;
                                LaserSource.laserList.Add(newLight[i]);
                            }

                            this.recreate = true;
                        }
                    }

                    if (hitType == ObjectType.Transmission)
                    {
                        if (!recreate)
                        {
                            int        hitKey = hit.transform.gameObject.GetComponent <ObjectPart>().key;
                            GameObject newLight;
                            if (hitKey == 0)
                            {
                                ObjectPart  hitPart = hitInfo.objectParts[1];
                                RotateAngle angle   = hitPart.rotateAngle;
                                Vector3     newPos  = hitPart.Position;
                                newLight = Instantiate(transform.parent.gameObject, newPos, Quaternion.identity);
                                newLight.transform.parent = this.transform;
                                Laser newLaser = newLight.gameObject.GetComponentInChildren <Laser>();
                                newLaser.initDirection.localPosition = SetDirection(angle);
                            }
                            else if (hitKey == 1)
                            {
                                ObjectPart hitPart = hitInfo.objectParts[0];
                                Debug.Log(hitPart.transform.parent.name);
                                RotateAngle angle  = hitPart.rotateAngle;
                                Vector3     newPos = hitPart.Position;
                                newLight = Instantiate(transform.parent.gameObject, newPos, Quaternion.identity);
                                newLight.transform.parent = this.transform;
                                Laser newLaser = newLight.gameObject.GetComponentInChildren <Laser>();
                                newLaser.initDirection.localPosition = SetDirection(angle);
                            }
                        }

                        this.recreate = true;
                    }

                    if (hitType == ObjectType.Absorber)
                    {
                        hitInfo.doors.SetTrigger("Openning");
                    }

                    if (hitType == ObjectType.Wall)
                    {
                        laserSource.isUpdate = true;
                        this.recreate        = true;
                    }
                }
            }

            projection = false;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Конструктор класса;
        /// </summary>
        public LasersGame(int parFieldWidth, int parFieldHeight)
        {
            _FieldHeight = parFieldHeight;
            _FieldWidth = parFieldWidth;
            _Laser = new Laser(new Point(0, 0), new Point(- COORDINATE_RATIO / 2, COORDINATE_RATIO / 2));

            _Goals = new List<Goal>();

            _Mirrors = new List<Square>();

            _Holes = new List<Square>();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Установить лазер
        /// </summary>
        /// <param name="parPos">Положение лазера</param>
        /// <param name="parVector">Вектор направления лазера</param>
        public void SetUpLaser(LaserSource parLaserSource)
        {
            if (PointInField(parLaserSource.Position))
            {
                Point vector = parLaserSource.Vector;

                vector.X = parLaserSource.Vector.X * COORDINATE_RATIO / (2 * Math.Abs(parLaserSource.Vector.X));
                vector.Y = parLaserSource.Vector.Y * COORDINATE_RATIO / (2 * Math.Abs(parLaserSource.Vector.Y));
                parLaserSource.Vector = vector;

                _Laser = new Laser(parLaserSource);

                CalculateLaser();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Установить лазер
        /// </summary>
        /// <param name="parPos">Положение лазера</param>
        /// <param name="parVector">Вектор направления лазера</param>
        public void SetUpLaser(Point parPos, Point parVector)
        {
            if (PointInField(parPos))
            {
                parVector.X = parVector.X * COORDINATE_RATIO / (2 * Math.Abs(parVector.X));
                parVector.Y = parVector.Y * COORDINATE_RATIO / (2 * Math.Abs(parVector.Y));

                _Laser = new Laser(parPos, parVector);

                CalculateLaser();
            }
        }