2011-02-12 15:56:31 +00:00
|
|
|
#include <ncurses.h>
|
2011-06-03 06:09:14 +00:00
|
|
|
#include <locale.h>
|
2011-06-03 05:48:26 +00:00
|
|
|
|
2011-02-06 23:28:11 +00:00
|
|
|
#include "game.h"
|
|
|
|
#include "keyboard.h"
|
2010-03-31 05:21:17 +00:00
|
|
|
|
2011-02-06 05:44:45 +00:00
|
|
|
const char *program_name;
|
|
|
|
|
|
|
|
int main(int argc, const char *argv[]) {
|
|
|
|
program_name = *argv;
|
2011-02-06 02:32:21 +00:00
|
|
|
int key;
|
2010-04-13 04:07:00 +00:00
|
|
|
|
2011-06-03 06:09:14 +00:00
|
|
|
setlocale(LC_ALL, "en_US.utf-8"); /* Support unicode characters. */
|
|
|
|
initscr();
|
|
|
|
raw(); /* Disable line buffers. */
|
|
|
|
noecho();
|
|
|
|
keypad(stdscr, TRUE); /* Enable arrow keys. */
|
|
|
|
start_color(); /* I want colors. */
|
|
|
|
curs_set(FALSE); /* Invisible cursor. */
|
|
|
|
set_escdelay(0);
|
|
|
|
assume_default_colors(COLOR_WHITE, COLOR_GREEN);
|
|
|
|
init_pair(1, COLOR_BLACK, COLOR_WHITE);
|
|
|
|
init_pair(2, COLOR_RED, COLOR_WHITE);
|
|
|
|
init_pair(3, COLOR_WHITE, COLOR_BLUE);
|
|
|
|
init_pair(4, COLOR_WHITE, COLOR_GREEN);
|
|
|
|
|
2010-04-13 04:07:00 +00:00
|
|
|
greet_player();
|
|
|
|
|
2011-02-06 02:32:21 +00:00
|
|
|
while (key != KEY_SPACEBAR) {
|
|
|
|
switch (key = getch()) {
|
2011-02-06 06:14:17 +00:00
|
|
|
case KEY_SPACEBAR:
|
|
|
|
initialize_game();
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
case 'Q':
|
2011-06-03 06:09:14 +00:00
|
|
|
endwin();
|
|
|
|
return(0);
|
2010-04-13 04:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
2011-02-06 02:32:21 +00:00
|
|
|
if ((key = getch()) == 'q' || key == 'Q') {
|
2011-06-03 06:09:14 +00:00
|
|
|
endwin();
|
2011-02-10 01:50:24 +00:00
|
|
|
end_game();
|
2011-06-03 06:09:14 +00:00
|
|
|
return(0);
|
2011-02-06 02:32:21 +00:00
|
|
|
} else {
|
|
|
|
handle_keyboard_event(key);
|
2010-04-20 04:10:42 +00:00
|
|
|
}
|
2010-04-13 04:07:00 +00:00
|
|
|
}
|
2010-04-03 03:32:19 +00:00
|
|
|
|
2010-04-12 05:56:28 +00:00
|
|
|
return(0);
|
2010-03-31 05:21:17 +00:00
|
|
|
}
|