Iz dosade na casu poceo sam da radim ovu igricu. Ovo verovatno nikome nece koristiti ali eto... Odnesite i vi profesoru ovaj kod pa vas mozda nagradi sa ocenom
#include <stdio.h>
char table[234] = "\n\n\t -------------- \n\t| | | |\n\t| | | |\n\t| | | |\n\t----------------\n\t| | | |\n\t| | | |\n\t| | | |\n\t----------------\n\t| | | |\n\t| | | |\n\t| | | |\n\t --------------";
char x[8];
int i, p, turn, player, winner;
void write_table() {
for(i=0;i<=234;i=i+1) {
switch (i) {
case 41:
printf("%c",x[6]);
i=i+1;
break;
case 46:
printf("%c",x[7]);
i=i+1;
break;
case 51:
printf("%c",x[8]);
i=i+1;
break;
case 113:
printf("%c",x[3]);
i=i+1;
break;
case 118:
printf("%c",x[4]);
i=i+1;
break;
case 123:
printf("%c",x[5]);
i=i+1;
break;
case 185:
printf("%c",x[0]);
i=i+1;
break;
case 190:
printf("%c",x[1]);
i=i+1;
break;
case 195:
printf("%c",x[2]);
i=i+1;
break;
}
printf("%c",table[i]);
}
}
void check_winner() {
if (x[0]==x[1] && x[1]==x[2] && x[1]!=0) {winner=x[0];}
if (x[3]==x[4] && x[4]==x[5] && x[4]!=0) {winner=x[3];}
if (x[6]==x[7] && x[7]==x[8] && x[7]!=0) {winner=x[6];}
if (x[0]==x[3] && x[3]==x[6] && x[3]!=0) {winner=x[0];}
if (x[1]==x[4] && x[4]==x[7] && x[4]!=0) {winner=x[1];}
if (x[2]==x[5] && x[5]==x[8] && x[5]!=0) {winner=x[2];}
if (x[0]==x[4] && x[4]==x[8] && x[4]!=0) {winner=x[0];}
if (x[2]==x[4] && x[4]==x[6] && x[4]!=0) {winner=x[2];}
}
main(){
player = 1;
turn = 0;
winner = 0;
for (i=0;i<=8;i++){ x[i]=i+49; }
write_table();
for (i=0;i<=8;i++){ x[i]=0; }
do {
if (player == 0) {
printf ("\n\n\nIgrac X je na potezu!\nIzaberite u koje polje zelite da upisete vas znak: ");}
else if (player == 1) {
printf ("\n\n\nIgrac O je na potezu!\nIzaberite u koje polje zelite da upisete vas znak: ");}
scanf("%d",&p);
if (x[p-1]!=79 && x[p-1]!=88){
if (player == 0) {
x[p-1]=88;
player=1;
system ("cls");
write_table();
check_winner();
if (winner != 0) {break;}
} else if (player == 1) {
x[p-1]=79;
player=0;
system ("cls");
write_table();
check_winner();
if (winner != 0) {break;}
}
}else{
turn--;
}
turn++;
} while (turn<9);
printf("\n\n\n");
if (winner==0){
printf("U ovoj partiji nema pobednika!");
}else{
printf("Pobednik je igrac >> %c <<", winner);
}
printf("\n\n\n");
system("pause");
return 0;
}
|