private void Restart() { level = 1; time = 1000; score = 0; upScore = 500; x = 3; y = 0; game = true; Clear(Field); Clear(Next); Tetris.NullArray(ref current); Tetris.NullArray(ref next); Tetris.NullArray(ref coordinates); Tetris.NullArray(ref array); Tetris.NullArray(ref moving); labelNext.Text = Convert.ToString(upScore); labelScore.Text = "0"; timer1.Interval = time; timer1.Enabled = true; figure = (Tetris.Figure)figures.GetValue(r.Next(figures.Length)); Tetris.SetNewFigure(ref current, figure); Tetris.Place(current, ref moving, array, ref x, ref y, ref coordinates); Update(true); nextFigure = (Tetris.Figure)figures.GetValue(r.Next(figures.Length)); Tetris.SetNewFigure(ref next, nextFigure); Draw(next, nextFigure); }
private void NewGame() { timer1.Interval = time; CreatePanel(10, 20); CreatePanel(4, 4); labelNext.Text = Convert.ToString(upScore); figure = (Tetris.Figure)figures.GetValue(r.Next(figures.Length)); Tetris.SetNewFigure(ref current, figure); Tetris.Place(current, ref moving, array, ref x, ref y, ref coordinates); Update(true); nextFigure = (Tetris.Figure)figures.GetValue(r.Next(figures.Length)); Tetris.SetNewFigure(ref next, nextFigure); Draw(next, nextFigure); }
public void 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) { ChangePosition(Tetris.Direction.Down); } else { DownSound.Play(); AddScore(0); for (int i = 0; i < 4; i++) { moving[coordinates[0, i], coordinates[1, i]] = 0; } for (int i = 0; i < 4; i++) { array[coordinates[0, i], coordinates[1, i]] = Convert.ToInt32(figure); } int linesCount = Tetris.FullLine(ref array); if (linesCount > 0) { Win.Play(); AddScore(linesCount); Draw(array, figure); } if (score >= upScore) { Tetris.NextLevel(ref level, out time, out upScore); labelNext.Text = Convert.ToString(upScore); timer1.Interval = time; } x = 3; y = 0; Tetris.NullArray(ref current); Tetris.NullArray(ref coordinates); figure = nextFigure; Tetris.SetNewFigure(ref current, figure); Clear(Next); nextFigure = (Tetris.Figure)figures.GetValue(r.Next(figures.Length)); Tetris.SetNewFigure(ref next, nextFigure); Draw(next, nextFigure); if (Tetris.Place(current, ref moving, array, ref x, ref y, ref coordinates) == true) { Update(true); } else { Lose.Play(); timer1.Enabled = false; game = false; DialogResult result = MessageBox.Show("Continue", "You Lose", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { Restart(); } } } }