void OnLevelFinish() { Finished = true; if (Current != null) { Current.Focused = false; Current = null; } if (LevelFinish != null) this.LevelFinish(this, EventArgs.Empty); }
/// <summary> /// �����û����� /// </summary> private void HandleUserInput() { MouseState state = Mouse.GetState(); #region ���²�������Ҫ�ҵ��������ݣ�����Ϊ�� if (state.LeftButton == ButtonState.Pressed && MouseDown == false) { MouseDown = true; FirstPoint = new Point(state.X, state.Y); if (Current != null) { if (state.Y > ControlPanel.Position.Y) { Offset.Y = 1000; return; } //�����㲻�ǵ�ǰ�㣬ȡ����ǰ���� if (!Current.Contains(FirstPoint)) { Current.Focused = false; Current = null; } else { if (Current is Prism) (Current as Prism).ChangeSelect(); } } #region �����ǰ��Ϊ�գ�Ѱ���µĵ�ǰ�� if (Current == null) { //�����пؼ��� if (FirstPoint.Y < this.Y + 600) { foreach(var le in Lenses) { if(le.Contains(FirstPoint)) { Current = le; le.Focused = true; break; } } } //���������ڿ�������� else if (FirstPoint.Y > ControlPanel.Position.Y) { int where = ControlPanel.PointInWhere(FirstPoint); switch (where) { case 1: if (ControlPanel.PrismCount > 0) { Current = new Prism(this, ControlPanel.Rec1.X, ControlPanel.Rec1.Y); ControlPanel.PrismCount -= 1; } break; case 2: if (ControlPanel.MirrorCount > 0) { Current = new Mirror(this, ControlPanel.Rec2.X, ControlPanel.Rec2.Y); ControlPanel.MirrorCount -= 1; } break; } if (Current != null) { Current.Focused = true; this.Lenses.Add(Current); Current.CanInput = false; } } } #endregion if (Current != null) { Offset.X = FirstPoint.X - Current.X; Offset.Y = FirstPoint.Y - Current.Y; } } #endregion #region �ͷŲ�������Ҫ�ж��ǵ���������ק���� else if (state.LeftButton == ButtonState.Released) { if (MouseDown == true) { if (Current != null && !Current.CanInput) { this.Lenses.Remove(Current); if (Current is Prism) ControlPanel.PrismCount += 1; else if (Current is Mirror) ControlPanel.MirrorCount += 1; UpdateLaser(Current.In); UpdateLaser(Current.Extra); CheckState(); Current = null; return; } //�ж��Ƿ��˿��������ư�ť if (!IsDraging) { int where = ControlPanel.PointInWhere(FirstPoint); if (where != 0) { if (ControlPanel.Style == ControlPanelStyle.Control) { if (where == 1) { Current.RotateLeft(); } else if (where == 2) { Current.RotateRight(); } else if (where == 3) { this.Lenses.Remove(Current); if (Current is Prism) ControlPanel.PrismCount += 1; else if (Current is Mirror) ControlPanel.MirrorCount += 1; UpdateLaser(Current.In); UpdateLaser(Current.Extra); Current = null; } } if (where == 4) { Guide.BeginShowMessageBox("��ʾ", "ȷ��Ҫ������", new string[] { "ȷ��", "ȡ��" }, 1, MessageBoxIcon.None, new AsyncCallback((s) => { var r = Guide.EndShowMessageBox(s); //ȷ�� if (r == 0) { foreach (var v in this.Lenses) { if (v is Prism) ControlPanel.PrismCount += 1; else ControlPanel.MirrorCount += 1; } this.Lenses.Clear(); UpdateAllEmitter(); Current = null; } }), null); } CheckState(); } } //��ק�������ѿؼ��ź�λ�� else if (IsDraging && Current != null) { Current.In = null; Current.Extra = null; Current.SetPosition(Current.X / 60 * 60 + this.X + 30, (Current.Y - this.Y)/ 60 * 60 + 30 + this.Y); UpdateAllEmitter(); CheckState(); } MouseDown = false; IsDraging = false; } } #endregion #region �ڰ���״̬�£��ж��Ƿ���ק if (MouseDown) { if (IsDraging == false && (state.X != FirstPoint.X || state.Y != FirstPoint.Y)) { IsDraging = true; if (Current != null) { Current.ClearLaser(); } } if (IsDraging && Current != null) { if (Offset.Y > 100) return; Current.SetPosition(state.X - Offset.X, state.Y - Offset.Y); Current.CanInput = this.CanPutIn(new Point(Current.X,Current.Y)); } } #endregion }