Beispiel #1
0
 public override void Update(Laser laser)
 {
     if (this.In.Contains(laser))
     {
         foreach (var l in hole1.Lasers.Values)
             Father.UpdateLaser(l);
         foreach (var l in hole2.Lasers.Values)
             Father.UpdateLaser(l);
     }
     else
     {
         Laser added = null;
         if (hole1.Contains(laser.EndPoint))
         {
             if (!hole2.Lasers.Keys.Contains(laser))
             {
                 added = new Laser(this, Father.Content, laser.Color, hole2.X, hole2.Y - 10, laser.Angle);
                 hole2.Lasers.Add(laser, added);
             }
         }
         else
         {
             if (!hole1.Lasers.Keys.Contains(laser))
             {
                 added = new Laser(this, Father.Content, laser.Color, hole1.X, hole1.Y - 10, laser.Angle);
                 hole1.Lasers.Add(laser, added);
             }
         }
         Father.UpdateLaser(added);
     }
 }
Beispiel #2
0
 public override void Update(Laser laser)
 {
     if (laser.Color == this.Color)
     {
         this.In = laser;
         this.Focused = true;
     }
 }
Beispiel #3
0
 public void CheckState()
 {
     if (In == null || In.Father == null || !this.Contains(In.EndPoint))
     {
         this.In = null;
         this.Focused = false;
     }
 }
Beispiel #4
0
 public virtual void Update(Laser laser)
 {
 }
Beispiel #5
0
        /// <summary>
        /// �ع��ߵ�·���ҵ������յ㣬��֪ͨ�յ�����
        /// </summary>
        internal void UpdateLaser(Laser laser)
        {
            if (laser == null) return;
            Point offset;

            if (laser.Angle < 90 || laser.Angle > 270) offset.X = 60;
            else if (laser.Angle > 90 && laser.Angle < 270) offset.X = -60;
            else offset.X = 0;
            if (laser.Angle > 0 && laser.Angle < 180) offset.Y = 60;
            else if (laser.Angle > 180 && laser.Angle < 360) offset.Y = -60;
            else offset.Y = 0;

            Point position = new Point(laser.X + offset.X, laser.Y + offset.Y);
            SpriteBase sprite;
            while (position.X > 0 && position.X < 480 && position.Y > this.Y && position.Y < this.Y + 600)
            {
                if ((sprite = this.FindChildWithPoint(position)) != null)
                {
                    laser.EndPoint = position;
                    if (sprite is Wall) return;
                    sprite.Update(laser);
                    return;
                }
                position.X += offset.X;
                position.Y += offset.Y;
            }
            position.X -= offset.X / 2;
            position.Y -= offset.Y / 2;
            laser.EndPoint = position;
        }
Beispiel #6
0
 internal override void ClearLaser()
 {
     this.Selected = null;
     if (this.Out != null)
     {
         this.Out.Father = null;
         this.Out = null;
     }
     if (this.Extra != null && this.Type == PrismType.Resolve)
     {
         this.Extra.Father = null;
         this.Extra = null;
     }
     this.Type = PrismType.Resolve;
 }
Beispiel #7
0
        public override void Update(Laser laser)
        {
            //���ߺϳɹ�ʽ��
            //������ǵ�ɫ/�̳��ϰ��ǻ��ɫ
            //��+��=��/��+��=��/��+��=��/��ɫ�ϳɰ�
            //�׷ֽ⻹�ǰ�

            if (this.Out == null || this.Type == PrismType.Resolve)
            {
                #region һ��������
                if (this.Out == null)
                {
                    this.Type = PrismType.Resolve;
                    In = laser;

                    switch (laser.Color)
                    {
                        case Colors.red:
                        case Colors.yellow:
                        case Colors.blue:
                        case Colors.white:
                            Out = new Laser(this, this.Father.Content, laser.Color, laser.EndPoint.X, laser.EndPoint.Y - 10, laser.Angle + 45);
                            Extra = new Laser(this, this.Father.Content, laser.Color, laser.EndPoint.X, laser.EndPoint.Y - 10, laser.Angle - 45);
                            break;
                        case Colors.orange:
                            Out = new Laser(this, this.Father.Content, Colors.red, laser.EndPoint.X, laser.EndPoint.Y - 10, laser.Angle + 45);
                            Extra = new Laser(this, this.Father.Content, Colors.yellow, laser.EndPoint.X, laser.EndPoint.Y - 10, laser.Angle - 45);
                            break;
                        case Colors.purple:
                            Out = new Laser(this, this.Father.Content, Colors.red, laser.EndPoint.X, laser.EndPoint.Y - 10, laser.Angle + 45);
                            Extra = new Laser(this, this.Father.Content, Colors.blue, laser.EndPoint.X, laser.EndPoint.Y - 10, laser.Angle - 45);
                            break;
                        case Colors.green:
                            Out = new Laser(this, this.Father.Content, Colors.blue, laser.EndPoint.X, laser.EndPoint.Y - 10, laser.Angle + 45);
                            Extra = new Laser(this, this.Father.Content, Colors.yellow, laser.EndPoint.X, laser.EndPoint.Y - 10, laser.Angle - 45);
                            break;

                    }
                    if(this.Focused) Out.Focused = true;
                    Selected = Out;
                }
                #endregion

                #region ����������
                else
                {
                    if (laser == In) ;
                    else if (laser.Color == In.Color)
                    {
                        Extra.Father = null;
                        Extra = laser;
                        this.Type = PrismType.Blend;
                        Out.SetColor(In.Color);
                    }
                    else
                    {
                        this.Type = PrismType.Blend;
                        Extra.Father = null;
                        Extra = laser;
                        int lc = (int)laser.Color;
                        int ic = (int)In.Color;
                        Colors color;
                        if (lc < 3 && ic < 3)
                        {
                            if (lc + ic == 1) color = Colors.purple;
                            else if (lc + ic == 2) color = Colors.orange;
                            else color = Colors.green;
                        }
                        else color = Colors.white;

                        if (Math.Abs(Math.Abs(Out.Angle - Extra.Angle) - 180) < 1)
                        {
                            float angle = Math.Abs(this.In.Angle - this.Extra.Angle);
                            if (angle > 180)
                            {
                                angle = 360 - angle;
                                angle = angle / 2 + Math.Max(this.In.Angle, this.Extra.Angle);
                            }
                            else
                            {
                                angle = angle / 2 + Math.Min(this.In.Angle, this.Extra.Angle);
                            }

                            angle = (int)(angle / 45) * 45;
                            Out.Angle = angle;
                        }
                        Out.SetColor(color);

                        //Out.Father = null;
                        //Out = new Laser(this, this.Father.Content, color, In.EndPoint.X, In.EndPoint.Y - 10, angle);
                        Out.Focused = this.Focused;
                        Selected = Out;
                    }
                }
                #endregion
            }
            Father.UpdateLaser(Out);
            if (this.Type == PrismType.Resolve) Father.UpdateLaser(Extra);
        }
Beispiel #8
0
        public override void CheckLaser()
        {
            if (this.Type == PrismType.Resolve)
            {
                if (In == null || In.Father == null || !this.Contains(In.EndPoint))
                {
                    this.ClearLaser();
                }
            }

            else
            {
                int exists = 2;
                if (Extra == null || Extra.Father == null || !this.Contains(Extra.EndPoint))
                {
                    Extra = null;
                    Selected = In;
                    exists -= 1;
                }
                if (In == null || In.Father == null || !this.Contains(In.EndPoint))
                {
                    In = null;
                    Selected = Extra;
                    exists -= 1;
                }
                //ֻʣһ������ڣ�״̬�ɺϳɱ�ɷֽ⣬Update
                if (exists == 1)
                {
                    Out.Father = null;
                    Out = null;
                    In = null;
                    this.Update(Selected);
                }
                //��������ⶼ�������ˣ�ִ��ClearLaser
                else if (exists == 0)
                {
                    ClearLaser();
                }
            }

            base.CheckLaser();
        }
Beispiel #9
0
 public void ChangeSelect()
 {
     if (Type == PrismType.Resolve && Selected != null)
     {
         Selected.Focused = false;
         Selected = (Selected == Extra) ? Out : Extra;
         Selected.Focused = true;
     }
 }
Beispiel #10
0
 public override void Update(Laser laser)
 {
     if (laser == null) return;
     if (Out != null && In != laser) return;
     this.In = laser;
     if (//���ܷ��䣬Out��ΪNull
         //�����ӽǶȴ���180��ʱ������������� M - 180 < L < Mʱ����
         (this.Angle >= 180 && (laser.Angle <= this.Angle - 180 || laser.Angle >= this.Angle))
         ||
         //�����ӽǶ�С��180��ʱ������������� M <= L <= M + 180ʱ������
         (this.Angle <= 180 && (laser.Angle >= this.Angle && laser.Angle <= this.Angle + 180))
         || Math.Abs(this.Angle - laser.Angle - 90) % 360 < 0.1
        )
     {
         ClearLaser();
     }
     else//���Է��䣬��Out�Ƿ�Ϊ�գ����ı�Ƕ�
     {
         if (Out == null)
         {
             this.Out = new Laser(this, this.Father.Content, laser.Color, laser.EndPoint.X, laser.EndPoint.Y - 10, 2 * this.Angle - laser.Angle);
         }
         else
         {
             Out.Angle = 2 * this.Angle - laser.Angle;
         }
         Father.UpdateLaser(Out);
     }
 }