Jump to content
  • Advertisement
Sign in to follow this  
Mr T 87

c# form array. Drawing a map?

This topic is 3736 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have done this before outside of a windows form but can't remember how. I have this...
            string[,] mapLayout = {
		            {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"},
                    {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"},
                    {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"},
                    {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"},
                    {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"},
                    {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"},
                    {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"},
                    {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"},
                    {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"},
                    {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"},
                    {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"},
                    {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"},
                    {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"},
                    {"| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |","| |"}};

I want to draw this as a game map into a label form object like.. label1.text. However I only seem able to print it all on one line. I'm guessing I am needing a line terminating character every so often in the array to move to the next line. I was aiming for a grid of 19x14 in label1.text. How should a search through, display and detect the end of the line? Regards, Adam

Share this post


Link to post
Share on other sites
Advertisement
My bad it's a label so I'm not sure whats wrong.

I think you could achieve the same thing using picture boxes and it might look better. There are also dawn methods you can use to draw on the form.

Share this post


Link to post
Share on other sites
Okay I have experimented and it is the same as a console application.

\n

string[,] text1 = {{"test", "for", "array"}, {"test2", "for", "array"}};

label1.Text = text1[0, 2] + "\n" + text1[0, 1] + "\n" + text1[1, 0];

Share this post


Link to post
Share on other sites
Thanks for the replies Chris. I'm sure i'll figure it out eventually.

The method you have outlined above would work quite well but seems like quite a lot of work, especially for an array of this size and since I may have multiple maps it would'nt be practical. It is a good idea to use images as the map tiles instead for aesthetics and I will most likely do this but only after I am happy with the method I am using to draw the 'tiles' or strings as they currently are. I am expecting the solution I am searching for to be some kind of a loop.. something along the lines of

while(array[,] != '\0')
{
label1.text = array[,]
//Move to next array position
If array == '\0' then \n
}


I know the above code is not syntatically correct but I hope it helps to understand what it is I am trying to achieve.

I would have previously used the method mentioned in the previous post but I'm trying to rid myself of old habits.

Regards,
Adam

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!