08-04-2011, 11:58 PM
|
|
|
|
تاريخ التسجيل: Mar 2011
الكلية: أخرى
نوع الدراسة: عضو هيئة تدريس
المستوى: متخرج
البلد:
الخبر
الجنس: ذكر
المشاركات: 4,052
|
|
لعبــــة x-o بالسي بلس بلس
الـســــلامـ علـــيكمـ ورحمــــة الله وبــركاتـــه
للي بيحــــب يستفيد من البرمــــجه في الالعــــاب .. هذي لعبـــــة x-o بالسي بلس بلس
ان شاء الله تعجبكـــــو ..
كود:
#include <iostream>
#include <conio>
#include <iomanip>
inline void reasult (char win[10],char lose[10])
{
cout<<win<<" is win ";
cout<<endl<<lose<<" is lose \n";
}
void main()
{
char player1[10],player2[10],game[3][3];
int i,k,row1,col1,col2,row2,counter=0;
bool z;
cout<<"\n \n \t welcome in my GAME =====> "; getch(); clrscr();
cout<<endl<<"the RULES of my GAME is :\n"
<<"it is the X-O GAME you must know it :) \n "
<<"1- we need 2 player \n"
<<"2- firest player choice x and the second player choice o";
getch(); clrscr();
cout<<"enter your name (for first player ):\t"; cin>>player1;
cout<<"enter your name (for second player ):\t"; cin>>player2;
for( i=0;i<3;i++)
for( k=0;k<3;k++)
game[i][k]='_';
//print screen
cout<<"---- the GAME now is------------------\n" ;
cout<<endl<<"---------------------------------------"<<endl;
cout<<setw(16);
for(i=0;i<3;i++)
cout<<"col"<<setw(10);
cout<<endl;
cout<<setw(16);
for(i=0;i<3;i++)
cout<<(i+1)<<setw(10);
cout<<endl<<"--------------------------------------"<<endl;
for(i=0;i<3;i++)
{
cout<<"row("<<(i+1)<<")"<<setw(10);
for(k=0;k<3;k++)
cout<<game[i][k]<<setw(10);
cout<<endl<<"--------------------------------------"<<endl;
}
while(counter<8)// loop 9 times
{
do{
z=false;
cout<<endl<<"(for first player) where do you want to put the x ??"
<<endl<<"row : "; cin>>row1; cout<<"colomn : "; cin>>col1;
// search of 11 and 10
if(game[row1-1][col1-1]=='o' || game[row1-1][col1-1]=='x' )
{cout<<"error!! you enter this place befor \n"; z=true;}
else
{
game[row1-1][col1-1]='x';
//print screen
cout<<"---- the GAME now is------------------\n" ;
cout<<endl<<"---------------------------------------"<<endl;
cout<<setw(16);
for(i=0;i<3;i++)
cout<<"col"<<setw(10);
cout<<endl;
cout<<setw(16);
for(i=0;i<3;i++)
cout<<(i+1)<<setw(10);
cout<<endl<<"--------------------------------------"<<endl;
for(i=0;i<3;i++)
{
cout<<"row("<<(i+1)<<")"<<setw(10);
for(k=0;k<3;k++)
cout<<game[i][k]<<setw(10);
cout<<endl<<"--------------------------------------"<<endl; //end of printe
}
for(i=0,k=0;i<2;i++,k++)
if(game[i][k]==game[i+1][k+1]&& game[i][k]=='x')
if(i<1)
continue;
else
{ reasult(player1,player2); goto end;} //we search for kodor
else
break;
for(i=0,k=2;i<2;i++,k--)
if(game[i][k]==game[i+1][k-1] && game[i][k]=='x')
if(i<1)
continue;
else
{reasult(player1,player2); goto end;}
else
break; //we search for kotor aksy
for(int n=0;n<3;n++)
for(i=n,k=0;k<=1;k++)
if(game[i][k]==game[i][k+1] && game[i][k]=='x')
if(k<1)
continue;
else
{ reasult(player1,player2); goto end;}
else
break; //end of rows
for(int n=0;n<3;n++)
for(i=n,k=0;k<=1;k++)
if(game[k][i]==game[k+1][i] && game[k][i]=='x')
if(k<1) continue;
else
{reasult(player1,player2); goto end;}
else
break;// search for col
}
}while(z);
counter++;
do{
z=false;
cout<<endl<<"(for second player where do you want to put the o"
<<endl<<"row : "; cin>>row2; cout<<"colomn : "; cin>>col2;
// search of 11 and 10
if(game[row2-1][col2-1]=='o' || game[row2-1][col2-1]=='x' )
{cout<<"error!! you enter this place befor \n"; z=true;}
else
{
game[row2-1][col2-1]='o';
//print screen
cout<<"---- the GAME now is------------------\n" ;
cout<<endl<<"---------------------------------------"<<endl;
cout<<setw(16);
for(i=0;i<3;i++)
cout<<"col"<<setw(10);
cout<<endl;
cout<<setw(16);
for(i=0;i<3;i++)
cout<<(i+1)<<setw(10);
cout<<endl<<"--------------------------------------"<<endl;
for(i=0;i<3;i++)
{
cout<<"row("<<(i+1)<<")"<<setw(10);
for(k=0;k<3;k++)
cout<<game[i][k]<<setw(10);
cout<<endl<<"--------------------------------------"<<endl;
}
// show if he win(by if..else..
for(i=0,k=0;i<2;i++,k++)
if(game[i][k]==game[i+1][k+1]&& game[i][k]=='o')
if(i<1)
continue;
else
{ reasult(player2,player1); goto end;} //we search for kodor
else
break;
for(i=0,k=2;i<2;i++,k--)
if(game[i][k]==game[i+1][k-1] && game[i][k]=='o')
if(i<1)
continue;
else
{reasult(player2,player1); goto end;}
else
break; //we search for kotor aksy
for(int n=0;n<3;n++)
for(i=n,k=0;k<=1;k++)
if(game[i][k]==game[i][k+1] && game[i][k]=='o')
if(k<1)
continue;
else
{ reasult(player2,player1); goto end;}
else
break; //end of rows
for(int n=0;n<3;n++)
for(i=n,k=0;k<=1;k++)
if(game[k][i]==game[k+1][i] && game[k][i]=='o')
if(k<1) continue;
else
{reasult(player2,player1); goto end;}
else
break;// search for col
}// end of else
}while(z);
counter++;
}
end:
getch();
}
|