Advertisement
teleias

CumulativeStarsToLevel -> AccountLevel

Dec 17th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. //Rextester.Program.Main is the entry point for your code. Don't change it.
  2. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace Rextester
  10. {
  11.     public class Program
  12.     {
  13.         public static void Main(string[] args)
  14.         {
  15.             //Your code goes here
  16.             Console.WriteLine("Hello, world!");
  17.             int a, b, c;
  18.             for(int i = 0; i < 50; i++)
  19.             {
  20.                 GetLevelFromStars(i, out a, out b, out c);
  21.             }
  22.         }
  23.         static List<int> cumulativeStarsAtLevel = new List<int>{6, 15, 27, 42, 60};
  24.         public static void GetLevelFromStars(int myStars, out int myLevel, out int starsToNextLevel, out int myProgressToNextLevel)
  25.         {
  26.             int lvlIndex = cumulativeStarsAtLevel.BinarySearch(myStars);
  27.             lvlIndex = lvlIndex < 0 ? ~lvlIndex : lvlIndex+1;
  28.             starsToNextLevel = myProgressToNextLevel = 0;
  29.            
  30.             myLevel = lvlIndex+1;
  31.  
  32.             int cumulativeStarsToCurrentLevel = lvlIndex > 0 ? cumulativeStarsAtLevel[lvlIndex-1] : 0;
  33.             int cumulativeStarsToNextLevel = lvlIndex < cumulativeStarsAtLevel.Count() ? cumulativeStarsAtLevel[lvlIndex] : myStars;
  34.            
  35.             starsToNextLevel = cumulativeStarsToNextLevel - myStars;
  36.             myProgressToNextLevel = myStars - cumulativeStarsToCurrentLevel;
  37.            
  38.            
  39.             Console.WriteLine(String.Format("@{0},\tlvl{1},\t({2} / {3})", myStars, myLevel, myProgressToNextLevel, myProgressToNextLevel + starsToNextLevel));
  40.  
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement