A general question about NCURSES:
How do you keep the screen properly updated?
My game requires precise timing and if the player cannot see what they need to do at all times, it's an instant lose. This is most problematic for me with NCURsES, where it seems like every clear();, scroll(), or movement of a window seems to glitch out the stdscr.
I have an error right now that SEEMS to be caused by clearing the screen, and I am finding it increasingly difficult to prevent the clear(); function from clearing the entire screen and stopping the user from seeing any output.
I don't know if this is explicitly caused by the clear function, but my program keeps "crashing," where it still says it is running, but there is no text and input seems to do nothing. There is far too much code to place here but I can place a snippet of it. Some of these functions are incomplete and I have since removed all clear statements, resorting to the scroll function which is equally inefficient in this context. Any help would be appreciated, because I'm not sure what to do in order to fix my program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
while(playing)
{
halfdelay(255);
switch(showOptions())
{ //Move, show stats/hp, show location/description/id, rest/heal, search area for supplies.
case 1:
{
current += movementReturn(current);
if(check4Monster(current))
{
MONSTER monster1(player1.level);
while(monster1.health > 0 and player1.health > 0)
{
switch(player1.classNum)
{
case 1: combat1(&monster1,&player1); break;
case 2: combat2(&monster1,&player1); break;
case 3: combat3(&monster1,&player1); break;
}
if(player1.health < 1) { playing = false; }
}
}
}
case 2: player1.outPutStats(); break; //no time passes
case 3:
{
std::string str = areaDesc[current];
for(int i = 0; i < str.length(); i++) { addch(str[i]); }
break; //couldn't figure out how to output strings so I just made my own integral function.
}
case 4: player1.heal(); break;
case 5: break; /*search(); adds a potion, half day passes, chance of monster spawn. */
default: printw("\nInvalid input, line 42. Press any key to try again. \n"); break;
}
//searching has a chance of spawning a monster. //if they succeed, they find items like potions and 1 of the four special drops that are needed to fight the final boss.
//make each location have story bits and information about the location in Warsaw citadel.
//based off Rayet-96A story. Story is revealed through each of these locations.
}
endwin();
}
| |
A link to the full source code is here:
https://www.onlinegdb.com/fork/r1iKTCPeV