private void FormTicTac_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Escape: { FormPause Pause = new FormPause(this); Pause.ShowDialog(); } break; } }
private void FormTetris_KeyDown(object sender, KeyEventArgs e) { if (game == true) { switch (e.KeyCode) { case Keys.Left: case Keys.A: if (coordinates[0, 0] != 0 && coordinates[0, 1] != 0 && coordinates[0, 2] != 0 && coordinates[0, 3] != 0 && array[coordinates[0, 0] - 1, coordinates[1, 0]] == 0 && array[coordinates[0, 1] - 1, coordinates[1, 1]] == 0 && array[coordinates[0, 2] - 1, coordinates[1, 2]] == 0 && array[coordinates[0, 3] - 1, coordinates[1, 3]] == 0) { MoveSound.Play(); ChangePosition(Tetris.Direction.Left); } break; case Keys.Right: case Keys.D: if (coordinates[0, 0] != 9 && coordinates[0, 1] != 9 && coordinates[0, 2] != 9 && coordinates[0, 3] != 9 && array[coordinates[0, 0] + 1, coordinates[1, 0]] == 0 && array[coordinates[0, 1] + 1, coordinates[1, 1]] == 0 && array[coordinates[0, 2] + 1, coordinates[1, 2]] == 0 && array[coordinates[0, 3] + 1, coordinates[1, 3]] == 0) { MoveSound.Play(); ChangePosition(Tetris.Direction.Right); } break; case Keys.Down: case Keys.S: while (coordinates[1, 0] != 19 && coordinates[1, 1] != 19 && coordinates[1, 2] != 19 && coordinates[1, 3] != 19 && array[coordinates[0, 0], coordinates[1, 0] + 1] == 0 && array[coordinates[0, 1], coordinates[1, 1] + 1] == 0 && array[coordinates[0, 2], coordinates[1, 2] + 1] == 0 && array[coordinates[0, 3], coordinates[1, 3] + 1] == 0) { ChangePosition(Tetris.Direction.Down); } if (coordinates[1, 0] == 19 || coordinates[1, 1] == 19 || coordinates[1, 2] == 19 || coordinates[1, 3] == 19 || array[coordinates[0, 0], coordinates[1, 0] + 1] != 0 || array[coordinates[0, 1], coordinates[1, 1] + 1] != 0 || array[coordinates[0, 2], coordinates[1, 2] + 1] != 0 || array[coordinates[0, 3], coordinates[1, 3] + 1] != 0) { Down(); } break; case Keys.Up: case Keys.W: ChangePosition(Tetris.Direction.Rotate); if (Tetris.Place(current, ref moving, array, ref x, ref y, ref coordinates) == true) { Rotate.Play(); Update(true); } else { for (int i = 0; i < 3; i++) { Tetris.Rotate(ref current); } Tetris.Place(current, ref moving, array, ref x, ref y, ref coordinates); Update(true); } break; } } switch (e.KeyCode) { case Keys.Escape: { timer1.Enabled = false; FormPause Pause = new FormPause(this); Pause.ShowDialog(); } break; } }