True. The bigger this thing gets, the more trouble I have finding out what exactly the problem is. I think soon I will have to split it into multiple files...
Still, at the moment I can read a map (albeit with a bit of buggy display sometimes) and open and close a door. This much has taken me over two days. It's kind of daunting.
Still, two more questions (I'm way out of my depth here) -
1.When reading from (or generating, for that matter) a map that doesn't fill the entire size I allocate for it, I sometimes get anomalous terrain types displaying off the edges. This has no effect on screen-size maps or gameplay, but it looks... ugly. My location printing code goes something like this:
Code:
void location::printloc(int x1, int y1, int x, int y)
{
cursorpos(x,y);
if (monst[x1][y1] < 1){ //checks to see if there is a monster of some type at location
if (item[x1][y1][0] < 1){ //ditto items
if (build[x1][y1] < 1){ //ditto buildings
if (terrain[x1][y1] == 1){ //ditto terrain
textcolor(7);
cout<<".";
}
else if (terrain[x1][y1] == 2) {
textcolor(15);
cout<<"#";
}
else if (terrain[x1][y1] == 3) {
textcolor(2);
cout<<"T";
}
else if (terrain[x1][y1] == 4) {
textcolor(6);
cout<<"+";
}
else if (terrain[x1][y1] == 5) {
textcolor(6);
cout<<"-";
}
else cout<<" ";
}
else cout<<" ";
}
else cout<<" ";
}
else if (monst[x1][y1] == 99){
textcolor(15);
cout<<"@";
}
else {
textcolor(7);
cout<<" ";
}
textcolor(7);
}
whereas the overall map-printer is as follows:
Code:
int mapprint(int mapx, int mapy) //function to display the map as a whole
{
int x(0); //sets the cursor to the top left edge.
int y(0);
locate.set_char(charx,chary);
while (y < 30) { //This may seem odd, but not all of the map is being displayed.
while (x < 100) { //This way, items/monsters/whatevers can be offscreen
locate.printloc(xdisp, ydisp, x, y);
x++;
xdisp++;
}
x = 0;
xdisp = mapx/2 - 50; //resets the map width display
y++;
ydisp++;
}
return 0;
}
As far as I can tell, the printing function shouldn't even get called outside the map boundaries, let alone actually place anything there (the terrain values for those locations are unspecified).
2.My quit function is a little buggy, it won't always register a keypress
Code:
else if (inputchar == 'q'){
cursorpos(0,31);
cout<<"Are you sure you want to quit?";
inputchar = getch();
while(inputchar !='y' && inputchar != EOF){
cursorpos(0,31);
cout<<"Quit cancelled.";
return 1;
In this instance, it *should* wait for any keypress at all, and if not 'y', print the "quit cancelled" message. However, sometimes it ignores a y keypress or doesn't register any keypress whatsoever. Is this due to the getch() function, or am I using the while loop incorrectly?