main.c (1387B)
1 #include <ncurses.h> 2 #include <string.h> 3 4 #include "board.h" 5 #include "draw.h" 6 #include "piece.h" 7 8 void 9 play_sprint() { 10 Board b; 11 b.q[0] = O; 12 b.q[1] = I; 13 b.q[2] = T; 14 b.q[3] = L; 15 b.q[4] = J; 16 b.q[5] = S; 17 b.q[6] = Z; 18 b.qi = 5; 19 20 clear(); 21 22 draw_box(COLS/2 - 11, LINES/2 - 11, COLS/2 + 10, LINES/2 + 11); 23 24 char key; 25 for (;;) { 26 draw_board(&b); 27 draw_queue(&b); 28 key = getch(); 29 if (key == 'q') break; 30 } 31 } 32 33 void 34 draw_menu_item(int y, const char *str) { 35 mvprintw(y, COLS/2 - strlen(str)/2, str); 36 } 37 38 void 39 draw_main_menu() { 40 clear(); 41 42 draw_box(COLS/2 - 11, LINES/2 - 11, COLS/2 + 10, LINES/2 + 11); 43 44 draw_menu_item(LINES/2 - 8, "Sprint"); 45 } 46 47 int 48 main() { 49 initscr(); 50 start_color(); 51 52 timeout(0); 53 keypad(stdscr, TRUE); 54 cbreak(); 55 noecho(); 56 57 curs_set(0); 58 59 int key; 60 61 init_pair(O, COLOR_BLACK, COLOR_YELLOW); 62 init_pair(I, COLOR_BLACK, COLOR_CYAN); 63 init_pair(T, COLOR_BLACK, COLOR_MAGENTA); 64 init_pair(L, COLOR_BLACK, 208); 65 init_pair(J, COLOR_BLACK, COLOR_BLUE); 66 init_pair(S, COLOR_BLACK, COLOR_GREEN); 67 init_pair(Z, COLOR_BLACK, COLOR_RED); 68 69 init_pair(8, COLOR_BLACK, COLOR_WHITE); 70 71 /* Main menu */ 72 draw_main_menu(); 73 for (;;) { 74 key = getch(); 75 if (key == 'q') break; 76 else if (key == '\n') { 77 play_sprint(); 78 draw_main_menu(); 79 } 80 else if (key == KEY_RESIZE) { 81 draw_main_menu(); 82 } 83 mvaddch(LINES/2 - 8, COLS/2 - 6, '>'); 84 } 85 86 endwin(); 87 88 return 0; 89 }