public static void ShowHighScores() { Engine.ClearScreen(); showControls = true; do { Console.BackgroundColor = ConsoleColor.DarkBlue; Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(0, 0); Engine.ClearScreen(); for (int i = 0; i < highScoresNames.Length; i++) { Console.SetCursorPosition(30, 10 + i); Console.WriteLine($"{i + 1} {highScoresNames[i]} {highScoresNumbers[i]} \n\n"); } BlockAnimation(); Thread.Sleep(50); showControls = Engine.EscapeNotPressed(); } while (showControls); // to prevent draw bug keypress Engine.GlitchFix(); }
public static SelectedMenu MenuSelection() { string tetris = @" ████████╗|███████╗|████████╗|██████╗ |██╗|███████▓ ╚▓═██╔░═╝|██╔════╝|╚▓═██╔▒═╝|██╔══██╗|██║|██╔════▒ ▒ ██║▒ |█████╗ | ▒ ██║░ |██████╔╝|██║|███████░ ░ ██║░ |██╔══╝ | ░ ██║░ |██╔══██╗|██║|╚════██▒ ▒ ██║ |███████▓| ▒ ██║ |██║ ██║|██║|███████░ ░ ╚═╝ |╚▓═════╝| ░ ▓═╝▒ |╚═╝ ╚▓╝|╚░╝|╚═══▓══▒ ░ ░ | ▒ | ▒ ░ | ▒ | | ▒ ▒ ░ | ░ | ░ ░ | ░ ░ | | ░ | | ░ | | | ░ "; // just add a string to add items to the main menu string[] selectMenu = { "Start Game", "High Scores", "Controls", "Credits", "Exit" }; int selection = 0; HighScores.GetHighScores(); ResetColor(); Engine.ClearScreen(); Engine.DrawTitle(tetris, 5); ConsoleKey keyDown; // to store the pressed key do { DrawMenu(selection, selectMenu); ConsoleKeyInfo keyInfo = ReadKey(true); //get the pressed key keyDown = keyInfo.Key; //safe the pressed key if (keyDown == ConsoleKey.UpArrow || keyDown == ConsoleKey.Z) { selection--; if (selection == -1) { selection = selectMenu.Length - 1; } } if (keyDown == ConsoleKey.DownArrow || keyDown == ConsoleKey.S) { selection++; if (selection == selectMenu.Length) { selection = 0; } } } while (keyDown != ConsoleKey.Enter); return((SelectedMenu)selection); }
static public void PlayGame() { Hud.Score = 0; level = 1; int dropSpeed = 20; isPlaying = true; TetrisBlock activeBlock = new TetrisBlock(); playField = new PlayField(); Engine.ClearScreen(); SetCursorPosition(0, 0); while (isPlaying) { tick++; KeyInputCheck(activeBlock, playField); if (tick % (dropSpeed - level) == 0) { activeBlock.YPos++; tick = 0; } if (playField.CollisionCheck(activeBlock)) { playField.UpdateField(activeBlock); playField.ScoreCheck(); // game over if (playField.CollisionCheck(activeBlock) && isPlaying) { HighScores.CheckHighScore(Hud.Score); isPlaying = false; } } Hud.DrawHud(); playField.DrawPlayField(xOffset, yOffset); activeBlock.DrawBlock(xOffset + activeBlock.XPos, yOffset + activeBlock.YPos); Thread.Sleep(40); } // remove keyboard input glitch Engine.GlitchFix(); }
public static void DrawHud() { Console.BackgroundColor = ConsoleColor.DarkBlue; Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(0,0); Engine.ClearScreen(); Console.SetCursorPosition(10, 5); Console.WriteLine($"Your score: {Score}"); Console.SetCursorPosition(10, 6); Console.WriteLine($"Your level: {PlayTetris.level}"); Console.SetCursorPosition(53, 5); Console.Write("Next block:"); nextBlock.DrawBlock(55, 8); Console.ResetColor(); }
public static void ShowCredits() { Engine.ClearScreen(); Console.ForegroundColor = (ConsoleColor)random.Next(9, 15); showCredits = true; do { Engine.ClearScreen(); PrintName(); Animation(); Thread.Sleep(50); showCredits = Engine.EscapeNotPressed(); } while (showCredits); Engine.GlitchFix(); }
public static void CheckHighScore(int score) { int oldScore = 0; int oldScoreTemp = 0; string oldNameScore = ""; string oldNameScoreTemp = ""; bool once = true; for (int i = 0; i < highScoresNames.Length; i++) { if (!once) { oldScoreTemp = highScoresNumbers[i]; highScoresNumbers[i] = oldScore; oldScore = oldScoreTemp; oldNameScoreTemp = highScoresNames[i]; highScoresNames[i] = oldNameScore; oldNameScore = oldNameScoreTemp; } if (score > highScoresNumbers[i] && once) { oldScore = highScoresNumbers[i]; highScoresNumbers[i] = score; oldNameScore = highScoresNames[i]; Console.BackgroundColor = ConsoleColor.DarkBlue; Console.Clear(); Console.SetCursorPosition(20, 2); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("Give your name:"); Console.CursorVisible = true; Console.SetCursorPosition(20, 3); highScoresNames[i] = Console.ReadLine(); SaveHighScores(); Console.CursorVisible = false; once = false; } } Console.ResetColor(); Engine.ClearScreen(); }
public static void GlitchFix() { Console.WriteLine("m"); Console.ResetColor(); Engine.ClearScreen(); }
private static void KeyInputCheck(TetrisBlock activeBlock, PlayField playField) { string pauseText = @" ___ | ___ | ___ | ___ | ___ /\--\ | /\--\ | /\__\ | /\--\ | /\--\ /##\--\ | /##\--\ | /#/--/ | /##\--\ | /##\--\ /#/\#\--\ | /#/\#\--\ | /#/--/ | /#/\#\--\ | /#/\#\--\ /##\-\#\--\ | /##\-\#\--\ | /#/--/ ___ | _\#\-\#\--\ | /##\-\#\--\ /#/\#\-\#\__\| /#/\#\-\#\__\| /#/__/ /\__\| /\-\#\-\#\__\| /#/\#\-\#\__\ \/__\#\/#/--/| \/__\#\/#/--/| \#\--\ /#/--/| \#\-\#\-\/__/| \#\-\#\-\/__/ \##/--/ | \##/--/ | \#\--/#/--/ | \#\-\#\__\ | \#\-\#\__\ \/__/ | /#/--/ | \#\/#/--/ | \#\/#/--/ | \#\-\/__/ | /#/--/ | \##/--/ | \##/--/ | \#\__\ | \/__/ | \/__/ | \/__/ | \/__/ "; if (KeyAvailable) { ConsoleKeyInfo key = ReadKey(); if (key.Key == ConsoleKey.Escape) { isPlaying = false; } if (key.Key == ConsoleKey.Enter && pauseMenu == false) { Engine.ClearScreen(); Engine.DrawTitle(pauseText, 10); pauseMenu = true; ReadKey(); } if (key.Key == ConsoleKey.Enter && pauseMenu == true) { Engine.ClearScreen(); pauseMenu = false; } if (key.Key == ConsoleKey.RightArrow) { if ((activeBlock.XPos < playField.XWith - (activeBlock.Shape.GetLength(1) + 1))) { activeBlock.XPos += 2; if (playField.CollisionCheck(activeBlock)) { activeBlock.XPos -= 2; } } } if (key.Key == ConsoleKey.LeftArrow) { if (activeBlock.XPos >= 1) { activeBlock.XPos -= 2; if (playField.CollisionCheck(activeBlock)) { activeBlock.XPos += 2; } } } if (key.Key == ConsoleKey.UpArrow) { activeBlock.RotateShape(); } if (key.Key == ConsoleKey.DownArrow) { tick = 1; activeBlock.YPos++; } if (key.Key == ConsoleKey.Spacebar) { while (!playField.CollisionCheck(activeBlock)) { activeBlock.YPos++; Hud.Score++; } playField.UpdateField(activeBlock); playField.ScoreCheck(); // game over if (playField.CollisionCheck(activeBlock)) { HighScores.CheckHighScore(Hud.Score); isPlaying = false; } } } }