In my past lives (basic, pascal, VB, actionscript etc) I was a big fan of using a mass of variables that any other part of the program i was building could use. Whether this was simply laziness or ignorance I am not entirely sure. I've hear from various places that it's possibly 'better' to use as few as possible, preferably none. It's not to say that they were all 'global' (I read that this is a term that doesn't really apply to C#, not that I completely understand the argument), but that there were a good number filling line after line at the top of the code.
Which brings me to this project. Now that I have pulled out the map creation part of it, I realise now that I am still referring to variables created in other parts. What if i want to drastically change the map generation algorithm? Actually, I already know that I do want to change it.
"Sure that looks OK, I can work with that" I tell myself. In reality, I know it could be better, and that I could make it better.
SO now, after saying yesterday (?) that i was going to work on some more features, I think I'll spend the next little while properly encapsulating (is that even the right word?) the map creation part. If I want to be able to, for example, create 4 separate maps and display them simultaneously, the current way I create the map will not handle that. It's not generic enough. There is still too much code specific to the test map that I was making to provide proof of concept.
There are probably two main things to change:
- make it so that all the abstraction for the map occurs in the map.cs
- remove calls from within map.cs to other parts of the project, e.g. Variables.mapstoragearray[]. You sir, just have to go!
I suspect that this means I'll need to send some parameters to the createMap() to establish required dimensions, and, importantly if i want to use the same routine to get more than one map at a time, return an array full to brim with information for the draw-map-to-screen part about which colours to put where.
not a big update, but i think it'll set me up for down the track.
* Edit
Seriously! Ctrl-H 'find and replace' FTW!
No comments:
Post a Comment