So first off here's the code. The random declaration is on line 3 and the random usage is on line 15 or so.
public static void wildPokemonEncounter(string pokemonRegion)
{
Pokemon wildPokemonEncountered = null;
Random rnd = new Random();
int possiblePokemon = 0;
foreach (KeyValuePair<string, pokemonStats> kvp in GameReference.pokemonInformation)
{
if (kvp.Key != "Bublbasuar" && kvp.Key != "Squirtle" && kvp.Key != "Charmander")
{
if (pokemonRegion == "Plain")
{
if ((kvp.Value.typeOfPokemon == "Plant" || kvp.Value.typeOfPokemon == "Normal" || kvp.Value.typeOfPokemon == "Bug") && kvp.Value.evolutionNumber==1)
{
possiblePokemon += 1;
}
}
}
}
int whichPokemon = rnd.Next(1, possiblePokemon);
int i = 1;
Console.WriteLine(possiblePokemon+" "+ i + " " + whichPokemon);
foreach (KeyValuePair<string, pokemonStats> kvp in GameReference.pokemonInformation)
{
if (kvp.Key != "Bulbasuar" && kvp.Key != "Squirtle" && kvp.Key != "Charmander")
{
if (pokemonRegion == "Plain")
{
pokemonStats thisPokemonsStats = GameReference.pokemonInformation[kvp.Key];
if ((thisPokemonsStats.typeOfPokemon == "Plant" || thisPokemonsStats.typeOfPokemon == "Normal" || thisPokemonsStats.typeOfPokemon == "Bug") && thisPokemonsStats.evolutionNumber == 1)
{
if (i == whichPokemon)
{
wildPokemonEncountered = new Pokemon(kvp.Key, kvp.Value);
slowTyper("`");
slowTyper("You found a Pokemon! Its a " + wildPokemonEncountered.name + "! Its level " + wildPokemonEncountered.level + " and of the type " + wildPokemonEncountered.typeOfPokemon + ".~");
Battle B = new Battle();
slowTyper("You enter into battle with the opposing Pokemon.");
Pokemon your_active_pokemon = null;
foreach (Pokemon pok in GameReference.pokemonInBag)
{
if (pok.is_Starting_Pokemon == true)
{
your_active_pokemon = pok;
}
}
B.PokemonBattle(wildPokemonEncountered, your_active_pokemon);
break;
}
else
{
i += 1;
}
}
}
}
}
}
I've tested just putting in a while true loop in order to check if for some reason the random just wasn't working in this area of the code but it worked. For some reason, though, every single time I run it, I get a four causing a Rattata to spawn. Any ideas?