Esempio n. 1
0
	public void AddEntryAndShowPlacment(string name, int score)
	{
		// Add new entry and sort
		LocalArcadeLeaderBoardEntry newEntry = new LocalArcadeLeaderBoardEntry(name, score);
		lbEntries.Add(newEntry);
		lbEntries.Sort();

		// Clear text to be ready for new text
		bodyText.text = "";

		// Show surrounding entries
		int entryIndex = lbEntries.IndexOf(newEntry);

		// Less than the max amount, just print it all them out
		if(lbEntries.Count <= NUM_OF_ENTRIES_PER_PAGE)
		{
			// Add all the entries 
			for (int i = 0; i < lbEntries.Count; i++)
				this.AddEntry(i, entryIndex);
		}
		else // If we have more than NUM_OF_ENTRIES we want to print the score in the middle
		{
			// If in the top of the leader board, it can print normally 
			if (entryIndex < NUM_OF_ENTRIES_PER_PAGE / 2)
			{
				// Add all the entries 
				for (int i = 0; i < NUM_OF_ENTRIES_PER_PAGE; i++)
					this.AddEntry(i, entryIndex);
			}

			// If in the last few entries, just print the end normally
			else if (entryIndex > lbEntries.Count - (NUM_OF_ENTRIES_PER_PAGE / 2))
			{
				// Add all the entries 
				for (int i = lbEntries.Count - NUM_OF_ENTRIES_PER_PAGE; i < lbEntries.Count; i++)
					this.AddEntry(i, entryIndex);
			}

			// If somewhere in the middle
			else
			{
				// Add all the entries between the new index
				for (int i = entryIndex - (NUM_OF_ENTRIES_PER_PAGE / 2); i < entryIndex + (NUM_OF_ENTRIES_PER_PAGE / 2); i++)
					this.AddEntry(i, entryIndex);
			}
		}

		// Save to file 
		using (StreamWriter sw = new StreamWriter(dataPath))
		{
			for (int i = 0; i < lbEntries.Count; i++)
				sw.WriteLine(lbEntries[i].ToString());
		}
	}
Esempio n. 2
0
	// For sorting when in a list
	public int CompareTo(object obj)
	{
		LocalArcadeLeaderBoardEntry other = obj as LocalArcadeLeaderBoardEntry;

		if (this.Score > other.Score)
			return -1;
		else if (this.Score < other.Score)
			return 1;
		else
			return 0;
	}