Pozdrav svima koji citaju ovo,ucim c++ za domaci ima iks oks igricu ,ona treba da bude OOP C++
Ja sam napravila,ali zelim da pitam da l je ovo ''dovoljno OOP c++''?
class IksOks
{
private:
char tabla[3][3];
public: IksOks() {}
void setTabla()
{
int n = 1;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{ tabla[i][j] = '0' + n;
n++; } } }
void stampajTabla()
{
for(int i = 0; i < 3; i++)
{ for(int j = 0; j < 3; j++)
if(j < 2) { cout << tabla[i][j] << "|"; }
else { cout << tabla[i][j] << endl; }
if(i < 2) { cout << "-+-+-\n"; } } }
void igracpom(char num, char igrac)
{
bool lospotez = true;
for(int i = 0; i < 3; i++)
{ for(int j = 0; j < 3; j++)
{
if(tabla[i][j] == num)
{
tabla[i][j] = igrac; lospotez = false; } } }
if(lospotez == true) { cout << "Pogresan Potez!\n"; } }
bool cekPobednik(char igrac, bool gameOver) {
for(int i = 0; i < 3; i++)
if(tabla[i][0] == tabla[i][1] && tabla[i][1] == tabla[i][2]) gameOver = true;
for(int i = 0; i < 3; i++)
if(tabla[0][i] == tabla[1][i] && tabla[1][i] == tabla[2][i]) gameOver = true;
if(tabla[0][0] == tabla[1][1] && tabla[1][1] == tabla[2][2]) gameOver=true;
if(tabla[0][2] == tabla[1][1] && tabla[1][1] == tabla[2][0]) gameOver = true;
if(gameOver == true) { cout << "Igrac " << igrac << " Pobedio!\n\n"; }
return gameOver; }
bool cek(bool gameOver)
{
int n = 1, count = 0;
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++)
{
if(tabla[i][j] == '0'+n) { count++; } n++; }
}
if(count < 1)
{
cout << "Nereseno!\n\n";
gameOver = true; }
return gameOver; }
};
int main()
{ bool done = false, gameOver = false;
char igrac = 'O', num;
IksOks jelena;
jelena.setTabla(); do {
if(igrac == 'X')
{
igrac = 'O';
}
else { igrac = 'X';
}
jelena.stampajTabla();
cout << "Igrac \"" << igrac << "\" Pritisni (q) da izadjes> ";
cin >> num;
cout << "\n";
if(num == 'q')
{
cout << "Dovidjenja!\n";
break; }
jelena.igracpom(num, igrac);
gameOver = jelena.cekPobednik(igrac, gameOver);
gameOver = jelena.cek(gameOver);
if(gameOver == true)
{
jelena.setTabla();
gameOver = false; } }
while(!done);
system("pause");
return 0;
};
|