Tic Tac Toe in C++

Intrebari despre limbajul C++, standardul C++, STL, OOP in C++ sau alte subiecte nelegate de VisualC++
Post Reply
CristinaM
Junior
Junior
Posts: 2
Joined: 04 Dec 2015, 13:12
Judet: Sibiu

Tic Tac Toe in C++

Post by CristinaM » 04 Dec 2015, 13:33

Buna ziua,

Am de realizat un proiect, tema fiind X si 0.
Aplicaţie gen „Tic Tac Toe” în reţea.(Observatii: - tabla de joc de dimensiune n*n ; - validare pe 5 elemente pe orizontală, verticală şi diagonală.)

Cum as putea face asta?

Multumesc mult.



davidush
Junior
Junior
Posts: 7
Joined: 12 Jan 2016, 23:32
Judet: Iaşi

Re: Tic Tac Toe in C++

Post by davidush » 20 Feb 2016, 17:01

poate te ajuta ce am ...
e un x si o co VS player si PLAYER VS PLAYER
ai meniu facut sper sa iti fie util



#include <iostream>
#include "stdlib.h"


using namespace std;

int main()
{
int i, j, k = 0;
char a[3][3], nume1[30], nume2[30], q, v;
begin:
char castig='r';
system("color A");
cout<< "jucatorul 1";
cin>>nume1;
system("cls");
cout<<" jucatorul 2";
cin>>nume2;
system ("cls");
a[0][0] = '1';
a[0][1] = '2';
a[0][2] = '3';
a[1][0] = '4';
a[1][1] = '5';
a[1][2] = '6';
a[2][0] = '7';
a[2][1] = '8';
a[2][2] = '9';
while ((k <= 9) && (castig == 'r'))
{
cout<<" Intoduceti un numar:"<<endl;
cout<<a[0][0]<<" "<<a[0][1]<<" "<< a[0][2]<<endl;
cout<<a[1][0]<<" "<<a[1][1]<<" "<< a[1][2]<<endl;
cout<<a[2][0]<<" "<<a[2][1]<<" "<<a[2][2]<<endl;
cout<<nume1<<":";
cin>>q;
for(i = 0; i <= 2; i++)
for(j =0; j <=2; j++)
if(q == a[j])
a[j] = 'X';
k++;
if((a[0][0] == a[0][1]) && (a[0][1] == a[0][2]))
castig = a[0][0];
if((a[0][0] == a[2][0] )&& (a[2][0] == a[1][0]))
castig = a[0][0];
if((a[1][0] == a[1][1]) && (a[1][1] == a[1][2]))
castig = a[1][0];
if((a[2][0] == a[2][1]) && (a[2][1] == a[2][2]))
castig = a[2][0];
if((a[0][1] == a[1][1]) && (a[1][1] == a[2][1]))
castig = a[0][1];

if( (a[0][2] == a[1][2]) && (a[1][2] == a[2][2]) )
castig = a[0][2];
if( (a[0][0] == a[1][1]) && (a[1][1] == a[2][2]) )
castig = a[0][0];
if( (a[0][2] == a[1][1]) && (a[1][1] == a[2][0]))
castig = a[0][0];
system ("cls");
if(castig == 'r')
{
cout<<" Introduceti un numar:"<<endl;
cout<<a[0][0]<<" "<<a[0][1]<<" "<< a[0][2]<<endl;
cout<<a[1][0]<<" "<<a[1][1]<<" "<< a[1][2]<<endl;
cout<<a[2][0]<<" "<<a[2][1]<<" "<<a[2][2]<<endl;
cout<<nume1<<":";
cin>>q;
for(i = 0; i <= 2; i++)
for(j =0; j <=2; j++)
if(q == a[j])
a[j] = '0';
k++;
system ("cls");
if((a[0][0] == a[0][1]) && (a[0][1] == a[0][2]))
castig = a[0][0];
if((a[0][0] == a[2][0] )&& (a[2][0] == a[1][0]))
castig = a[0][0];
if((a[1][0] == a[1][1]) && (a[1][1] == a[1][2]))
castig = a[1][0];
if((a[2][0] == a[2][1]) && (a[2][1] == a[2][2]))
castig = a[2][0];
if((a[0][1] == a[1][1]) && (a[1][1] == a[2][1]))
castig = a[0][1];

if( (a[0][2] == a[1][2]) && (a[1][2] == a[2][2]) )
castig = a[0][2];
if( (a[0][0] == a[1][1]) && (a[1][1] == a[2][2]) )
castig = a[0][0];
if( (a[0][2] == a[1][1]) && (a[1][1] == a[2][0]))
castig = a[0][0];

}


}
system ("color C");
if (castig == 'X')
cout<<nume1<<"a castigat"<<endl;
if(castig == '0')
cout<<nume2<<"a castigat"<<endl;
if(castig == 'r')
cout<<"Remiza"<<endl;
cout<<"Apasa tasta q pentru a iesi din joc si tasta c pentru a relua o noua partida"<<endl;
cin>>v;
if(v == 'q')
return 0;
if(v == 'c')
{
system("cls");
goto begin;
}


}

Post Reply