private static void Update() { //Update loop. while (true) { dropTime = (int)dropTimer.ElapsedMilliseconds; if (dropTime > dropRate) { dropTime = 0; dropTimer.Restart(); tet.Drop(); } if (isDropped == true) { tet = nexttet; nexttet = new TetrisObject.Tetrominoe(); tet.Spawn(); isDropped = false; } int j; for (j = 0; j < 10; j++) { if (droppedtetrominoeLocationGrid[0, j] == 1) { return; } } Input(); ClearBlock(); } //End Update. }
static void Main(string[] args) { // For using unicode. Console.OutputEncoding = System.Text.Encoding.Unicode; try { if (args.Length != 2) { Console.WriteLine("Program can work with two args (player name,theme)\ntheme\nCyan => Press 1\nGreen => Press 2\nMagenta => Press 3\nRed => Press 4\nYellow => Press any numbers\n"); return; } if (args.Length == 2) { playerName = args[0]; theme = Convert.ToInt32(args[1]); switch (theme) { case 1: Console.ForegroundColor = ConsoleColor.Cyan; break; case 2: Console.ForegroundColor = ConsoleColor.Green; break; case 3: Console.ForegroundColor = ConsoleColor.Magenta; break; case 4: Console.ForegroundColor = ConsoleColor.Red; break; default: Console.ForegroundColor = ConsoleColor.Yellow; break; } } } catch (Exception) { Console.WriteLine("Wrong input !\nPlease enter again with player name and theme ....\ntheme\nCyan => Press 1\nGreen => Press 2\nMagenta => Press 3\nRed => Press 4\nYellow => Press any numbers\n"); Console.ReadKey(true); return; } Console.Clear(); // For game border drawBorder(); Console.SetCursorPosition(5, 5); Console.WriteLine("Press any key"); Console.SetCursorPosition(7, 6); Console.WriteLine("to start"); Console.SetCursorPosition(6, 8); Console.WriteLine("☆Control☆"); Console.SetCursorPosition(2, 10); Console.WriteLine("spacebar → rotate"); Console.SetCursorPosition(2, 11); Console.WriteLine("left/right → move"); Console.SetCursorPosition(2, 12); Console.WriteLine("up → quick drop"); Console.SetCursorPosition(2, 13); Console.WriteLine("down → drop faster"); Console.ReadKey(true); // Time start. timer.Start(); dropTimer.Start(); long time = timer.ElapsedMilliseconds; Console.SetCursorPosition(25, 0); Console.WriteLine($"Player {playerName} Level {level}"); Console.SetCursorPosition(25, 1); Console.WriteLine($"Score {score} ♚ Hi score {hiScore}"); Console.SetCursorPosition(25, 2); Console.WriteLine($"LinesCleared {linesCleared}"); // Creating tetris block by instantiation an object from TetrisObject namespace and Tetrominoe class nexttet = new TetrisObject.Tetrominoe(); tet = nexttet; tet.Spawn(); nexttet = new TetrisObject.Tetrominoe(); Update(); Console.SetCursorPosition(0, 26); Console.WriteLine("Game Over"); Console.SetCursorPosition(0, 27); Console.WriteLine("Replay? (Y/N)"); string input = Console.ReadLine(); // Press Y or y to replay. if (input == "y" || input == "Y") { int[,] grid = new int[23, 10]; droppedtetrominoeLocationGrid = new int[23, 10]; timer = new Stopwatch(); dropTimer = new Stopwatch(); inputTimer = new Stopwatch(); dropRate = 300; isDropped = false; isKeyPressed = false; linesCleared = 0; score = 0; level = 1; GC.Collect(); Console.Clear(); Main(args); } else { return; } }