public void Update(float deltaTime) { if (_pauseBlinkAccumulatedTime < 500f) { _pauseBlinkAccumulatedTime += deltaTime; } else { _pauseBlinkAccumulatedTime = 0; _pauseBlink = !_pauseBlink; } if (_gameOverBlinkAccumulatedTime < 500f) { _gameOverBlinkAccumulatedTime += deltaTime; } else { _gameOverBlinkAccumulatedTime = 0; _gameOverBlink = !_gameOverBlink; } if (Paused) { return; } if (TetrisStatictics.GameOver) { return; } if (!ActiveTetromino.Active) { CheckForTetris(); AddNextTetromino(); return; } int level = 5 * TetrisStatictics.Level; if (level < 999) { level = 999; } if (_accumulatedTime < level) { _accumulatedTime += deltaTime; return; } ActiveTetromino.Down(); _accumulatedTime = 0; }
/// <summary> /// Moves the active tetromino one down if it is possible. /// </summary> public void MoveActiveTetrominoOneDownIfPossible() { if (!Paused) { MovingTetrominoMutex.WaitOne(); if (ActiveTetromino != null) { ActiveTetromino.MoveDownIfPossible(Fieldgrid); } MovingTetrominoMutex.ReleaseMutex(); } }
/// <summary> /// Drops the active tetromino all the way down and locks it in place. /// </summary> public void DropActiveTetromino() { if (!Paused) { MovingTetrominoMutex.WaitOne(); if (ActiveTetromino != null) { ActiveTetromino.DropDown(Fieldgrid); } MovingTetrominoMutex.ReleaseMutex(); } }
/// <summary> /// Rotates the active tetromino to the left if it is possible. /// </summary> public void RotatActiveTetrominoToTheLeftIfPossible() { if (!Paused) { MovingTetrominoMutex.WaitOne(); if (ActiveTetromino != null) { ActiveTetromino.RotateLeftIfPossible(Fieldgrid); } MovingTetrominoMutex.ReleaseMutex(); } }
private void RenderTetrisCanvas(Graphics graphics) { for (int x = 0; x < LevelSize.Width; x++) { for (int y = 0; y < LevelSize.Height; y++) { int xPosition = (x * TetrominoDrawing.SQUARE_SIZE) + TetrisLevel.XMARGIN; int yPosition = (y * TetrominoDrawing.SQUARE_SIZE) + TetrisLevel.YMARGIN; TetrominoDrawing tetrominoDrawing = TetrominoDrawing.GetTetrominoColors(LevelMatrix[y][x]); graphics.FillRectangle(new SolidBrush(tetrominoDrawing.FillColor), new Rectangle(xPosition, yPosition, TetrominoDrawing.SQUARE_SIZE, TetrominoDrawing.SQUARE_SIZE)); graphics.DrawRectangle(new Pen(tetrominoDrawing.BorderColor, TetrominoDrawing.SQUARE_BORDER), new Rectangle(xPosition, yPosition, TetrominoDrawing.SQUARE_SIZE, TetrominoDrawing.SQUARE_SIZE)); } } for (int x = 0; x < LevelSize.Width; x++) { for (int y = 0; y < LevelSize.Height; y++) { if (LevelMatrix[y][x] == TetrominoType.Empty) { continue; } int xPosition = (x * TetrominoDrawing.SQUARE_SIZE) + TetrisLevel.XMARGIN; int yPosition = (y * TetrominoDrawing.SQUARE_SIZE) + TetrisLevel.YMARGIN; TetrominoDrawing tetrominoDrawing = TetrominoDrawing.GetTetrominoColors(TetrominoType.Filled); graphics.FillRectangle(new SolidBrush(Color.LightGray), new Rectangle(xPosition, yPosition, TetrominoDrawing.SQUARE_SIZE, TetrominoDrawing.SQUARE_SIZE)); graphics.DrawRectangle(new Pen(Color.White, TetrominoDrawing.SQUARE_BORDER), new Rectangle(xPosition, yPosition, TetrominoDrawing.SQUARE_SIZE, TetrominoDrawing.SQUARE_SIZE)); } } ActiveTetromino.Render(graphics); }