try this one insteadNCurses has better introduction material. I learned from some tutorial I googled, I forget what it's called now. It's the same thing as PDCurses, the functions don't need to be changed when you switch between them. That's why people say its portable even though the two are different between Windows and Linux.
And it is hard to explain. But unless you want to do something really fancy, it works to ignore stuff about making new windows (other than stdscr). Once I figured it out its just like:
#include <curses> //the library
int main()
{
char input;
struct
{
int y = 0;
int x = 0;
int hp = 1;
} player;
// these are fun, I learned in C
// my compiler didn't like them :*(
initscr(); // start up the curses features
cbreak(); // don't require enters for input
noecho(); // don't write back what is input
while(player.hp > 0) // self explanatory
{
mvaddch(player.y, player.x, '@');
// move() and addch() combined;
// it's not quite cartesian, y goes first
refresh();
// show what's changed
input = getch();
// should get input from keyboard
// does it wait for the input? I forget.
// make a while loop for it if it doesn't
mvaddch(player.y, player.x, ' ');
// delete the player symbol
// it's probably going to move every turn, so...
// a new one will be made by the time it refreshes
if (input == KEY_UP) // up arrow
player.y++; //change the variable in the struct
if (input == KEY_DOWN) //down
player.y--;
// and so on...
}
endwin();
//clean up curses stuff
}
It's a silly little game loop, doesn't even allow for collision or monster movement, but it's easier with curses. And a switch would be better for player commands, once you get enough of them.
So, you get the idea.
Edits: a few silly mistakes since I haven't done it in a while.
It gets more fun when you use colors.
more edits: I'm satisfied with it now, I think. One more silly mistake and I'm good.
finally: I just realized I didn't want to write a whole scheme for player movement and just a tiny example for curses...
Could've found the same thing linking to that kuro5hin article. Meh.
[ January 10, 2008: Message edited by: nerdpride ]
[ January 10, 2008: Message edited by: nerdpride ]