Jump to content

[C++] X si 0


DoTT
 Share

Recommended Posts

A trecut ceva timp de cand am mai dat pe forum si de cand am facut ultimul program.. De atunci am mai invatat cate putin si am facut un mic joc de x si 0 pentru scoala...

 

 

#include<iostream>
void main()
{
std::cout<<"Creator: DoTT @ B-zone Forum"<<std::endl;std::cout<<"[url="http://b-zone.ro/forum/user/4145-dott/"]http://b-zone.ro/forum/user/4145-dott/[/url]"<<std::endl<<std::endl;
char cPatrat1 = '1';
char cPatrat2 = '2';
char cPatrat3 = '3';
char cPatrat4='4';
char cPatrat5='5';
char cPatrat6='6';
char cPatrat7='7';
char cPatrat8='8';
char cPatrat9='9';
int iTura = 1;
bool bJocTerminat(true);

//Joc
do{ //Tabla
std::cout<<cPatrat1<<"|"<<cPatrat2<<"|"<<cPatrat3<<std::endl;
std::cout<<"-+-+-"<<std::endl;
std::cout<<cPatrat4<<"|"<<cPatrat5<<"|"<<cPatrat6<<std::endl;
std::cout<<"-+-+-"<<std::endl;
std::cout<<cPatrat7<<"|"<<cPatrat8<<"|"<<cPatrat9<<std::endl;
//Simbol
char cSimbol;
if (iTura == 1)
{cSimbol = 'X';
}
else {cSimbol = 'O';
}
//Miscari
std::cout<<"Tura jucatorului "<<iTura<<", alege o casuta: ";
bool bMiscareValida;
do{
char cUrmMiscare;
std::cin>>cUrmMiscare;
bMiscareValida = true;

//Verifica miscarea
if(cUrmMiscare == '1' && cPatrat1 == '1')
{cPatrat1 = cSimbol;}
else if(cUrmMiscare == '2' && cPatrat2 == '2')
{cPatrat2 = cSimbol;}
else if(cUrmMiscare == '3' && cPatrat3 == '3')
{cPatrat3 = cSimbol;}
else if(cUrmMiscare == '4' && cPatrat4 == '4')
{cPatrat4 = cSimbol;}
else if(cUrmMiscare == '5' && cPatrat5 == '5')
{cPatrat5 = cSimbol;}
else if(cUrmMiscare == '6' && cPatrat6 == '6')
{cPatrat6 = cSimbol;}
else if(cUrmMiscare == '7' && cPatrat7 == '7')
{cPatrat7 = cSimbol;}
else if(cUrmMiscare == '8' && cPatrat8 == '8')
{cPatrat8 = cSimbol;}
else if(cUrmMiscare == '9' && cPatrat9 == '9')
{cPatrat9 = cSimbol;}
else {std::cout<<"Miscare nevalida"<<std::endl;
bMiscareValida = false;}
}while(!bMiscareValida);
bJocTerminat = false;
bool bCastig = true;
//Castig
if(cPatrat1 != '1')
{
if(cPatrat2 == cPatrat1 && cPatrat3 == cPatrat1)
{
bJocTerminat = true;
}
if(cPatrat4 == cPatrat1 && cPatrat7 == cPatrat1)
{
bJocTerminat = true ;
}
}
if(cPatrat5 != '5')
{
if(cPatrat1 == cPatrat5 && cPatrat9 == cPatrat5)
{
bJocTerminat= true;}
if(cPatrat2 == cPatrat5 && cPatrat8 == cPatrat5)
{
bJocTerminat= true;}
if(cPatrat3 == cPatrat5 && cPatrat7 == cPatrat5)
{
bJocTerminat= true;}
if(cPatrat4 == cPatrat5 && cPatrat6 == cPatrat5)
{
bJocTerminat= true;}
}
if(cPatrat9 != '9')
{
if(cPatrat6 == cPatrat9 && cPatrat3 == cPatrat9)
{
bJocTerminat= true;}
if(cPatrat8 == cPatrat9 && cPatrat7 == cPatrat9)
{
bJocTerminat= true;}
}
if(cPatrat1 != '1' && cPatrat2 != '2 '&& cPatrat3 != '3 '&&
 cPatrat4 != '4' && cPatrat5 != '5 '&& cPatrat6 != '6 '&&
 cPatrat7 != '7' && cPatrat8 != '8' && cPatrat9 != '9' && !bJocTerminat)
{
bJocTerminat = true;
  bCastig = false;
}

if(bJocTerminat)
{

std::cout<<cPatrat1<<"|"<<cPatrat2<<"|"<<cPatrat3<<std::endl;
std::cout<<"-+-+-"<<std::endl;
std::cout<<cPatrat4<<"|"<<cPatrat5<<"|"<<cPatrat6<<std::endl;
std::cout<<"-+-+-"<<std::endl;
std::cout<<cPatrat7<<"|"<<cPatrat8<<"|"<<cPatrat9<<std::endl;
if(bCastig)
{
std::cout<<"Joc Terminat"<<std::endl;
std::cout<<"Jucatorul "<<iTura<<" a castigat"<<std::endl;
}
else
{
std::cout<<"Egalitate"<<std::endl;
}

}
else
{
if(iTura == 1)
{iTura = 2;}
else
{iTura = 1;
}

}
std::cin.get();
}while(!bJocTerminat);
std::cin.get();
}


 

 

 

Din moment ce e primul program Visual C++ pe care il uploadez , spuneti-mi va rog daca http://www.2shared.c...xsio.html e tot ceea ce aveti nevoie ca sa functioneze.

 

Daca nu, http://www.2shared.c...PZh6/xsio.html? e arhiva cu toate fisierele.

Am incercat sa il fac sa se repete singur , insa nu mi-a reusit , o sa mai lucrez (posibil) la el.

Edited by eB Teodor
Link to comment
Share on other sites

Foarte buna ideea!

Programul are mici scapari, dar nu cred ca este important acum sa insisti pe chestii de genu: "daca nu introduci nr corespunzator sa faca asa, asa, etc.

Important este ca merge foarte bine si inca odatata te felicit pentru idee.

Link to comment
Share on other sites

Scrierea e gresita, sau asa e de la mine

Am deschis codul tau cu codeblock's , adica am rescris-o si e o greseala

Cu codeblocks nu mil ia cu void main() , dar mil ia cu int main() ...

Frumoasa creatia , gg

 

error: '::main' must return 'int'

Edited by FreedoM9
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.