private void timer1_Tick(object sender, EventArgs e) { if (CheckFallingDown()) { figure.FallDown(); } else { foreach (Point position in figure.GetAbsoluteCoordinates()) { board[position.Y, position.X] = CellState.Filled; } CheckFullLines(); ScoreLabel.Text = "Score: " + score; figure = CreateNewFigure(new Point(CellsXMax / 2, 1), nextFigure.type); nextFigure = CreateNewFigure(new Point(1, 1), (FigureType)random.Next(0, 8)); NextFigurePictureBox.Refresh(); if (CheckLostGame()) { timer1.Stop(); MessageBox.Show("You lost! Try Again!"); Restart(); } } BoardPictureBox.Refresh(); }
public Form1() { InitializeComponent(); timer2.Interval = 100; timer2.Start(); SetSizes(); Restart(); BoardPictureBox.Refresh(); }
private void timer2_Tick(object sender, EventArgs e) //todo: Исправить дублирование { canMoveLeft = true; canMoveRight = true; if (movingDirection != Direction.None && keyIsPressed) { if (movingDirection == Direction.Left) { foreach (Point position in figure.GetAbsoluteCoordinates()) { if ((position.X - 1 < 0) || (board[position.Y, position.X - 1] == CellState.Filled)) { canMoveLeft = false; break; } } if (canMoveLeft) { figure.Move(movingDirection); } } if (movingDirection == Direction.Right) { foreach (Point position in figure.GetAbsoluteCoordinates()) { if ((position.X + 1 > CellsXMax - 1) || (board[position.Y, position.X + 1] == CellState.Filled)) { canMoveRight = false; break; } } if (canMoveRight) { figure.Move(movingDirection); } } if (movingDirection == Direction.Down && CheckFallingDown()) { figure.FallDown(); } } BoardPictureBox.Refresh(); }