6:daaf6e5b3501 | 7:41468077b5bb |
---|---|
26 * POSSIBILITY OF SUCH DAMAGE. | 26 * POSSIBILITY OF SUCH DAMAGE. |
27 * | 27 * |
28 */ | 28 */ |
29 | 29 |
30 #include "terminal-chess.h" | 30 #include "terminal-chess.h" |
31 #include "game.h" | |
32 #include "input.h" | |
31 #include <string.h> | 33 #include <string.h> |
32 #include <time.h> | 34 #include <time.h> |
33 #include <ncurses.h> | 35 #include <getopt.h> |
34 | 36 |
35 int get_settings(int argc, char **argv, Settings *settings) { | 37 int get_settings(int argc, char **argv, Settings *settings) { |
36 char *valid; | 38 char *valid; |
37 unsigned long int time, port; | 39 unsigned long int time, port; |
38 uint8_t timeunit = 60; | 40 uint8_t timeunit = 60; |
42 switch (opt) { | 44 switch (opt) { |
43 case 'b': | 45 case 'b': |
44 settings->gameinfo.servercolor = BLACK; | 46 settings->gameinfo.servercolor = BLACK; |
45 break; | 47 break; |
46 case 'r': | 48 case 'r': |
47 settings->gameinfo.servercolor = (rand()>>5) & 1 ? WHITE : BLACK; | 49 settings->gameinfo.servercolor = rand() & 1 ? WHITE : BLACK; |
48 break; | 50 break; |
49 case 't': | 51 case 't': |
50 case 'a': | 52 case 'a': |
51 len = strlen(optarg); | 53 len = strlen(optarg); |
52 if (optarg[len-1] == 's') { | 54 if (optarg[len-1] == 's') { |
123 printw(" No time limit\n"); | 125 printw(" No time limit\n"); |
124 } | 126 } |
125 refresh(); | 127 refresh(); |
126 } | 128 } |
127 | 129 |
128 static WINDOW* window; | |
129 | |
130 void leavescr() { | 130 void leavescr() { |
131 mvprintw(getmaxy(window)-1, 0, "Leaving terminal-chess. Press any key..."); | |
132 getch(); | |
133 endwin(); | 131 endwin(); |
134 } | 132 } |
135 | 133 |
136 int main(int argc, char **argv) { | 134 int main(int argc, char **argv) { |
137 srand(time(NULL)); | 135 srand(time(NULL)); |
160 "specify\nseconds for the -t option, use the s suffix.\n" | 158 "specify\nseconds for the -t option, use the s suffix.\n" |
161 "Example: -t 150s\n" | 159 "Example: -t 150s\n" |
162 ); | 160 ); |
163 return EXIT_SUCCESS; | 161 return EXIT_SUCCESS; |
164 } | 162 } |
165 | 163 tchess_window = initscr(); |
166 window = initscr(); | |
167 cbreak(); | 164 cbreak(); |
165 if (has_colors()) { | |
166 start_color(); | |
167 init_colorpairs(); | |
168 bkgd(COLOR_PAIR(COL_YB)); | |
169 } else { | |
170 fprintf(stderr, "Non-colored terminals are not supported yet."); | |
171 endwin(); | |
172 return EXIT_FAILURE; | |
173 } | |
168 atexit(leavescr); | 174 atexit(leavescr); |
169 | 175 |
170 return is_server(&settings) ? server_run(&settings) : client_run(&settings); | 176 return is_server(&settings) ? server_run(&settings) : client_run(&settings); |
171 } | 177 } |
172 | 178 |