Kod: Označi sve
#include <iostream>
#include <cstdlib>
using namespace std;
char uputa[7][7] {
{ '—' , '—' , '—' , '—' , '—' , '—' , '—' },
{ '|' , '1' , '|' , '2' , '|' , '3' , '|' },
{ '|' , '—' , '—' , '—' , '—' , '—' , '|' },
{ '|' , '4' , '|' , '5' , '|' , '6' , '|' },
{ '|' , '—' , '—' , '—' , '—' , '—' , '|' },
{ '|' , '7' , '|' , '8' , '|' , '9' , '|' },
{ '—' , '—' , '—' , '—' , '—' , '—' , '—' }
};
char igra[7][7] {
{ '_' , '_' , '_' , '_' , '_' , '_' , '_' },
{ '|' , ' ' , '|' , ' ' , '|' , ' ' , '|' },
{ '|' , '_' , '_' , '_' , '_' , '_' , '|' },
{ '|' , ' ' , '|' , ' ' , '|' , ' ' , '|' },
{ '|' , '_' , '_' , '_' , '_' , '_' , '|' },
{ '|' , ' ' , '|' , ' ' , '|' , ' ' , '|' },
{ '_' , '_' , '_' , '_' , '_' , '_' , '_' }
};
bool pobedaIgrac() {
if ( igra[1][1] == 'X' && igra[1][3] == 'X' && igra[1][1] == 'X' && igra[1][5] == 'X' ) return true;
if ( igra[3][1] == 'X' && igra[3][3] == 'X' && igra[3][1] == 'X' && igra[3][5] == 'X' ) return true;
if ( igra[5][1] == 'X' && igra[5][3] == 'X' && igra[5][1] == 'X' && igra[5][5] == 'X' ) return true;
if ( igra[1][1] == 'X' && igra[3][3] == 'X' && igra[1][1] == 'X' && igra[5][5] == 'X' ) return true;
if ( igra[5][1] == 'X' && igra[3][3] == 'X' && igra[5][1] == 'X' && igra[1][5] == 'X' ) return true;
if ( igra[1][1] == 'X' && igra[3][1] == 'X' && igra[1][1] == 'X' && igra[5][1] == 'X' ) return true;
if ( igra[1][3] == 'X' && igra[3][3] == 'X' && igra[1][3] == 'X' && igra[5][3] == 'X' ) return true;
if ( igra[1][5] == 'X' && igra[3][5] == 'X' && igra[1][5] == 'X' && igra[5][5] == 'X' ) return true;
return false;
}
bool pobedaKomp() {
if ( igra[1][1] == 'O' && igra[1][3] == 'O' && igra[1][1] == 'O' && igra[1][5] == 'O' ) return true;
if ( igra[3][1] == 'O' && igra[3][3] == 'O' && igra[3][1] == 'O' && igra[3][5] == 'O' ) return true;
if ( igra[5][1] == 'O' && igra[5][3] == 'O' && igra[5][1] == 'O' && igra[5][5] == 'O' ) return true;
if ( igra[1][1] == 'O' && igra[3][3] == 'O' && igra[1][1] == 'O' && igra[5][5] == 'O' ) return true;
if ( igra[5][1] == 'O' && igra[3][3] == 'O' && igra[5][1] == 'O' && igra[1][5] == 'O' ) return true;
if ( igra[1][1] == 'O' && igra[3][1] == 'O' && igra[1][1] == 'O' && igra[5][1] == 'O' ) return true;
if ( igra[1][3] == 'O' && igra[3][3] == 'O' && igra[1][3] == 'O' && igra[5][3] == 'O' ) return true;
if ( igra[1][5] == 'O' && igra[3][5] == 'O' && igra[1][5] == 'O' && igra[5][5] == 'O' ) return true;
return false;
}
void ispis() {
for ( int i=0 ; i<7 ; i++ ) {
for ( int j=0 ; j<7 ; j++ ) cout<<igra[i][j];
cout<<" ";
for ( int k=0 ; k<7 ; k++ ) cout<<uputa[i][k];
cout<<endl;
}
}
void ciscenje() {
for ( int i=1 ; i<=5 ; i+=2 ) {
for ( int j=1 ; j<=5 ; j+=2 ) {
igra[i][j] = ' ';
}
}
}
int main() {
pocetak:
ciscenje();
int poz;
for ( int i=0 ; i<5 ; i++) {
neki:
system("clear");
ispis();
cout<<"---------------------------"<<endl;
cout<<"Unesite poziciju"<<endl;
cin>>poz;
if ( poz < 1 || poz > 9 ) {
cout<<"UNESITE POZICIJU!!!!!!!!!!!"<<endl;
system("sleep 3");
goto neki;
}
switch(poz) {
case 1: if( igra[1][1] == ' ' ) igra[1][1] = 'X';
else {
cout<<"Unesite slobodnu poziciju!"<<endl;
system("sleep 3");
goto neki;
}
break;
case 2: if( igra[1][3] == ' ' ) igra[1][3] = 'X';
else {
cout<<"Unesite slobodnu poziciju!"<<endl;
system("sleep 3");
goto neki;
}
break;
case 3: if( igra[1][5] == ' ' ) igra[1][5] = 'X';
else {
cout<<"Unesite slobodnu poziciju!"<<endl;
system("sleep 3");
goto neki;
}
break;
case 4: if( igra[3][1] == ' ' ) igra[3][1] = 'X';
else {
cout<<"Unesite slobodnu poziciju!"<<endl;
system("sleep 3");
goto neki;
}
break;
case 5: if( igra[3][3] == ' ' ) igra[3][3] = 'X';
else {
cout<<"Unesite slobodnu poziciju!"<<endl;
system("sleep 3");
goto neki;
}
break;
case 6: if( igra[3][5] == ' ' ) igra[3][5] = 'X';
else {
cout<<"Unesite slobodnu poziciju!"<<endl;
system("sleep 3");
goto neki;
}
break;
case 7: if( igra[5][1] == ' ' ) igra[5][1] = 'X';
else {
cout<<"Unesite slobodnu poziciju!"<<endl;
system("sleep 3");
goto neki;
}
break;
case 8: if( igra[5][3] == ' ' ) igra[5][3] = 'X';
else {
cout<<"Unesite slobodnu poziciju!"<<endl;
system("sleep 3");
goto neki;
}
break;
case 9: if( igra[5][5] == ' ' ) igra[5][5] = 'X';
else {
cout<<"Unesite slobodnu poziciju!"<<endl;
system("sleep 3");
goto neki;
}
break;
}
if ( pobedaIgrac() ) {
system("clear");
ispis();
cout<<"POBJEDILI STE CESTITAMO!"<<endl;
goto ponovo;
}
for ( int j=1 ; j<=5 ; j+=2 ) {
for ( int k=1 ; k<=5 ; k+=2 ) {
if ( igra[j][k] == ' ' ) {
igra[j][k] = 'O';
if ( pobedaKomp() ) {
system("clear");
ispis();
cout<<"IZGUBILI STE!!!! <img src="http://programiranje.org/images/smilies/10.gif" alt=":P" title="Tongue">"<<endl;
goto ponovo;
} else {
igra[j][k] = ' ';
}
}
}
}
// random potez kompa
int moguci[2][9] , l(0) , n;
for ( int j=0 ; j<2 ; j++ ) {
for ( int k=0 ; k<9 ; k++ ) {
moguci[j][k] = 0;
}
}
for ( int j=1 ; j<=5 ; j+=2 ) {
for ( int k=1 ; k<=5 ; k+=2 ) {
if ( igra[j][k] == ' ' ) {
moguci[0][l] = j;
moguci[1][l] = k;
l++;
}
}
}
n = rand() % l;
igra[ moguci[0][n] ][ moguci[1][n] ] = 'O';
if ( i == 4 && pobedaIgrac() == false && pobedaKomp() == false ) {
cout<<"Nerijeseno."<<endl;
system("sleep 3");
goto ponovo;
}
}
ponovo:
char l;
cout<<"Zelite li igrati ponovo (D/N) ?"<<endl;
cin>>l;
if ( l == 'D' || l == 'd') goto pocetak;
else return 0;
}