Sunteți pe pagina 1din 4

#include<stdio.

h>

#include<conio.h>

#include<windows.h>

#include<stdlib.h>

char tabla[10] = { 'o', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

int verCas();

void drawTabla();

int main()

int player=1 , i, choice;

char simbol;

do

drawTabla();

player = (player % 2) ? 1 : 2; // schimbai forma

printf("Jucatorul %d introdu un simbol : ",player);

scanf("%d",&choice);

simbol = (player == 1) ? 'X' : 'O';

if(choice == 1 && tabla[1] == '1') tabla[1] = simbol;

else if(choice == 2 && tabla[2] == '2') tabla[2] = simbol;

else if(choice == 3 && tabla[3] == '3') tabla[3] = simbol;

else if(choice == 4 && tabla[4] == '4') tabla[4] = simbol;

else if(choice == 5 && tabla[5] == '5') tabla[5] = simbol;


else if(choice == 6 && tabla[6] == '6') tabla[6] = simbol;

else if(choice == 7 && tabla[7] == '7') tabla[7] = simbol;

else if(choice == 8 && tabla[8] == '8') tabla[8] = simbol;

else if(choice == 9 && tabla[9] == '9') tabla[9] = simbol;

else{

printf("Optiune nu este buna , casuta e ocupata ! Apasa enter pentru a


introduce alta valoare");

player--;

getch();

i= verCas();

player++;

}while(i == -1);

drawTabla();

if(i==1){

printf("\nCastigatorul este %d ",--player);

else {

printf("\nEgalitate ");

getch(); // verifica pentru ce

return 0;//vrerifica pentru ce

int verCas(){
if(tabla[1] == tabla[2] && tabla[2] == tabla [3]) return 1; //posibil sa fie greseli

else if(tabla[4] == tabla[5] && tabla[5] == tabla [6]) return 1;

else if(tabla[7] == tabla[8] && tabla[8] == tabla [9]) return 1;

else if(tabla[1] == tabla[4] && tabla[4] == tabla [7]) return 1;

else if(tabla[2] == tabla[5] && tabla[5] == tabla [8]) return 1;

else if(tabla[3] == tabla[6] && tabla[6] == tabla [9]) return 1;

else if(tabla[1] == tabla[5] && tabla[5] == tabla [9]) return 1;

else if(tabla[3] == tabla[5] && tabla[5] == tabla [7]) return 1;

else if(tabla[1] != '1' && tabla[2] != '2' && tabla[3] != '3' && tabla[4] != '4' && tabla[5] != '5' && tabla[6] !
= '6' && tabla[7] != '7' && tabla[8] != '8' && tabla[9] !='9')

return 0;

else return -1; // verifica de ce?

void drawTabla()

system("cls");

printf("\n\n\tTic Tac Toe\n\n");

printf("Player 1 (X) - Player2 (O)\n\n\n");// introdu numele cu string

printf(" | | \n");

printf(" %c | %c | %c \n", tabla[1],tabla[2], tabla[3]);

printf("_____|_____|_____\n");

printf(" | | \n");
printf(" %c | %c | %c \n", tabla[4],tabla[5], tabla[6]);

printf("_____|_____|_____\n");

printf(" | | \n");

printf(" %c | %c | %c \n", tabla[7],tabla[8], tabla[9]);

printf(" | | \n\n");