/// <summary> /// Assign the next block to the current block. Move it to the top of the screen and generate a new next block. /// </summary> private void SwapBlocks() { _currentPieceXPosition = _currentPieceNextXPosition = _centerX; _currentPieceYPosition = _currentPieceNextYPosition = _centerY; CurrentPiece = _nextPiece; GenerateRandomPiece(); }
/// <summary> /// Handles the game loop. /// </summary> public void Run() { GenerateRandomPiece(); CurrentPiece = NextPiece; GenerateRandomPiece(); DrawCurrentBlock(); while (true) { if (Console.KeyAvailable) { HandleKey(Console.ReadKey(true /* do not display*/).Key); } if (DeltaTime()) { if (_paused) { string alert = _visible ? "Game Paused" : ""; _visible = !_visible; Console.MoveBufferArea(5, 21, 11, 1, 5, 20); Console.SetCursorPosition(5, 20); Console.BackgroundColor = ConsoleColor.DarkGreen; Console.WriteLine(alert); Console.ResetColor(); } else { ChangePosition(Direction.Y, Change.Increment); ValidateMove(); } } DrawCurrentBlock(); MaximumNavigation(); DetectGameOver(); } }
/// <summary> /// Generates a new random piece and assigns it to the next block. /// </summary> private void GenerateRandomPiece() { BlockType block = (BlockType)(_random.Next(7)); NextPiece = new Tetriminos(block); }