I am a beginning programmer working on a simple snake game. The program was constructed by my professor, and we have to debug it, however, he left out the main.cpp file on accident (he actually did not mean to leave it out). But I went ahead and constructed my main.cpp from an older file.
I included the ncurses library for all the curses functions. In class, we use DEV C++, but I am using XCODE. I just copy pasted the files.
Strange thing is, in class, using the same exact code except for the main.cpp file, the snake would display after each keyboard arrow input. But now, I am only able to display the snake and its position on the very first display call, and none after. Below is the code in main():
if(body.size() > length)
{ body.erase(body.begin());
mvprintw(1,50,"Snake Snipped Size %d",body.size());
clrtoeol();
}
attron(COLOR_PAIR(BLACKONYELLOW));
for(int i = 0; i<body.size(); i++)
{
mvprintw(i,1,"The %d position of the snake is at %d %d",i,body[i].y, body[i].x);
mvprintw(body[i].y,body[i].x,"%c",'s');
}
attron(COLOR_PAIR(WHITEONBLACK));
refresh();
}
Everything works on the first python.display() call, but then after entering the while loop, nothing is displayed except a gray block which moves along with my keyboard arrow inputs. I inserted cout statements into the display and move functions, and they are being called at the right times. But nothing is showing up on the screen, neither the snake itself or the lines that should be displaying the snake's position, only the cout statements. Maybe it has to do with "location"'s constructors/destructors? Please see below:
#include "location.h"
LOCATION::LOCATION(int firstX, int firstY)
{
x = firstX;
y = firstY;
me = number++;
}
LOCATION::~LOCATION()
{
attron(WHITEONBLACK);
mvprintw(10,1,"Erasing location number %d at %d %d",me, y,x);
mvprintw(y, x,"%c", '*');
refresh();
}
int LOCATION::number = 0;
But even still, the statement that should be fired by the destructor is not appearing on the screen.
Quite confused here, not sure why nothing is showing up when the first display() call works fine, and I know the following ones are being called as well, but nothing shows up on screen. Is it something with that happened when I converted the project to XCODE from DEV C++, or the ncurses lib used by XCode? Just not sure why it is not behaving as it did in class with the same code except for the main.cpp file. Any advice would be appreciated!