/// <summary> /// 产生新形状并下落 /// </summary> public static void MakeNewShape() { if (Game.State == GameStates.Playing) { Globals.IndexOfCurrentShape = Globals.NextIndexOfShape; Random rand = new Random(); Globals.NextIndexOfShape = rand.Next(18); //MakeNewViewShape(Globals.NextIndexOfShape);//显示预览形状 //由于产生新形状时采用了AllShapes.Eddy(Globals.IndexOfCurrentShape);所以这里采用了下面的一句,而不是上面注释掉的 //否则出现的新形状与预览形状相差90度 MakeNewViewShape(AllShapes.Shapes[Globals.NextIndexOfShape].EddiedIndex); Globals.BasePoint = new GirdPoint(0, 0); AllShapes.Eddy(Globals.IndexOfCurrentShape); } }
//按键 private void FormMain_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.Left) { if (Game.CanOp) { AllShapes.ToLeft(Globals.IndexOfCurrentShape); Sound.PlaySound(Application.StartupPath + @"\Sounds\Left.wav", IntPtr.Zero, 1); } } else if (e.KeyCode == Keys.Right) { if (Game.CanOp) { AllShapes.ToRight(Globals.IndexOfCurrentShape); Sound.PlaySound(Application.StartupPath + @"\Sounds\Right.wav", IntPtr.Zero, 1); } } else if (e.KeyCode == Keys.Down) { if (Game.CanOp) { AllShapes.timer.Stop(); AllShapes.ToDown(Globals.IndexOfCurrentShape); AllShapes.timer.Start(); } } else if (e.KeyCode == Keys.Up) { if (Game.CanOp) { AllShapes.Eddy(Globals.IndexOfCurrentShape); Sound.PlaySound(Application.StartupPath + @"\Sounds\Up.wav", IntPtr.Zero, 1); } } else if (e.KeyCode == Keys.Q) { Game.StartNewGame(); } else if (e.KeyCode == Keys.P) { if (Game.State == GameStates.Playing) { Game.Pause(); } else if (Game.State == GameStates.Paused) { Game.Resume(); } } else if (e.KeyCode == Keys.O) //设置 { Game.Pause(); FormSet fs = new FormSet(); fs.ShowDialog(); } else if (e.KeyCode == Keys.S) //save { Game.Pause(); FormSave fs = new FormSave(); fs.ShowDialog(); } else if (e.KeyCode == Keys.L) //Load { Game.Pause(); FormLoad fL = new FormLoad(); fL.ShowDialog(); } else if (e.KeyCode == Keys.D1) { if (Game.State == GameStates.Stoped) { Game.ChangeLevel(1); } else { this.labelTempInfo.Text = "游戏过程中不可设置速度级别"; } } else if (e.KeyCode == Keys.D2) { if (Game.State == GameStates.Stoped) { Game.ChangeLevel(2); } else { this.labelTempInfo.Text = "游戏过程中不可设置速度级别"; } } else if (e.KeyCode == Keys.D3) { if (Game.State == GameStates.Stoped) { Game.ChangeLevel(3); } else { this.labelTempInfo.Text = "游戏过程中不可设置速度级别"; } } else if (e.KeyCode == Keys.D4) { if (Game.State == GameStates.Stoped) { Game.ChangeLevel(4); } else { this.labelTempInfo.Text = "游戏过程中不可设置速度级别"; } } else if (e.KeyCode == Keys.D5) { if (Game.State == GameStates.Stoped) { Game.ChangeLevel(5); } else { this.labelTempInfo.Text = "游戏过程中不可设置速度级别"; } } else if (e.KeyCode == Keys.D6) { if (Game.State == GameStates.Stoped) { Game.ChangeLevel(6); } else { this.labelTempInfo.Text = "游戏过程中不可设置速度级别"; } } else if (e.KeyCode == Keys.D7) { if (Game.State == GameStates.Stoped) { Game.ChangeLevel(7); } else { this.labelTempInfo.Text = "游戏过程中不可设置速度级别"; } } else if (e.KeyCode == Keys.D8) { if (Game.State == GameStates.Stoped) { Game.ChangeLevel(8); } else { this.labelTempInfo.Text = "游戏过程中不可设置速度级别"; } } else if (e.KeyCode == Keys.D9) { if (Game.State == GameStates.Stoped) { Game.ChangeLevel(9); } else { this.labelTempInfo.Text = "游戏过程中不可设置速度级别"; } } }