0

Im making a silly 2D game but is struggling a bit with external files that describes how the map should look like.

I currently have map001.txt that looks like this

00000000000000000000
01111111111111111110
01111111111111111110
01111111111111111110
01111111111111111110
01111111111111111110
01111111111111111110
00000000000000000000
00000000000000000000
00000000000000000000

Using TextReader does not make it happen, it cant seem to find the file :(

Jason94
  • 13,320
  • 37
  • 106
  • 184
  • What are the map001.txt files settings in your project? Is it a resource or content? And you could share some code to how you tried to access the file. – BigL Jan 21 '12 at 12:23

1 Answers1

1

Windows Phone 7 uses Isolated Storage, which is different approach than other systems e.g. Windows 7.

I assume you are using C# and you have maps predefined. You have two options

  • Include file in the project
  • write this map string into the code

there are more option - like using database - but these two are simple and good enough. If I were you I would go with second one. Map looks pretty simple, so the loading time and memory using shouldn't be a problem.

Best way is to define a helper (if you are interested why I made it static readonly here's an explanation)

public static class MapHelper
{
    public static readonly string Map = @"
                                          00000000000000000000
                                          01111111111111111110
                                          01111111111111111110
                                          01111111111111111110
                                          01111111111111111110
                                          01111111111111111110
                                          01111111111111111110
                                          00000000000000000000
                                          00000000000000000000
                                          00000000000000000000
                                          ";

}

Now if you want to extract the map as lines here a snippet

  var lines = Map.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

to get the width and height use

        width = lines.Select(x => x.Length).Max();
        height = lines.Length;
Community
  • 1
  • 1
Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108
  • Since i have very small maps, this would work i think. For larger projects i would like to make a seperate editor and store data in exernal files. thanks – Jason94 Jan 21 '12 at 13:33