static void Main() { int selectedMenuItem = (int)MenuItemsNames.MainMenu; Menu menu = new Menu(); Scoreboard scoreboard = new Scoreboard(); Scramble scramble = new Scramble(); do { Console.Clear(); // show current menu item switch (selectedMenuItem) { // main menu page case (int)MenuItemsNames.MainMenu: MainMenu(menu, ref selectedMenuItem); break; // scoreboard page for 3x3x3 cube case (int)MenuItemsNames.ScoreboardPageRegular: ScoreboardPage(scoreboard.Scoreboard3); selectedMenuItem = (int)MenuItemsNames.MainMenu; break; // scoreboard page for 2x2x2 cube case (int)MenuItemsNames.ScoreboardPage: ScoreboardPage(scoreboard.Scoreboard2); selectedMenuItem = (int)MenuItemsNames.MainMenu; break; // timer and scramble for 3x3x3 cube case (int)MenuItemsNames.TimerScramblePageRegular: Stopwatch stopwatch = new Stopwatch(); TimerScramblePage(scramble, stopwatch, scoreboard, true); selectedMenuItem = (int)MenuItemsNames.MainMenu; break; // timer and scramble for 2x2x2 cube case (int)MenuItemsNames.TimerScramblePage: Stopwatch stopwatch2 = new Stopwatch(); TimerScramblePage(scramble, stopwatch2, scoreboard, false); selectedMenuItem = (int)MenuItemsNames.MainMenu; break; } } while (true); }
static void TimerScramblePage(Scramble scramble, Stopwatch stopwatch, Scoreboard scoreboard, bool isRegularCube) { Console.ResetColor(); bool exit = false; bool isCounterActive = false; // generate new scramble string newScramble = scramble.GenerateScramble(); while (!exit) { Console.Clear(); Console.WriteLine($"newScramble: {newScramble}"); Console.WriteLine("Press space for start timer"); if (isCounterActive) { Console.WriteLine("Time counting.."); } ConsoleKey key; key = Console.ReadKey(true).Key; // convert time to milliseconds TimeSpan stopwatchElapsed = stopwatch.Elapsed; int timeInMilliseconds = Convert.ToInt32(stopwatchElapsed.TotalMilliseconds); if (key == ConsoleKey.Spacebar && timeInMilliseconds == 0) { // start counting time stopwatch.Start(); isCounterActive = true; } else if (key == ConsoleKey.Spacebar && timeInMilliseconds > 0) { // stop counting time stopwatch.Stop(); // get formatted time string formattedStopwatch = stopwatchElapsed.ToString("mm\\:ss\\.ff"); isCounterActive = false; Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine($"Your time is: {formattedStopwatch}"); Console.ResetColor(); Console.WriteLine("Type 'e' to return to the menu. Type 'r' to get new scramble"); bool newExit = false; while (!newExit) { ConsoleKey newKey; newKey = Console.ReadKey(true).Key; // add result time with scramble to specific list if (newKey == ConsoleKey.E || newKey == ConsoleKey.R) { List <ScoreboardItems> newResult = new List <ScoreboardItems>() { new ScoreboardItems() { Scramble = newScramble, Time = formattedStopwatch } }; // assign new item to specific scoreboard if (isRegularCube) { scoreboard.Scoreboard3 = newResult; } else { scoreboard.Scoreboard2 = newResult; } newExit = true; } if (newKey == ConsoleKey.E) { // go back to menu if key is equal 'e' exit = true; } else if (newKey == ConsoleKey.R) { // if key is equal 'r' invoke TimerScramblePage with new scramble and stopwatch Scramble newScrambleClass = new Scramble(); Stopwatch newStopwatch = new Stopwatch(); exit = true; TimerScramblePage(newScrambleClass, newStopwatch, scoreboard, isRegularCube); } } } } }