for (byte i = 1; i < 6; ++i)
MapNPC[i] = new clNPC();
How will that even run without throwing an exception? Array indexing starts at 0, so you're missing one already by starting your for loop at 1, and if you go until i == 5 (i < 6 constraint) you should get an index out of bounds exception because your array only has 5 slots in it (indices 0, 1, 2, 3, and 4).
for (byte i = 1; i < 6; ++i)
{
Random RandomCoord = new Random();
MapNPC[i].X = Convert.ToInt16(RandomCoord.Next(0, 25));
MapNPC[i].Y = Convert.ToInt16(RandomCoord.Next(0, 25));
}
As mentioned above this will not work. Every Random object you allocate will start with the same seed (because the seed is based on time and you're in a tight loop) so they will always generate the same sequence of numbers. You need to write that loop like this:
| // instantiate the Random object outside of the loop |
| Random RandomCoord = new Random(); |
| |
| // use 0 and 5 here; not 1 and 6. arrays start indexing at 0. |
| for (byte i = 0; i < 5; ++i) |
| { |
| MapNPC[i].X = Convert.ToInt16(RandomCoord.Next(0, 25)); |
| MapNPC[i].Y = Convert.ToInt16(RandomCoord.Next(0, 25)); |
| } |