-
newbie needs help
Hello there.
Im trying to learn C++ and have done some smaller things but wanted to make a little test game and need some help if possible. i wanted to load from a file a gamearea that is 3x3 square with the numbers 1-8 in 8 of the 9 avaliable squares but i have no clue how to do this yet, anyone that can help or give an example ?
-
This would be easier if more information was given. What kind of game? What library (opengl, allegro, so on..)? what for/purpose? etc...
Example that might get you started (i made this in the reply window so it might be wrong).
Code:
int grid[3][3]; //3x3 grid
int count = 1;
for(int i = 0; i < 3; i++){
for(int n = 0; n < 3; n++){
if(i == 2 && n == 2) break; //stops from loading in 9th grid
grid[i][n] = count; //assign 1-8
count++;
}
}
-
Hey there :)
WHat i wanted to try to make is a game in 3*3 squares with 1 number in each square except the last one as i said in the other post. the blank one you are supposed to be able to move around and when you move the blank one where annother number is they switch places, and you win when you have the numbers lined up in order 1 to 8 etc.
But what i had a problem with then starting this is getting a grid to load from file X why i want it to load from a file at start is becuase it going to make the numberd square be at random places at every start and keep track of what what numbers landed at wich places.
i the way of looks i was thinking of someting like this
http://www.imagefrog.net/out.php/i2874_4.jpg
-
Why would you have to load it from a file, unless you wanted to have pre-set grids for different difficulties. But loading from a file would not be random by nature. There is the rand() function (which sometimes doesn't appear too random from my experience). I would probably start by having the user being able to move in different directions, and set the values of the squares depending on the move.
Pseudocode that should get you started
Code:
give user option to move in a direction
if user tries to move outside grid don't allow it
else set current square to the square you are moving to
set moved to square to 0 or w/e you want
edit: there are a lot of ways to approach the same problem