2010-03-31 05:21:17 +00:00
|
|
|
#include <ncurses.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <string.h>
|
2010-03-31 20:39:28 +00:00
|
|
|
#include "common.h"
|
2010-04-01 05:28:00 +00:00
|
|
|
#include "../lib/card.h"
|
2010-03-31 05:21:17 +00:00
|
|
|
|
|
|
|
int main(int argc, const char *argv[]) {
|
|
|
|
char message[] = "Welcome to tty-solitaire.";
|
|
|
|
int ch;
|
|
|
|
int row_number, column_number;
|
|
|
|
struct card *card = NULL;
|
|
|
|
|
|
|
|
initscr(); /* initialize the terminal in curses mode */
|
|
|
|
raw(); /* disable line buffers */
|
|
|
|
noecho(); /* character echo is unnecessary */
|
|
|
|
keypad(stdscr, TRUE); /* enable F and arrow keys */
|
|
|
|
|
|
|
|
getmaxyx(stdscr, row_number, column_number);
|
|
|
|
mvprintw(row_number / 2 - 1,
|
|
|
|
(column_number - strlen(message)) / 2,
|
|
|
|
"%s\n",
|
|
|
|
message);
|
|
|
|
|
|
|
|
card = initialize_card();
|
|
|
|
|
|
|
|
set_card(card, KING, CLUBS, TRUE, 1, 1);
|
|
|
|
|
2010-04-01 05:28:00 +00:00
|
|
|
refresh_card(card);
|
2010-03-31 05:21:17 +00:00
|
|
|
|
|
|
|
while ((ch = getch()) != KEY_F(1)) {
|
|
|
|
switch(ch) {
|
|
|
|
case KEY_LEFT:
|
|
|
|
case 'h':
|
2010-04-01 05:28:00 +00:00
|
|
|
refresh_card(card);
|
2010-03-31 05:21:17 +00:00
|
|
|
break;
|
|
|
|
case KEY_RIGHT:
|
|
|
|
case 'l':
|
2010-04-01 05:28:00 +00:00
|
|
|
refresh_card(card);
|
2010-03-31 05:21:17 +00:00
|
|
|
break;
|
|
|
|
case KEY_UP:
|
|
|
|
case 'k':
|
2010-04-01 05:28:00 +00:00
|
|
|
refresh_card(card);
|
2010-03-31 05:21:17 +00:00
|
|
|
break;
|
|
|
|
case KEY_DOWN:
|
|
|
|
case 'j':
|
2010-04-01 05:28:00 +00:00
|
|
|
refresh_card(card);
|
2010-03-31 05:21:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
endwin();
|
|
|
|
puts("Game finished.");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|