// ---------------------------------------------------------------------------------------------------------------- // Adds LeaderBoard objects into a List, data will be extracted from @param list. // @param list will have been populated with data in the form of Position-Name-Diff-Score-Time private static List <LeaderBoard> addLeaderboardObjects(List <string> list, bool isOnline) { int count = 0; if (isOnline) { count = MAXNUMBEROFONLINESCORES; } else { count = MAXNUMBEROFLOCALSCORES; } // This list will be sorted; List <LeaderBoard> temp = new List <LeaderBoard>(); for (int i = 0; i < count && i < list.Count; i++) { // Return the data (string) and index i; string line = list[i]; temp.Add(new LeaderBoard { lbPosition = Convert.ToInt32(GlobalApp.splitString(line, 0, '-')), lbName = GlobalApp.splitString(line, 1, '-'), lbScore = Convert.ToInt32(GlobalApp.splitString(line, 2, '-')), lbDiff = Convert.ToInt32(GlobalApp.splitString(line, 3, '-')), lbTime = GlobalApp.splitString(line, 4, '-') }); } return(temp); }
protected override void OnCreate(Bundle savedInstanceState) { try { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.UserInput); saveBtn = FindViewById <Button>(Resource.Id.saveBtn); menuBtn = FindViewById <Button>(Resource.Id.menuBtn); enterNameTxt = FindViewById <EditText>(Resource.Id.enterNameETxt); scoreTxtView = FindViewById <TextView>(Resource.Id.scoreTxtView); timeTxtView = FindViewById <TextView>(Resource.Id.timeTxtView); highScoreTxtView = FindViewById <TextView>(Resource.Id.highScoreTxtView); congratTxtView = FindViewById <TextView>(Resource.Id.congratulationsTxtView); chkBoxName = FindViewById <CheckBox>(Resource.Id.chkBoxPreviousName); // Event handlers: enterNameTxt.Click += EditTextClick; menuBtn.Click += MenuButtonClick; chkBoxName.Click += CheckBoxClick; saveBtn.Click += SaveButtonClick; // Initializing data for the User input. enterNameTxt.Text = DEFAULTENTERNAMEHERE; string content = Intent.GetStringExtra(GlobalApp.getPlayersScoreVariable()); // Why starting at index 1? Because the Name will come before the score data. string score = GlobalApp.splitString(content, 1, '-'); string dif = GlobalApp.splitString(content, 2, '-'); string time = GlobalApp.splitString(content, 3, '-'); scoreTxtView.Text += " " + score; timeTxtView.Text += " " + time; chkBoxName.Enabled = !GlobalApp.isNewPlayer(); // We don't want the checkbox to be auto checked. if (chkBoxName.Enabled) { chkBoxName.Checked = false; } checkForNewPositionToLocalAndOnline(score, time, dif); } catch { GlobalApp.Alert(this, 0); } }
// ---------------------------------------------------------------------------------------------------------------- // Determines if the @param scoreStr, and timeStr is a players new high score. // All parameters must have been extracted from a players score data (Name-Diff-Score-Time). // @timeStr will be in the form of either HH:MM:SS or MM:SS public static bool newHighTimeScore(string scoreStr, string timeStr, string difStr) { int score = Convert.ToInt32(scoreStr); int minutes = 0; int seconds = 0; // Counts the number of special characters in timeStr, // In this case we are counting the number of ":" // There will be two if timeStr is in the format of HH:MM:SS // Otherwise there will be only one MM:SS int count = GlobalApp.findNumberOfCharacters(":", timeStr); // What we are determining is if the timeStr has 2 ":"; // if it does have 2 ":", the format of timeStr is HH:MM:SS if (count < 2) { // First part of the string minutes = Convert.ToInt32(GlobalApp.splitString(timeStr, 0, ':')); // Second part of the string seconds = Convert.ToInt32(GlobalApp.splitString(timeStr, 1, ':')); localPosition = determinePosition(false, score, 0, minutes, seconds); onlinePosition = determinePosition(true, score, 0, minutes, seconds); } else { // First part of the string int hours = Convert.ToInt32(GlobalApp.splitString(timeStr, 0, ':')); // Second part of the string minutes = Convert.ToInt32(GlobalApp.splitString(timeStr, 1, ':')); // Third part of the string seconds = Convert.ToInt32(GlobalApp.splitString(timeStr, 2, ':')); localPosition = determinePosition(false, score, hours, minutes, seconds); onlinePosition = determinePosition(true, score, hours, minutes, seconds); } return(localPosition <= MAXNUMBEROFLOCALSCORES || onlinePosition <= MAXNUMBEROFONLINESCORES); }
// ---------------------------------------------------------------------------------------------------------------- // Determines the position of the players score, by comparing the time it took to complete the game // @params score, hours, minutes, and seconds must be properly extracted from a string. private static int determinePosition(bool isOnline, int score, int hours, int minutes, int seconds) { int currentHours = 0; int currentMinutes = 0; int currentSeconds = 0; int position = 1; List <LeaderBoard> listLBd = PopulateLeaderBoardData(isOnline); for (int i = 0; i < listLBd.Count; i++) { if (hours == 0) { // Extract the new comparable values from the strings stored in listLbd. // We are extracting particular values separated by the special character ":" currentMinutes = Convert.ToInt32(GlobalApp.splitString(listLBd[i].lbTime, 0, ':')); currentSeconds = Convert.ToInt32(GlobalApp.splitString(listLBd[i].lbTime, 1, ':')); if (minutes > currentMinutes) { position++; } else if (minutes == currentMinutes) { if (seconds > currentSeconds) { position++; } } } else { // Extract the new comparable values from the strings stored in listLbd. // We are extracting particular values separated by the special character ":" currentHours = Convert.ToInt32(GlobalApp.splitString(listLBd[i].lbTime, 0, ':')); currentMinutes = Convert.ToInt32(GlobalApp.splitString(listLBd[i].lbTime, 1, ':')); currentSeconds = Convert.ToInt32(GlobalApp.splitString(listLBd[i].lbTime, 2, ':')); if (hours > currentHours) { position++; } else if (hours == currentHours) { if (minutes > currentMinutes) { position++; } else { if (minutes == currentMinutes) { if (seconds > currentSeconds) { position++; } } } } } } return(position); }