I was trying to make a space invaders game using arrays to store the invaders, but each time I run the code it freezes and has the error about my array being the wrong size.
Error:
An unhandled exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
Can anyone please help? Here is my code:
class invaders
{
ingame game = new ingame();
PictureBox[] spaceinvaders = new PictureBox[100];
public void spawn(int level)
{
PictureBox invader = new PictureBox();
Bitmap img = (WindowsFormsApplication1.Properties.Resources.SpaceInvader);
for (int n = 1; n == 3 + level; n++)
{
for (int i = 12; i == 493; i = i + 37)
{
invader = new PictureBox();
invader.Size = new Size(12, 12);
invader.Image = img;
spaceinvaders[i] = invader;
spaceinvaders[i].Location = new Point(i, n);
}
}
game.Controls.AddRange(spaceinvaders);
}
}
forloops in your example can even be entered since the base condition is respectively1 == 3 + xand12 == 943. You need to use the<sign in this case.