1. Your map has 15 columns (that means indeces 0 through 14) yet you're going from columns 0 through 15
2. You declared map1 with 9 rows, yet it has 8 rows. You need to add another row after this one: {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; or leave it as is and re-declare map1 with 8 rows
3. Since map1 has 9 rows (for now) (that means indeces 0 through 8) you don't want to go to row 9 as your program is currently doing
different/better way to do it?
Whenever you copy-and-paste, that's a sign that you need to put the duplicated code in a function or loop. The following will do the same job (this code assumes 9 rows and 15 columns)
If the ints serve some other special purpose, you may consider using a std::map<int, char> which would store the relationship between the int and the character to output (so no need to do an if statement for each output).
You may consider storing the map (that is, the map of the level, not the std::map) in a text file and reading it in (you can have each level in its own text file, for example).
Finally, you're not doing anything Windows-specific so no need to #include <windows.h> , and also main() should be int main()
Pressing enter does nothing. I think it may be because of the order in game() where the screen is cleared, but the systen("pause") should fix it, right?
Man I am making a game just like what you are doing at the moment, but you are doing it all wrong.
1.Store the map in a 2D char array.
2.Make the infrastructure to the game e.g.
void gamerutine();//all the different functions
void refresh();
void printer();
void keyinput();
void refreshoutput();
ect...
So your method of printing should be...
for (int a=0;a<maxmaphight;a++)
{
for (int b=0;b<maxmapwidth;b++)
{
cout << map[a][b];//map is where you have sored all your chars
}
cout<<endl;
}
It would be a good idea to create two of the same arrays one called output and one called map, map is a const and output isnt, each cycle output is renewed by the maaps chars and then you add on other things to the map like monsters, and your char.
your colision detection should be something like (presudo code)...
int myx;
int myy;
int adderx=0;//to reset
int addery=0;
inputdown(because the y axis is inverted)
addery++;
inputup
addery--;
inputright
adderx++;
inputleft
adderx--;
if(map[myy+addery][myx+adderx])!='#';//this is a resistant char
{
mapx+=adderx;
mapy+=addery;
}
ALSO...
dont forget to clear the screen like this(because it has no flicker):
COORD newpos = {0,0};
SetConsoleCursorPosition( GetStdHandle(STD_OUTPUT_HANDLE), newpos );