Programlama | Programlama Dilleri | C Programlama Dili |C++

Anasayfa Programlama C / C++ Basit Bir XOX Oyunu


Basit Bir XOX Oyunu

AÇIKLAMA

FONKS?YONLARLA DERLENM?? BAS?T B?R XOX OYUNU UMARIM AÇIKLAYICI OLMU?TUR 

  1. #include<stdio.h>
  2.  
  3. int a,b;
  4. void tema();
  5. void yer();
  6. int game[4][4]={{0}};
  7. char oyuncu;
  8. void tablociz();
  9. void kimkazandi();
  10. int kazandi = 0;
  11.  
  12. //--------------------------------------------------------------------------
  13. void tema()
  14. {
  15.         printf("\n\n *****   X-O-X GAME    *****\n\n");
  16.         printf("\n       X-O-X Tablo\n ________________\n");
  17.         for(a=1;a<4;a++){
  18.         for(b=1;b<4;b++){
  19.         if(game[a][b]==0) printf("  .  ");}
  20.         printf("\n\n");}
  21. }
  22.  
  23. //-----------------------------------------------------------------------------
  24.  
  25. void yer()
  26. {
  27.  
  28.     int konum,satir=0,sutun=0;
  29.  
  30.     while(1){
  31.  
  32.         printf("%c oyuncun karekteri nereye yerlestirsin (1-9):\n",oyuncu);
  33.         scanf("%d",&konum);
  34.  
  35.         if(konum<1 || konum>9)
  36.         {
  37.                printf("\nlutfen (1-9) araliginda secim yapiniz\n\n");
  38.                continue;
  39.         }
  40.  
  41.         if(konum<4)
  42.         {
  43.             satir=1;
  44.             sutun=konum;
  45.         }
  46.         else if(konum<7)
  47.         {
  48.             satir=2;
  49.             sutun=konum-3;
  50.         }
  51.         else
  52.         {
  53.             satir=3;
  54.             sutun=konum-6;
  55.         }
  56.  
  57.         if(game[satir][sutun]!=0)
  58.         {
  59.             printf("\n baska konum seciniz \n");
  60.             continue;
  61.         }
  62.  
  63.         if(oyuncu == 'X')
  64.         {
  65.             game[satir][sutun] = 1;
  66.             oyuncu = 'O';
  67.             break;
  68.         }
  69.         else if(oyuncu == 'O')
  70.         {
  71.             game[satir][sutun] = 2;
  72.             oyuncu = 'X';
  73.             break;
  74.         }
  75.     }
  76.     return;
  77. }
  78.  
  79. //-------------------------------------------------------------------------------------------------------
  80. void tablociz()
  81. {
  82.     system("cls");
  83.     printf("\n\n *****   X-O-X GAME    *****\n\n");
  84.     printf("\n   X-O-X table \n  ------------\n");
  85.  
  86.           for(a=1;a<4;a++)
  87.       {
  88.           for(b=1;b<4;b++)
  89.           {
  90.               if(game[a][b]==0)printf("  .  ");
  91.               else if(game[a][b]==1)printf("  X  ");
  92.               else printf("  O  ");
  93.           }
  94.           printf("\n\n");
  95.      }
  96. }
  97. //--------------------------------------------------------------------------------------------------------------
  98. void kimkazandi()
  99. {
  100.     if(game[1][1] == game[1][2] && game[1][2] == game[1][3])
  101.         kazandi = game[1][1];
  102.  
  103.     if(game[2][1] == game[2][2] && game[2][2] == game[2][3])
  104.         kazandi = game[2][1];
  105.  
  106.     if(game[3][1] == game[3][2] && game[3][2] == game[3][3])
  107.         kazandi = game[3][1];
  108.  
  109.     if(game[1][1] == game[2][1] && game[2][1] == game[3][1])
  110.         kazandi = game[1][1] ;
  111.  
  112.     if(game[1][2] == game[2][2] && game[2][2] == game[3][2])
  113.         kazandi = game[1][2] ;
  114.  
  115.     if(game[1][3] == game[2][3] && game[2][3] == game[3][3])
  116.         kazandi = game[1][3] ;
  117.  
  118.     if(game[1][1] == game[2][2] && game[2][2] == game[3][3])
  119.         kazandi = game[1][1];
  120.  
  121.     if(game[1][3] == game[2][2] && game[2][2] == game[3][1])
  122.         kazandi = game[1][3];
  123.  
  124. }
  125. //----------------------------------------------------------------------------------------------------------------
  126.  
  127. int main()
  128. {
  129.     int saygac = 0;
  130.  
  131.     tema();
  132.  
  133.     printf("ilk hangi karekter baslasin ( X OR  O ): \n");
  134.  
  135.     scanf("%c",&oyuncu);
  136.  
  137.     while(1){
  138.         yer();
  139.         tablociz();
  140.         kimkazandi();
  141.  
  142.         if(kazandi == 1)
  143.         {
  144.             printf("kazanan X\n");
  145.             break;
  146.         }
  147.  
  148.         if (kazandi == 2)
  149.         {
  150.             printf("kazanan O\n");
  151.             break;
  152.         }
  153.  
  154.  
  155.         saygac++;
  156.  
  157.         if(saygac == 9)
  158.         {
  159.            printf("YER DOLDU BERABERE\n");
  160.            break;
  161.         }
  162.  
  163.     }
  164.  
  165. return 0;
  166. }

Yorumlar (0)
Sadece kayıtlı kullanıcılar yorum yazabilir!
Son Güncelleme ( Çarşamba, 10 Temmuz 2013 01:07 )  
backlinktr.biz | 523: Origin is unreachable

Error 523 Ray ID: 53553b6b4a40d413 • 2019-11-14 01:32:34 UTC

Origin is unreachable

You

Browser

Working
Budapest

Cloudflare

Working
backlinktr.biz

Host

Error

What happened?

The origin web server is not reachable.

What can I do?

If you're a visitor of this website:

Please try again in a few minutes.

If you're the owner of this website:

Check your DNS Settings. A 523 error means that Cloudflare could not reach your host web server. The most common cause is that your DNS settings are incorrect. Please contact your hosting provider to confirm your origin IP and then make sure the correct IP is listed for your A record in your Cloudflare DNS Settings page. Additional troubleshooting information here.