Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7509641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:58:40+00:00 2026-05-29T22:58:40+00:00

What I am trying to do is create a map generator that will create

  • 0

What I am trying to do is create a map generator that will create a grid of rectangles, and then fill random rectangles with different properties. (For example in a grid of 2×2, 1,1 would be just a normal ‘field’ in the game, 1,2 would be a base and have different properties than one (like the ability to construct units), 2,1 would be a water tile (and not be passable by units), and 2,2 would be a mountain (similar properties of the previous). I’ve created (what I think) is a grid, but when I attempt to reference the array that I created it doesn’t work the way I’d like it to. My guess is that I am not doing it correctly, but here is some code:

namespace MapGenie
    {
        public class Game1 : Microsoft.Xna.Framework.Game
        {
            GraphicsDeviceManager graphics;
            SpriteBatch spriteBatch;

            GameMap[,] basicMap = new GameMap[10,10]; //I have this done in Initialization normally.
            Rectangle[,] basicGrid = new Rectangle[10,10];
        }
    }

    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);

        int GridSize = 20;

        for(int x = 0;x <10;x++)
            for (int y = 0; y < 10; y++)
            {
                basicMap[x, y] = new GameMap(Content.Load<Texture2D>("Textures\\Plains"));
                basicMap[x, y].position.X = x * GridSize;
                basicMap[x, y].position.Y = y * GridSize;
                basicGrid[x, y] = new Rectangle(x, y, x * GridSize, y * GridSize);
            }
    }

    protected override void Update(GameTime gameTime)
    {
        //This is what I use to test reference a specific point on the grid, however whenever the 
        //mouse crosses into any of the 3x3 area starting with 1,1 it closes the program.
        if (mousePoint.Intersects(basicGrid[3, 3]))
            this.Exit();
    }

So the question is simply: How can I get the program to recognize just a single rectangle in the array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:58:41+00:00Added an answer on May 29, 2026 at 10:58 pm

    The problem with your code is on this line:

    basicGrid[x, y] = new Rectangle(x, y, x * GridSize, y * GridSize);
    

    Look at the constructor for Rectangle (MSDN). Note that it asks for the width and height of the rectangle. You are giving it something different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a wpf control that will display a map image
I'm trying (as a self-learning exercise) to create a Clojure macro that will generate
i've been trying to create a map-related android app, but i realized that the
I'm trying to create a map, where the key is an int , and
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create my first iPhone app that would play back audio. When I
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
I'm trying to develop an application that will simulate a route through Google's Navigation
I am trying to create a program that tracks bike intervals and creates a
I'm trying to create one entity from 2 tables that are related not by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.