#include <stdio.h> #include <conio.h> #include <stdlib.h>
void board(int a, int b, int c, int d, int e, int f, int g, int h, int i) { printf(" %c | %c | %c \n",a,b,c); printf("----------\n"); printf(" %c | %c | %c \n",d,e,f); printf("----------\n"); printf(" %c | %c | %c \n",g,h,i); printf("\n\n"); }
void menu() { printf("--------------------\n"); printf("- XO -\n"); printf("--------------------\n"); printf("\n\n"); } int check(char arr[]) { if(arr[0] == arr[1] == arr[2])return 1; if(arr[3] == arr[4] == arr[5])return 1; if(arr[6] == arr[7] == arr[8])return 1; if(arr[0] == arr[3] == arr[6])return 1; if(arr[1] == arr[4] == arr[7])return 1; if(arr[2] == arr[5] == arr[8])return 1; if(arr[0] == arr[4] == arr[8])return 1; if(arr[2] == arr[4] == arr[6])return 1;
return 0; }
int main() { int action, turn, position; position=0; char score[9] = {'1','2','3','4','5','6','7','8','9'}; system("cls"); menu(); printf("\n"); printf("1)Play\n2)Exit\n"); scanf("%d", &action); system("cls"); menu(); turn = 1; for(int i=0; i<5; i++) { system("cls"); menu(); board(score[0],score[1],score[2],score[3],score[4],score[5],score[6],score[7],score[8]); printf("\nX Turn\n"); turn=0; scanf("%d", &position); score[position-1] = 'X'; if(check(score) == 1) printf("We Have a winner!!"); system("cls"); menu(); board(score[0],score[1],score[2],score[3],score[4],score[5],score[6],score[7],score[8]); printf("\nO Turn\n"); scanf("%d", &position); score[position-1] = 'O'; &n bsp; if(check(score) == 1) printf("We Have a winner!!"); } getch(); return 0; }
|