MouhcineFD

X O FD

Apr 10th, 2013
4,317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 17.30 KB | None | 0 0
  1. //All copyrights recived to MouhcineFD
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. char tab[3][3],tabb[2][10];
  6. int i,j,posij,nbrj,nbrp,pgan;
  7. void afich();
  8. void jouerhasar();
  9. int scangan();
  10. void utijouer();
  11. int intljouer();
  12. void rmtazero();
  13. void pausesc(int nbresec)
  14. {
  15.     clock_t goal;
  16.     goal=(nbresec*CLOCKS_PER_SEC)+clock();
  17.     while(goal>clock())
  18.         ;
  19. }
  20. int main()
  21. {
  22.     system("title X O By MouhcineFD");
  23.     printf("////////////////////////////////////////////////////\n");
  24.     printf("////////////////////////////////////////////////////\n");
  25.     printf("//// Bienvenue Sur X O Devlopper Par MouhcineFD ////\n");
  26.     printf("////////////////////////////////////////////////////\n");
  27.     printf("////////////////////////////////////////////////////\n");
  28.     pausesc(3);
  29.     int choixm=1,choixm2,qint,choixm3,qjp;
  30.     srand(time(NULL));
  31.     while(choixm==1)
  32.     {
  33.         do
  34.         {
  35.             printf("\nCombien de partie voulez vous jouer ? ! Le maximan 10 !\n");
  36.             scanf("%d",&nbrp);
  37.             if(nbrp<=0||nbrp>10)
  38.                 printf("\nT'as choisi le mauvais choix !!!\nRepete la choix.\n");
  39.         }
  40.         while(nbrp<=0||nbrp>10);
  41.         pgan=qjp=nbrp;
  42.         for(i=0; i<3; i++)
  43.         {
  44.             for(j=0; j<3; j++)
  45.             {
  46.                 tab[i][j]=' ';
  47.             }
  48.         }
  49.         for(i=0; i<2; i++)
  50.         {
  51.             for(j=0; j<nbrp; j++)
  52.             {
  53.                 tabb[i][j]=' ';
  54.             }
  55.         }
  56.         nbrj=0;
  57.         do
  58.         {
  59.             printf("\nVoulez-vous jouer avec ?\n1 : Ordinateur.\n2 : Un autre joueur.\n");
  60.             scanf("%d",&choixm3);
  61.             switch(choixm3)
  62.             {
  63.             case 1:
  64.                 do
  65.                 {
  66.                     printf("\nSelectionnez le niveau :\n1 : Facile.\n2 : Difficile.\n");
  67.                     scanf("%d",&choixm2);
  68.                     switch(choixm2)
  69.                     {
  70.                     case 1:
  71.                         while(nbrp>0)
  72.                         {
  73.                             system("cls");
  74.                             if(qjp%2==0)
  75.                             {
  76.                                 jouerhasar();
  77.                                 nbrj++;
  78.                             }
  79.                             while(nbrj<9&&scangan()!=0)
  80.                             {
  81.                                 if(nbrj<9&&scangan()!=0)
  82.                                 {
  83.                                     printf("\n Vous (O).\n");
  84.                                     utijouer();
  85.                                     nbrj++;
  86.                                 }
  87.                                 if(nbrj<9&&scangan()!=0)
  88.                                 {
  89.                                     if(casajouer()!=0)
  90.                                         jouerhasar();
  91.                                     nbrj++;
  92.                                 }
  93.                             }
  94.                             rmtazero();
  95.                             nbrp--;
  96.                             qjp=nbrp;
  97.                         }
  98.                         break;
  99.                     case 2:
  100.  
  101.                         while(nbrp>0)
  102.                         {
  103.                             system("cls");
  104.                             tab[1][1]='X';
  105.                             utijouer();
  106.                             if(intljouer()!=0)
  107.                                 if(casajouer()!=0)
  108.                                     jouerhasar();
  109.                             nbrj=5;
  110.                             while(nbrj<9&&scangan()!=0)
  111.                             {
  112.                                 utijouer();
  113.                                 nbrj++;
  114.                                 if(nbrj<9&&scangan()!=0)
  115.                                 {
  116.                                     if(casajouer()!=0)
  117.                                         jouerhasar();
  118.                                     nbrj++;
  119.                                 }
  120.                             }
  121.                             rmtazero();
  122.                             nbrp--;
  123.                         }
  124.                         break;
  125.                     default:
  126.                         printf("\nT'as choisi le mauvais choix !!!\nRepete la choix.\n");
  127.                         break;
  128.                     }
  129.                 }
  130.                 while(choixm2!=1&&choixm2!=2);
  131.             case 2:
  132.                 while(nbrp>0)
  133.                 {
  134.                     system("cls");
  135.                     while(nbrj<9&&scangan()!=0)
  136.                     {
  137.                         if(qjp%2==0)
  138.                         {
  139.                             if(nbrj<9&&scangan()!=0)
  140.                             {
  141.                                 printf("\nLe role de joueur "" O "" .\n");
  142.                                 utijouer();
  143.                                 nbrj++;
  144.                             }
  145.                         }
  146.                         if(nbrj<9&&scangan()!=0)
  147.                         {
  148.                             printf("\nLe role de joueur "" X "" .\n");
  149.                             utijouer();
  150.                             tab[(posij%10)-1][(posij/10)-1]='X';
  151.                             nbrj++;
  152.                         }
  153.                         qjp=2;
  154.                     }
  155.                     rmtazero();
  156.                     nbrp--;
  157.                     qjp=nbrp;
  158.                 }
  159.                 break;
  160.             default:
  161.                 printf("\nT'as choisi le mauvais choix !!!\nRepete la choix.\n");
  162.                 break;
  163.             }
  164.         }
  165.         while(choixm3!=1&&choixm3!=2);
  166.         system("cls");
  167.         for(i=0; i<3; i++)
  168.         {
  169.             for(j=0; j<3; j++)
  170.             {
  171.                 tab[i][j]=' ';
  172.             }
  173.         }
  174.         afich();
  175.         choixm2=choixm3=0;
  176.         for(i=0; i<2; i++)
  177.         {
  178.             for(j=0; j<pgan; j++)
  179.             {
  180.                 if(tabb[i][j]=='1')
  181.                 {
  182.                     if(i==0)
  183.                         choixm2++;
  184.                     if(i==1)
  185.                         choixm3++;
  186.  
  187.                 }
  188.             }
  189.         }
  190.         if(choixm2>choixm3)
  191.         {
  192.             printf("\n\n***********************************************\n");
  193.             printf("*** Le gagnant au total parties est le ** X ***\n");
  194.             printf("***********************************************\n\n");
  195.         }
  196.         else if(choixm2<choixm3)
  197.         {
  198.             printf("\n\n***********************************************\n");
  199.             printf("*** Le gagnant au total parties est le ** O ***\n");
  200.             printf("***********************************************\n\n");
  201.         }
  202.         else
  203.         {
  204.             printf("\n\n*****************************************************\n");
  205.             printf("*** L'egalite entre les joueurs au total parties. ***\n");
  206.             printf("*****************************************************\n\n");
  207.         }
  208.         system("pause");
  209.         system("cls");
  210.         do
  211.         {
  212.             printf("\nVoulez-vous jouer a nouveau ?\n1 : OUI\n2 : NON\n");
  213.             scanf("%d",&choixm);
  214.             if(choixm!=1&&choixm!=2)
  215.                 printf("\nT'as choisi le mauvais choix !!!\nRepete la choix.\n");
  216.         }
  217.         while(choixm!=1&&choixm!=2);
  218.         system("cls");
  219.     }
  220.     printf("////////////////////////////////////////\n");
  221.     printf("////////////// MouhcineFD //////////////\n");
  222.     printf("//// vous remercions d'avoir choisi ////\n");
  223.     printf("///////////////// X O //////////////////\n");
  224.     printf("////////////////////////////////////////\n");
  225.     pausesc(3);
  226.     return 0;
  227. }
  228. void rmtazero()
  229. {
  230.     afich();
  231.     if(scangan()==0)
  232.     {
  233.         printf("\nLe gagnant dans cette partie est le "" %c "" .\n\n",tab[i][j]);
  234.         if(tab[i][j]=='X')
  235.         {
  236.             tabb[0][pgan-nbrp]='1';
  237.             tabb[1][pgan-nbrp]='0';
  238.         }
  239.         else
  240.         {
  241.             tabb[1][pgan-nbrp]='1';
  242.             tabb[0][pgan-nbrp]='0';
  243.         }
  244.     }
  245.     else
  246.     {
  247.         printf("\nL'egalite entre les joueurs au cette partie.\n\n");
  248.         tabb[1][pgan-nbrp]='0';
  249.         tabb[0][pgan-nbrp]='0';
  250.     }
  251.     system("pause");
  252.     for(i=0; i<3; i++)
  253.     {
  254.         for(j=0; j<3; j++)
  255.         {
  256.             tab[i][j]=' ';
  257.         }
  258.     }
  259.     nbrj=0;
  260. }
  261. void afich()
  262. {
  263.     int v;
  264.     printf("\n     X1  X2  X3\n");
  265.     printf("    ___________              ");
  266.     for(v=0; v<pgan+1; v++)
  267.     {
  268.         printf("____");
  269.     }
  270.     printf("\n");
  271.     for(i=0; i<3; i++)
  272.     {
  273.         printf("Y%d ",i+1);
  274.         for(j=0; j<3; j++)
  275.         {
  276.             printf("| %c ",tab[i][j]);
  277.         }
  278.  
  279.         printf("|");
  280.         printf("             |");
  281.         if(i==0)
  282.         {
  283.             for(v=0; v<pgan+1; v++)
  284.             {
  285.                 if(v==0)
  286.                     printf("   |");
  287.                 else
  288.                 {
  289.                     if(v<10)
  290.                         printf("P%d |",v);
  291.                     else
  292.                         printf("P%d|",v);
  293.                 }
  294.             }
  295.         }
  296.         else
  297.         {
  298.             for(v=0; v<pgan+1; v++)
  299.             {
  300.                 if(v==0&&i==1)
  301.                     printf(" X |");
  302.                 else if(v==0&&i==2)
  303.                     printf(" O |");
  304.                 else
  305.                     printf(" %c |",tabb[i-1][v-1]);
  306.             }
  307.         }
  308.         printf("\n   |___|___|___|             |");
  309.         for(v=0; v<pgan+1; v++)
  310.         {
  311.             printf("___|");
  312.         }
  313.         printf("\n");
  314.     }
  315. }
  316. void jouerhasar()
  317. {
  318.     do
  319.     {
  320.         i=(rand()%(2-0+1))+0;
  321.         j=(rand()%(2-0+1))+0;
  322.     }
  323.     while(tab[i][j]!=' ');
  324.     tab[i][j]='X';
  325. }
  326. int scangan()
  327. {
  328.     for(i=j=0; j<3; j++)
  329.     {
  330.         if(tab[i][j]!=' ')
  331.             if(tab[i][j]==tab[i+1][j]&&tab[i+1][j]==tab[i+2][j])
  332.  
  333.                 return 0;
  334.  
  335.     }
  336.     for(i=j=0; i<3; i++)
  337.     {
  338.         if(tab[i][j]!=' ')
  339.             if(tab[i][j]==tab[i][j+1]&&tab[i][j+1]==tab[i][j+2])
  340.                 return 0;
  341.     }
  342.     if(tab[j+1][j+1]!=' ')
  343.     {
  344.         if(tab[j][j]==tab[j+1][j+1]&&tab[j+1][j+1]==tab[j+2][j+2])
  345.         {
  346.             tab[i][j]=tab[j][j];
  347.             return 0;
  348.         }
  349.         if(tab[j+2][j]==tab[j+1][j+1]&&tab[j+1][j+1]==tab[j][j+2])
  350.         {
  351.             tab[i][j]=tab[j+2][j];
  352.             return 0;
  353.         }
  354.     }
  355. }
  356. int casajouer()
  357. {
  358.     for(i=j=0; j<3; j++)
  359.     {
  360.         if(tab[i][j]==' ')
  361.             if(tab[i+1][j]=='X'&&tab[i+1][j]==tab[i+2][j])
  362.             {
  363.                 tab[i][j]='X';
  364.                 return 0;
  365.             }
  366.         if(tab[i+1][j]==' ')
  367.             if(tab[i][j]=='X'&&tab[i][j]==tab[i+2][j])
  368.             {
  369.                 tab[i+1][j]='X';
  370.                 return 0;
  371.             }
  372.         if(tab[i+2][j]==' ')
  373.             if(tab[i][j]=='X'&&tab[i][j]==tab[i+1][j])
  374.             {
  375.                 tab[i+2][j]='X';
  376.                 return 0;
  377.             }
  378.     }
  379.     for(i=j=0; i<3; i++)
  380.     {
  381.         if(tab[i][j]==' ')
  382.             if(tab[i][j+1]=='X'&&tab[i][j+1]==tab[i][j+2])
  383.             {
  384.                 tab[i][j]='X';
  385.                 return 0;
  386.             }
  387.         if(tab[i][j+1]==' ')
  388.             if(tab[i][j]=='X'&&tab[i][j]==tab[i][j+2])
  389.             {
  390.                 tab[i][j+1]='X';
  391.                 return 0;
  392.             }
  393.         if(tab[i][j+2]==' ')
  394.             if(tab[i][j]=='X'&&tab[i][j]==tab[i][j+1])
  395.             {
  396.                 tab[i][j+2]='X';
  397.                 return 0;
  398.             }
  399.     }
  400.     i=j=0;
  401.     if(tab[i][j]==' ')
  402.         if(tab[i+1][j+1]=='X'&&tab[i+1][j+1]==tab[i+2][j+2])
  403.         {
  404.             tab[i][j]='X';
  405.             return 0;
  406.         }
  407.     if(tab[i+1][j+1]==' ')
  408.         if(tab[i][j]=='X'&&tab[i][j]==tab[i+2][j+2])
  409.         {
  410.             tab[i+1][j+1]='X';
  411.             return 0;
  412.         }
  413.     if(tab[i+2][j+2]==' ')
  414.         if(tab[i][j]=='X'&&tab[i][j]==tab[i+1][j+1])
  415.         {
  416.             tab[i+2][j+2]='X';
  417.             return 0;
  418.         }
  419.     if(tab[i][j+2]==' ')
  420.         if(tab[i+1][j+1]=='X'&&tab[i+1][j+1]==tab[i+2][j])
  421.         {
  422.             tab[i][j+2]='X';
  423.             return 0;
  424.         }
  425.     if(tab[i+1][j+1]==' ')
  426.         if(tab[i][j+2]=='X'&&tab[i][j]==tab[i+2][j])
  427.         {
  428.             tab[i+1][j+1]='X';
  429.             return 0;
  430.         }
  431.     if(tab[i+2][j]==' ')
  432.         if(tab[i][j+2]=='X'&&tab[i][j+2]==tab[i+1][j+1])
  433.         {
  434.             tab[i+2][j]='X';
  435.             return 0;
  436.         }
  437.     for(i=j=0; j<3; j++)
  438.     {
  439.         if(tab[i][j]==' ')
  440.             if(tab[i+1][j]=='O'&&tab[i+1][j]==tab[i+2][j])
  441.             {
  442.                 tab[i][j]='X';
  443.                 return 0;
  444.             }
  445.         if(tab[i+1][j]==' ')
  446.             if(tab[i][j]=='O'&&tab[i][j]==tab[i+2][j])
  447.             {
  448.                 tab[i+1][j]='X';
  449.                 return 0;
  450.             }
  451.         if(tab[i+2][j]==' ')
  452.             if(tab[i][j]=='O'&&tab[i][j]==tab[i+1][j])
  453.             {
  454.                 tab[i+2][j]='X';
  455.                 return 0;
  456.             }
  457.     }
  458.     for(i=j=0; i<3; i++)
  459.     {
  460.         if(tab[i][j]==' ')
  461.             if(tab[i][j+1]=='O'&&tab[i][j+1]==tab[i][j+2])
  462.             {
  463.                 tab[i][j]='X';
  464.                 return 0;
  465.             }
  466.         if(tab[i][j+1]==' ')
  467.             if(tab[i][j]=='O'&&tab[i][j]==tab[i][j+2])
  468.             {
  469.                 tab[i][j+1]='X';
  470.                 return 0;
  471.             }
  472.         if(tab[i][j+2]==' ')
  473.             if(tab[i][j]=='O'&&tab[i][j]==tab[i][j+1])
  474.             {
  475.                 tab[i][j+2]='X';
  476.                 return 0;
  477.             }
  478.     }
  479.     i=j=0;
  480.     if(tab[i][j]==' ')
  481.         if(tab[i+1][j+1]=='O'&&tab[i+1][j+1]==tab[i+2][j+2])
  482.         {
  483.             tab[i][j]='X';
  484.             return 0;
  485.         }
  486.     if(tab[i+1][j+1]==' ')
  487.         if(tab[i][j]=='O'&&tab[i][j]==tab[i+2][j+2])
  488.         {
  489.             tab[i+1][j+1]='X';
  490.             return 0;
  491.         }
  492.     if(tab[i+2][j+2]==' ')
  493.         if(tab[i][j]=='O'&&tab[i][j]==tab[i+1][j+1])
  494.         {
  495.             tab[i+2][j+2]='X';
  496.             return 0;
  497.         }
  498.     if(tab[i][j+2]==' ')
  499.         if(tab[i+1][j+1]=='O'&&tab[i+1][j+1]==tab[i+2][j])
  500.         {
  501.             tab[i][j+2]='X';
  502.             return 0;
  503.         }
  504.     if(tab[i+1][j+1]==' ')
  505.         if(tab[i][j+2]=='O'&&tab[i][j]==tab[i+2][j])
  506.         {
  507.             tab[i+1][j+1]='X';
  508.             return 0;
  509.         }
  510.     if(tab[i+2][j]==' ')
  511.         if(tab[i][j+2]=='O'&&tab[i][j+2]==tab[i+1][j+1])
  512.         {
  513.             tab[i+2][j]='X';
  514.             return 0;
  515.         }
  516. }
  517. void utijouer()
  518. {
  519.     afich();
  520.     do
  521.     {
  522.         printf("\nEntrez les coordonnees de la case a jouer sur la forme XY : ");
  523.         scanf("%d",&posij);
  524.         if(tab[(posij%10)-1][(posij/10)-1]==' ')
  525.             tab[(posij%10)-1][(posij/10)-1]='O';
  526.         else
  527.         {
  528.             printf("\nT'as choisi le mauvais case !!!\nRepete la choix.\n");
  529.             posij=0;
  530.         }
  531.     }
  532.     while(posij==0);
  533.     system("cls");
  534. }
  535. int intljouer()
  536. {
  537.     if(tab[0][0]=='O')
  538.     {
  539.         tab[2][2]='X';
  540.         utijouer();
  541.         if(tab[2][1]=='O')
  542.         {
  543.             tab[1][2]='X';
  544.             return 0;
  545.         }
  546.         else if(tab[1][2]=='O')
  547.         {
  548.             tab[2][1]='X';
  549.             return 0;
  550.         }
  551.     }
  552.     else if(tab[2][2]=='O')
  553.     {
  554.         tab[0][0]='X';
  555.         utijouer();
  556.         if(tab[1][0]=='O')
  557.         {
  558.             tab[0][1]='X';
  559.             return 0;
  560.         }
  561.         else if(tab[0][1]=='O')
  562.         {
  563.             tab[1][0]='X';
  564.             return 0;
  565.         }
  566.     }
  567.     else if(tab[2][0]=='O')
  568.     {
  569.         tab[0][2]='X';
  570.         utijouer();
  571.         if(tab[1][2]=='O')
  572.         {
  573.             tab[0][1]='X';
  574.             return 0;
  575.         }
  576.         else if(tab[0][1]=='O')
  577.         {
  578.             tab[1][2]='X';
  579.             return 0;
  580.         }
  581.     }
  582.     else if(tab[0][2]=='O')
  583.     {
  584.         tab[2][0]='X';
  585.         utijouer();
  586.         if(tab[1][0]=='O')
  587.         {
  588.             tab[2][1]='X';
  589.             return 0;
  590.         }
  591.         else if(tab[2][1]=='O')
  592.         {
  593.             tab[1][0]='X';
  594.             return 0;
  595.         }
  596.     }
  597.     else if(tab[1][0]=='O')
  598.     {
  599.         tab[1][2]='X';
  600.         utijouer();
  601.  
  602.         if(tab[2][1]=='O')
  603.         {
  604.             tab[2][2]='X';
  605.             return 0;
  606.         }
  607.         else if(tab[0][1]=='O')
  608.         {
  609.             tab[0][2]='X';
  610.             return 0;
  611.         }
  612.     }
  613.     else if(tab[1][2]=='O')
  614.     {
  615.         tab[1][0]='X';
  616.         utijouer();
  617.         if(tab[0][1]=='O')
  618.         {
  619.             tab[0][0]='X';
  620.             return 0;
  621.         }
  622.         else if(tab[2][1]=='O')
  623.         {
  624.             tab[2][0]='X';
  625.             return 0;
  626.         }
  627.     }
  628.     else if(tab[2][1]=='O')
  629.     {
  630.         tab[0][1]='X';
  631.         utijouer();
  632.         if(tab[1][0]=='O')
  633.         {
  634.             tab[0][0]='X';
  635.             return 0;
  636.         }
  637.         else if(tab[1][2]=='O')
  638.         {
  639.             tab[0][2]='X';
  640.             return 0;
  641.         }
  642.     }
  643.     else if(tab[0][1]=='O')
  644.     {
  645.         tab[2][1]='X';
  646.         utijouer();
  647.         if(tab[1][0]=='O')
  648.         {
  649.             tab[2][0]='X';
  650.             return 0;
  651.         }
  652.         else if(tab[1][2]=='O')
  653.         {
  654.             tab[2][2]='X';
  655.             return 0;
  656.         }
  657.     }
  658. }
Advertisement
Add Comment
Please, Sign In to add comment