#include #include "curses.h" #include "../player.h" #include "../game.h" #include "../main.h" #include "../common.h" int interfaceInit() { // initialize ncurses library if ((screen = initscr()) == NULL) { perror("initscr() error'd"); return ERROR; } original_cursor = curs_set(0); // store original cursor position for restore keypad(screen, TRUE); // enable arrow keys/keypad noecho(); // turn off key echoing nonl(); // do not do NL->CR/NL on output cbreak(); // Handle char presses immediately, do not wait for \n // draw a border for fun box(screen, 0, 0); mvwaddstr(screen, LINES/2-1, COLS/2-4, LOGO_STRING_A); mvwaddstr(screen, LINES/2, COLS/2-4, LOGO_STRING_B); mvwaddstr(screen, LINES/2+1, COLS/2-4, LOGO_STRING_C); mvwaddstr(screen, LINES/2+3, COLS/2-5, "Q/q to quit"); return SUCCESS; } void interfaceLoop() { int key = getch(); switch (key) { case 'q': case 'Q': is_running = 0; break; case KEY_UP: (*player_commands[PLAYER_MOVE])(NORTH, 1); break; case KEY_DOWN: (*player_commands[PLAYER_MOVE])(SOUTH, 1); break; case KEY_RIGHT: (*player_commands[PLAYER_MOVE])(EAST, 1); break; case KEY_LEFT: (*player_commands[PLAYER_MOVE])(WEST, 1); break; } } void interfaceDraw() { clear(); mvwaddstr(screen, player.y, player.x, "@"); refresh(); } void interfaceClose() { delwin(screen); endwin(); refresh(); }