void display8hotext(void)//TEXT模式下写调用 CGROM 中字符 { unsigned int hang;// unsigned int lie;// for(hang=1;hang<=((size_hang*3/8)/8);hang++)//3/8屏字符8 { for(lie=1;lie<=(size_lie/8);lie++) display_ascii( &h8O,hang, lie ); } for(hang=(((size_hang*3/8)/8)+1);hang<=(((size_hang*3/8)/8)+2);hang++)//2/8屏H { for(lie=1;lie<=(size_lie/8);lie++) display_ascii( &h8O+1,hang, lie ); } for(hang=(((size_hang*3/8)/8)+3);hang<=(((size_hang*3/8)/8)+5);hang++)//3/8屏 O { for(lie=1;lie<=(size_lie/8);lie++) display_ascii( &h8O+2,hang, lie ); } }
// my main man int main() { char x = 0; int y = 0; char option = 'a'; int currentPlayer = 0; // switches between 0 and 1 int board[WIDTH][HEIGHT]; int winCheck; // stores return of win checker clear_table(board, WIDTH, HEIGHT); printf("This program plays the game of tic-tac-toe\n"); while(1) { // ASKYYY // printf("It is Player %s's turn. Please type in one of the following:\n", currentPlayer?"O":"X"); // printf("\"x, y\": makes move in square x, y\n\"c\": clears board\n\"s\": displays ASCII board\n\"p\": displays PGM board\n\n"); printf("Enter a command for Player %d ([row,col], c, s, p):", currentPlayer + 1); // scanf an int, if it's an int then start reading as coordinates // else if it's a char then I dunno you can store it as option I guess scanf("%c", &x); if(x >= '0' && x <='9') { // ● a legal move x = atoi((const char *) &x); // there are better ways than atoi like subtracting value of ascii but w/e scanf(", %d", &y); x--; y--; // X AND Y ARE NOW 0-INDEXED if(!make_move(board, WIDTH, HEIGHT, y, x, currentPlayer)) { printf("Invalid selection\n\n"); while((getchar())!='\n'); // Clears input buffer continue; // this takes you into the else case with the switch actually } // Here's your win check. winCheck = check_four_in_a_row(board, WIDTH, HEIGHT); // store for analysis if(winCheck) { if(winCheck == -1) { // Full board printf("Game over, no player wins.\n"); exit(0); } else { // A player wins, wincheck is 1 or 2 printf("Congratulations, Player %d wins!\n", winCheck); exit(0); } } // else keep playing because the board's not full and nobody won // printf("Changing currentPlayer\n"); currentPlayer = !currentPlayer; } else { option = x; switch(option) { case 'c': // ● c: clear the board clear_table(board, WIDTH, HEIGHT); currentPlayer = 0; break; case 's': // ● s: print the state of the board as displayed in Figure 1 display_ascii(board, WIDTH, HEIGHT); break; case 'p': // ● p: print the state of the board as an image (see below for more info) display_image(board, WIDTH, HEIGHT); break; case '1': // invalid move break; default: printf("Not a menu item\n"); break; } } while((getchar())!='\n'); // Clears input buffer. } }