Give this a shot:
static void Main(string[] args)
{
Dictionary<string, string[]> skins = new Dictionary<string, string[]>();
skins.Add("ahri", new string[] { "Academy", "Challenger", "Dynasty", "Foxfire", "Midnight", "Popstar" });
skins.Add("leesin", new string[] { "Traditional", "Acolyte", "Dragon Fist", "Musy Thai", "Pool Party", "SKT T1", "Knockout" });
// Creates title for application
Console.WriteLine("Conor's Random League of Legends Skin Selector v0.1\r\n\r\n");
Random rnd = new Random();
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("What champion would you like to select a skin for?.. ");
string champion = Console.ReadLine().ToLower();
Console.Write("Press the 'enter' key for a random champion.. ");
Console.ReadLine();
if(skins.ContainsKey(champion))
{
//return a random champion skin from the user input key in dict based on a random number from the length of the string array
Console.WriteLine(skins[champion][rnd.Next(skins[champion].Length)]);
}
}
Adding to a Dictionary allows you to simplify the process by being able to check against the champion name or Key and then randomly select a skin from the string[] array or Value based on its length thanks to a random number between 0 and the count of the elements within the array.
Hope this helps bud :)
Edit: I got bored and played around with this a bit (by bored I mean trying to avoid going my assignments) so I came up with something a little more user friendly for you. People will probably hate me for giving you the entire solution but it shows you ways to handle these situations so I see it as teaching by example. Have a look.
static void Main(string[] args)
{
Console.Clear(); //For a 'clean slate' on every execution, can ditch this if you want
Console.ForegroundColor = ConsoleColor.Gray;
Dictionary<string, string[]> skins = new Dictionary<string, string[]>();
skins.Add("ahri", new string[] { "Academy", "Challenger", "Dynasty", "Foxfire", "Midnight", "Popstar" });
skins.Add("leesin", new string[] { "Traditional", "Acolyte", "Dragon Fist", "Musy Thai", "Pool Party", "SKT T1", "Knockout" });
Console.WriteLine("Conor's Random League of Legends Skin Selector v0.1\r\n\r\n");
Console.WriteLine("What champion would you like to select a skin for? \r\nPress enter for a random champion... ");
var champion = Console.ReadLine();
var rnd = new Random();
if (champion.Equals(string.Empty))
{
var tmpList = Enumerable.ToList(skins.Keys);
champion = tmpList[rnd.Next(tmpList.Count)];
}
else
{
champion = champion.Trim().ToLower();
}
Console.Write(string.Format("Champion {0} Selected \r\n", champion));
if (skins.ContainsKey(champion))
{
Console.WriteLine(string.Format("Your random skin for {0} is: {1}\r\n", champion, skins[champion][rnd.Next(skins[champion].Length)]));
}
else
{
Console.Clear(); //clear the slate so console doesn't look cluttered.
Main(args);
}
}
Now this is pretty much complete except for your 127 odd additions in champions and their skins.
Quick rundown, short and sweet.
- Does a single call to the
Console which handles all user input, the rest is automated
- Checks for an empty
string if it finds one this is effectively and enter keystroke as if they enter an incorrect value it won't be found in the Dict so it will 'restart' the program anyway. So they're left with two options: enter a correct value that is represented as a string Key or leave it blank and hit enter.
- If and empty
string is found (enter) it converts the Keys of the skins Dict to a List and randomly selects one based on a random number between 0 and the Count() of the elements within said Dict
- Else it converts the read input to a useable string for the purpose here and moves on
- Checks if the adjusted user input or the randomly selected
string key against the Keys of the Dict if found, outputs a random skin based on the Length or Count of the array elements under that Keys Value, at which time the program exists.
- If the
Key isn't found (only based on incorrect user input) then it clears the console and 'restarts' the application.
This is far from the best possible implementation available but it works and I can't really see a problem with it's logic, can feel free to update me if it has an issue somewhere. Suppose I should do my assignments now. This was 15 mins well spent, entertaining. Gotta love coding :)
Hope this helps and maybe you have a few things you can research now and expand your knowledge on.
Later