public static void StartGame() { isKeyPressed = false; gameOver = false; LineCleared = 0; Score = 0; Combo = 0; Level = 1; Speed = 250; int piecesCounter = 0; var blocks = Blocks.createBlocks(); matrix = new bool[MATRIX_ROWS, MATRIX_COLS]; while (true) { if (gameOver) { break; } // printing score/level/lines HelperFunctions.PrintStats(); // picking new piece and next piece bool[,] newPiece; newPiece = pieces.Count == 0 ? HelperFunctions.PickRandomBlock(blocks, rnd) : pieces.Pop(); piecesCounter++; // if first piece is a bomb -> pick another one while (piecesCounter == 1 && newPiece.GetLength(0) == 1 && newPiece.GetLength(1) == 1) { newPiece = HelperFunctions.PickRandomBlock(blocks, rnd); } pieces.Push(HelperFunctions.PickRandomBlock(blocks, rnd)); HelperFunctions.NextBlock(pieces.Peek()); // setting new piece's coordinates curPiece = newPiece; curX = 0; curY = matrix.GetLength(1) / 2 - 1; // change tetris color when bomb incoming HelperFunctions.ChangeConsoleColor(newPiece); // setting the new piece on the top middle HelperFunctions.SettingPieceInMatrix(curPiece, matrix, curX, curY); // printing matrix HelperFunctions.PrintMatrix(matrix, 1, 1); while (true) { // checking for movements and rotation HelperFunctions.InputEvents(); // trying to move the piece 1 row down if (!HelperFunctions.TryMove(matrix, curPiece, curX + 1, curY, "down")) { // if piece is the bomb - destroy if (curPiece.GetLength(0) == 1 && curPiece.GetLength(1) == 1) { HelperFunctions.DestroyWithBomb(); } // check if piece can't move from the top of the frame if (curX + 1 == 1) { // get player's name and add highscore HelperFunctions.GameOver(); gameOver = true; } // exit the cicle and get next block break; } // move piece down HelperFunctions.ReplacePosition(curPiece, curX + 1, curY); // printing matrix HelperFunctions.PrintMatrix(matrix, 1, 1); Thread.Sleep(Speed); } // check for full lines and drop blocks HelperFunctions.ClearLines(); // calculate level, score and speed HelperFunctions.SetLevelScoreAndSpeed(); } HelperFunctions.AskForRestart(); }
static void Main(string[] args) { Player player = new Player(); Window window = new Window(60, 50); Menu menu = new Menu(player); Admin admin = new Admin(); World world = new World(); Platform platform = new Platform(); Game game = new Game(); UI ui = new UI(); Blocks actualBlock = game.RandomBlock(); while (true) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); menu.Start(key.Key, world, ui); //admin.ConsolePos(key.Key); //admin.ConsoleChangePos(key.Key , Console.CursorLeft , Console.CursorTop); if (menu.IfStarted() && !game.IfLose(platform)) { if (actualBlock.moveable && actualBlock.created) { actualBlock.Move(actualBlock.squares, key.Key, world, platform, player); } } if (game.IfLose(platform)) { game.PlayAgain(key.Key, world, platform, player); } } //admin.ConsolePosShow(Console.CursorLeft , Console.CursorTop); if (menu.IfStarted() && !game.IfLose(platform)) { player.ChangePlayerLevel(); ui.ShowPlayerStatus(player); platform.FullPlatform(player); if (!actualBlock.created) { actualBlock.Create(); } } if (menu.IfStarted() && actualBlock.moveable && actualBlock.created && !game.IfLose(platform)) { if (actualBlock.gravityTime == 3) { actualBlock.Gravity(actualBlock.squares, world, platform); } } if (!actualBlock.moveable && !game.IfLose(platform)) { actualBlock = game.RandomBlock(); } if (game.IfLose(platform)) { game.Lose(player); } actualBlock.AddGravityTime(); Thread.Sleep(150 / player.speed); } }