//键盘事件 private void Key_Event(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Left) { current.MoveLeft(); if (!game.BorderCheck(current) || !game.CollideCheck(current, canvus)) { current.MoveRight(); } } else if (e.KeyCode == Keys.Right) { current.MoveRight(); if (!game.BorderCheck(current) || !game.CollideCheck(current, canvus)) { current.MoveLeft(); } } else if (e.KeyCode == Keys.Up) { current.ClockwiseRotation(); if (!game.BorderCheck(current) || !game.CollideCheck(current, canvus)) { current.AnticlockwiseRotation(); } } else if (e.KeyCode == Keys.Down) { if (game.MoveDownCheck(current, canvus)) { current.MoveDown(); } } else if (e.KeyCode == Keys.Escape && !stop) { stop = !stop; timer1.Enabled = false; panel1.Visible = true; panel1.Enabled = true; } SendCurrent(); pictureBox1.Refresh(); All_Paint(pe); }
private void Window_KeyDown(object sender, KeyEventArgs e) { if (gameTimer.IsEnabled && this.wait.Opacity == 0) { if (e.Key == Key.Right) { fallingPattern.MoveRight(); } if (e.Key == Key.Left) { fallingPattern.MoveLeft(); } if (e.Key == Key.Down) { fallingPattern.PivotRight(); } if (e.Key == Key.Up) { fallingPattern.PivotLeft(); } if (e.Key == Key.Space) { this.gameTimer.Interval = new TimeSpan(0, 0, 0, 0, 1); } } if (lost && e.Key == Key.R) { Reset(); } if (e.Key == Key.X) { ExitCurrentGame(); } if (e.Key == Key.P && this.gameTimer.IsEnabled == true && this.lost != true) { PauseGame(); } if (e.Key == Key.G && this.gameTimer.IsEnabled == false && this.lost != true) { GameGo(); } }
/// <summary> /// 键盘监听 /// </summary> private void LocalDoubleForm_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.A) { lcurrent.MoveLeft(); if (!lgame.BorderCheck(lcurrent) || !lgame.CollideCheck(lcurrent, lcanvus)) { lcurrent.MoveRight(); } } else if (e.KeyCode == Keys.D) { lcurrent.MoveRight(); if (!lgame.BorderCheck(lcurrent) || !lgame.CollideCheck(lcurrent, lcanvus)) { lcurrent.MoveLeft(); } } else if (e.KeyCode == Keys.W) { lcurrent.ClockwiseRotation(); if (!lgame.BorderCheck(lcurrent) || !lgame.CollideCheck(lcurrent, lcanvus)) { lcurrent.AnticlockwiseRotation(); } } else if (e.KeyCode == Keys.S) { if (lgame.MoveDownCheck(lcurrent, lcanvus)) { lcurrent.MoveDown(); } } pictureBox1.Refresh(); All_paint(lpe); if (e.KeyCode == Keys.Left) { rcurrent.MoveLeft(); if (!rgame.BorderCheck(rcurrent) || !rgame.CollideCheck(rcurrent, rcanvus)) { rcurrent.MoveRight(); } } else if (e.KeyCode == Keys.Right) { rcurrent.MoveRight(); if (!rgame.BorderCheck(rcurrent) || !rgame.CollideCheck(rcurrent, rcanvus)) { rcurrent.MoveLeft(); } } else if (e.KeyCode == Keys.Up) { rcurrent.ClockwiseRotation(); if (!rgame.BorderCheck(rcurrent) || !rgame.CollideCheck(rcurrent, rcanvus)) { rcurrent.AnticlockwiseRotation(); } } else if (e.KeyCode == Keys.Down) { if (rgame.MoveDownCheck(rcurrent, rcanvus)) { rcurrent.MoveDown(); } } else if (e.KeyCode == Keys.Escape && !stop) { stop = !stop; timer1.Enabled = false; panel1.Visible = true; panel1.Enabled = true; } pictureBox2.Refresh(); All_paint(rpe); }