الصفحات

الثلاثاء، 7 ديسمبر، 2010

لعبه x-o

This is my second Game I made
it is the X-O Game
I hope to admire  you
you can operate it with borland ++C
this is the Code:
---------------------------------------------------------- 
#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();
}


‏هناك 7 تعليقات:

  1. Gracias, buen trabajo! Este fue el material que tenía que tener.

    ردحذف
  2. Yo sólo quería hacer una observación rápida de decir que me alegro de haber encontrado tu blog. Gracias

    ردحذف
  3. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working ,great job!

    ردحذف
  4. 非常好东西。

    ردحذف
  5. Muchas gracias por escribir esto, se unbelieveably informativo y me dijo que una tonelada

    ردحذف
  6. Texto emocionante neste espaço, opiniôes deste modo realção aos que visitar neste espaço :)
    Faz mais do teu blog, aos teus cybernautas.

    ردحذف
  7. je ma pell badis mais jeux bon jeux

    ردحذف