/* Method for sorting ( Replaced by Form3.HighScoresSortingAlgo() ) */ public void CompareTo(Object obj) { GameStats other = (GameStats)obj; }
/* My High Scores Sorting Algorithm */ private List <GameStats> HighScoreSortingAlgo(List <GameStats> orignalList) { // function properties List <int> gameScores = new List <int>(); List <GameStats> list = orignalList; int rep, replicate, next; // start to end loop for (rep = 0; rep < list.Count; rep++) { // Reset subscripts for comparing list indices. replicate = rep; next = replicate + 1; // Debugging s Console.WriteLine("\nWe are now in for loop rep = " + rep); Console.WriteLine($"Rep = {rep}, Replicate = {replicate}, Next = {next}, list.Count = {list.Count}"); // End of list reached, if (next == list.Count) { Console.WriteLine($"End of list reached."); break; } // -------------------------------------------------------------------------- // The Sorting Algorithm. // -------------------------------------------------------------------------- if (list[rep].GameScore == list[next].GameScore) { // compare time if (list[rep].GameSeconds == list[next].GameSeconds) { // compare bombs if (list[rep].TotalBombs == list[next].TotalBombs) { // compare difficulty if (list[rep].BoardSize == list[next].BoardSize) { // do nothing now. } else if (list[rep].BoardSize <= list[next].BoardSize) { // make a clone of second object GameStats clone = new GameStats( list[next].PlayerName, list[next].GameSeconds, list[next].BoardSize, list[next].TotalBombs, list[next].GameScore ); // swap the indexes list.RemoveAt(next); // remove second object list.Insert(rep, clone); // insert clone before first object // Reverse sort highest score to front of the list. while (replicate > 0) { // make next variable current first object index next = replicate; // if first object index score is greater than preceding score, swap elements. if (list[replicate].BoardSize >= list[--replicate].GameScore && list[next].GameScore >= list[replicate].GameScore && list[next].GameSeconds <= list[replicate].GameSeconds && list[next].TotalBombs >= list[replicate].TotalBombs) { // clone for swap clone = new GameStats( list[next].PlayerName, list[next].GameSeconds, list[next].BoardSize, list[next].TotalBombs, list[next].GameScore ); // swap the indexes list.RemoveAt(next); // remove second object list.Insert(replicate, clone); // insert clone before first object } } } } else if (list[rep].TotalBombs < list[next].TotalBombs) { // make a clone of second object GameStats clone = new GameStats( list[next].PlayerName, list[next].GameSeconds, list[next].BoardSize, list[next].TotalBombs, list[next].GameScore ); // swap the indexes list.RemoveAt(next); // remove second object list.Insert(rep, clone); // insert clone before first object // Reverse sort highest score to front of the list. while (replicate > 0) { // make next variable current first object index next = replicate; // if first object index score is greater than preceding score, swap elements. if (list[replicate].TotalBombs > list[--replicate].TotalBombs && list[next].GameScore >= list[replicate].GameScore && list[next].GameSeconds <= list[replicate].GameSeconds) { // clone for swap clone = new GameStats( list[next].PlayerName, list[next].GameSeconds, list[next].BoardSize, list[next].TotalBombs, list[next].GameScore ); // swap the indexes list.RemoveAt(next); // remove second object list.Insert(replicate, clone); // insert clone before first object } } } } else if (list[rep].GameSeconds > list[next].GameSeconds) { // make a clone of second object GameStats clone = new GameStats( list[next].PlayerName, list[next].GameSeconds, list[next].BoardSize, list[next].TotalBombs, list[next].GameScore ); // swap the indexes list.RemoveAt(next); // remove second object list.Insert(rep, clone); // insert clone before first object // Reverse sort highest score to front of the list. while (replicate > 0) { // make next variable current first object index next = replicate; // if first object index score is greater than preceding score, swap elements. if (list[replicate].GameSeconds < list[--replicate].GameScore && list[next].GameScore >= list[replicate].GameScore) { // clone for swap clone = new GameStats( list[next].PlayerName, list[next].GameSeconds, list[next].BoardSize, list[next].TotalBombs, list[next].GameScore ); // swap the indexes list.RemoveAt(next); // remove second object list.Insert(replicate, clone); // insert clone before first object } } } } // if current score is less than score next on the list else if (list[rep].GameScore < list[next].GameScore) { Console.WriteLine($"list[rep({rep})].GameScore ({list[rep].GameScore}) is < list[next({next})].GameScore ({list[next].GameScore})"); Console.WriteLine($"rep = {rep} next = {next}"); // make a clone of second object GameStats clone = new GameStats( list[next].PlayerName, list[next].GameSeconds, list[next].BoardSize, list[next].TotalBombs, list[next].GameScore ); // swap the indexes list.RemoveAt(next); // remove second object list.Insert(rep, clone); // insert clone before first object // Reverse sort highest score to front of the list. while (replicate > 0) { // make next variable current first object index next = replicate; // if first object index score is greater than preceding score, swap elements. if (list[replicate].GameScore > list[--replicate].GameScore) { // clone for swap clone = new GameStats( list[next].PlayerName, list[next].GameSeconds, list[next].BoardSize, list[next].TotalBombs, list[next].GameScore ); // swap the indexes list.RemoveAt(next); // remove second object list.Insert(replicate, clone); // insert clone before first object } } } // -------------------------------------------------------------------------- } // Return sorted list upon function exit. return(list); }