First a bit of background.
Im very new to programming, having had my first college about it two weeks past now. before, knew about as much about c++ as my dog.
However, i've started a rather ambitious little pet project about a simple computer game. its called Maze, and the idea is to walk from one side to the other. basically:
Start:
OXX
XXX
XXX
victory condition:
XXX
XXX
XXO
But a bit bigger, and with impassable walls.
/backbround.
And that the problem. I want to be able to create a bigger map from inside the game without hardcoding a maximum. at this moment, I have the field information stored inside an array called map[x][y], with x and y being the dimensions of the playing field(including the border where you cant walk). However, im struggeling with the array. If i declare it as a global before the main function, than its max will be hardcoded. At the moment, de declaration looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
int trans[10],perm[4];
//some main menu etc.
void maap()
{
int loop=0,count=0;
int c=0;
if(trans[0]==0)
{
int map [perm[0]+2][perm[1]+2]{};/*writemap:blanco*/
map[perm[2]][perm[3]]=1;/*define player starting position*/
/*define borders from here onwards*/
for(loop=0;loop==(perm[1]+2)/*Y-axes size*/;loop++)
{
for(count=0;count==(perm[0]+2)/*X-axes size*/;count++)
{
if(count==0||count==(perm[1]+2)||loop==0||loop==(perm[0]+2))
{map[count][loop]=4;/*field value 4=side*/
}
}
}
/*some more if's, to read the player's surroundings to enable the verification of player
movement, and to write said movement. also, to possibly give access
to automated/manual map-with-walls creation.*/
|
trans[10] is the global variable i use to send information between functions. the first digit tells the function what to do, in the above case to declare the array map[x][y] that I want so desperately to be global.
perm[4] is the array i use to store two global values, the first two remember the map size, and other two the player's location.
Here, the map[x][y] array is declared inside the map() function, because that the first time i know the size it has to be. However, i will need to access the map[x][y] array outside of this loop(but inside the function), to both read it out and to write the player's movements.
Side info: This map() function is called by a function called create(), that sets the trans[0]=0 to trigger this if.
I've tried searching this forum, since it helped me find a way to clear my screen(read: skip 100 lines). Does someone know how to make it work? Might it be possible to declare the array globally, and specify its size later? if so, how? Or am i thinking entirely the wrong way around?
As a last note, I am aware that it's considered bad pratice to use global variables, and to transfer information between functions by typing them as int function(info to transfer here). Hoever, i didn't really feel like making 10-argument functions to transfer the data.
I didn't think you guys want to see the entire +/- 100 lines of code, but if you need to, i'll post it of course.
Thanks for your time in advance.