1

I am trying to make 2 for-loops that can store Rectangles for me in an array yet when i run the for-loops i get the Error message :"Index was outside the bounds of the array" Can someone please explain what i am doing wrong?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;

namespace WindowsFormsApplication1
{
    class Game : GameEngine
{
    Rectangle[] Rect = new Rectangle[45];
    int blockX, blockY, blockW = 187, blockH=15, blockCount;
    public override void Render(Graphics g)
    {
        fpsCounter.Frame();
        i++;
        g.Clear(Color.Black);
        g.FillRectangle(Brushes.White, i / 2f, 20, 20, 20);
        g.FillRectangle(Brushes.Yellow, Cursor.Position.X, this.Height-(this.Height / 10), 200, 20);
        g.DrawString(fpsCounter.getFps().ToString(), Font, Brushes.Green, 5, 5);
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; i < 10; k++)
            {
                blockCount++;
                Rect[blockCount] = new Rectangle(blockX, blockY, blockW, blockH);
                blockX = blockX + blockW + 5;
            }
        blockY = blockY + blockH + 5;
        }
    }

    private FpsCounter fpsCounter = new FpsCounter();
    int i = 0;
    }
}
leppie
  • 115,091
  • 17
  • 196
  • 297
Luguan
  • 11
  • 2

0 Answers0