/// <summary> /// Move the shapes away. /// </summary> /// <param name="button">The button.</param> private static void MoveShapesAway(ConsoleKey button) { if (button == ConsoleKey.LeftArrow) { if (!mover.CheckBorder(tetrisGrid, placedShapes, Side.left)) { mover.MoveLeft(ref tetrisGrid); } } else if (button == ConsoleKey.RightArrow) { if (!mover.CheckBorder(tetrisGrid, placedShapes, Side.rigth)) { mover.MoveRight(ref tetrisGrid); } } else if (button == ConsoleKey.DownArrow) { if (!mover.CheckBorder(tetrisGrid, placedShapes, Side.down)) { tetris.MoveDown(ref tetrisGrid, ref countOfBlocks); } } else if (button == ConsoleKey.UpArrow) { mover.OnButtonUp(ref tetrisGrid, boundary, placedShapes, heightOfShapes); } GameTetris.PrintMatrix(tetrisGrid, score, matrixWidth, topLimit); }
/// <summary> /// Check for game end /// </summary> private static void Endgame() { int counterForLines = 0; for (int i = 0; i < matrixWidth; i++) { for (int j = 0; j < matrixHeight; j++) { if (tetrisGrid[i][j] == placedShapes) { counterForLines++; } } if (counterForLines == matrixWidth) { mover.DeleteLine(tetrisGrid, i); score++; } } bool gameOver = false; for (int i = 0; i < matrixHeight; i++) { if (tetrisGrid[topLimit][i] == placedShapes) { Console.Clear(); Console.WriteLine("Game over! You lost!"); Console.WriteLine("And Your score is " + score); aTimer.Stop(); thread.Abort(); gameOver = true; } } if (!gameOver) { mover.SetShape(ref tetrisGrid, ref currentShape, countOfBlocks, shapesArray); GameTetris.PrintMatrix(tetrisGrid, score, matrixWidth, topLimit); countOfBlocks++; } }