Görsel etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

C ile Amiral Battı

C ile amiral battı oyunu. Hocamızın örnek oyunuydu umarım kodları anlayabilirsiniz..





C ile yılan oyunu


Hocamızın verdiği görsel ödevini sınıftan bir arkadaşımız snake ile yapmıştı. Karışık ve yorucu umarım anlayabilirsiniz.

Source Code

#include<graphics.h>
#include<conio.h>
#include<time.h>
#include<stdio.h>
#include <limits.h>
#include <stdlib.h>
   int check = 3,mouse = 0,score = 8;
void checker(int randx,int randy,int x,int y)
{
        int temp1 = randx-x;
        int temp2 = randy-y;
            if(temp1 < 0)
                temp1 *= -1;
            if(temp2 < 0)
                temp2 *= -1;
        if(temp1 <= 8 && temp2 <= 8)
        {
            mouse = 0;
            score++;
        }
}
void dead(int x,int y)
{
            if(x <= 5 || x+10 >= 635 || y <= 5 || y+10 >= 475)
        {
            outtextxy(10,10,"OYUN BITTI");
            Sleep(3000);
            return;
        }
}
int main()
{
   int gd = DETECT, gm;
   int x = 6,y = 6,i = 0,j,temp1,temp2,kontrol=1;
   int randx=10,randy=10;
   int sayac = 0,busy = 0;
   initgraph(&gd, &gm, "");
   while(1)
   {
        if(mouse == 0)
        {
            srand(time(NULL));
            randx = rand() % 630 +5;
            randy = rand() % 470 +5;
            mouse = 1;
        }

    setcolor(WHITE);
    rectangle(randx,randy,randx+7,randy+7);
    setcolor(RED);
        for(i = 0;i <= 5;i++)
            rectangle(0+i,0+i,640-i,480-i);
    setcolor(YELLOW);
        i =0;
            if(check == 0)
            {

                if(kontrol ==3)
                {
                    busy = 1;
                    for(i=score-sayac-1;i>=0;i--)
                        rectangle(x-(i*10),y,x+10-(i*10),y+10);
                    for(j=sayac;j>=0;j--)
                    {
                        rectangle(x,y-(j*10),x+10,y+10-(j*10));
                        checker(randx,randy,x,y-(j*10));
                        dead(x,y-(j*10));

                    }

                    Sleep(250);
                    sayac++;
                    if(sayac == score)
                    {
                       y -= (score-1)*10;
                       kontrol = 0;
                       sayac = 0;
                    }
                }

                else if(kontrol == 2)
                {
                    busy = 1;
                    for(i=score-sayac-1;i>=0;i--)
                        rectangle(x+(i*10),y,x+10+(i*10),y+10);
                    for(j=sayac;j>=0;j--)
                    {
                        rectangle(x,y-(j*10),x+10,y+10-(j*10));
                        checker(randx,randy,x,y-(j*10));
                        dead(x,y-(j*10));
                    }

                    Sleep(250);
                    sayac++;
                    if(sayac == score)
                    {
                       y -= (score-1)*10;
                       kontrol = 0;
                       sayac = 0;
                    }
                }
                else if(kontrol == 1)
                {
                    check = 1;
                    kontrol = 1;
                    continue;
                }
                else
                {
                   y-=10;
                   for(i=0;i<score;i++)
                   rectangle(x,y+(i*10),x+10,y+10+(i*10));
                   Sleep(250);
                   kontrol = 0;
                   busy = 0;
                }
            }
            else if(check == 1)
            {
                if(kontrol ==3)
                {
                busy = 1;
                    for(i=score-sayac-1;i>=0;i--)
                        rectangle(x-(i*10),y,x+10-(i*10),y+10);
                    for(j=sayac;j>=0;j--)
                    {
                        rectangle(x,y+(j*10),x+10,y+10+(j*10));
                        checker(randx,randy,x,y+(j*10));
                        dead(x,y+(j*10));
                    }

                    Sleep(250);
                    sayac++;
                    if(sayac == score)
                    {
                       y += (score-1)*10;
                       kontrol = 1;
                       sayac = 0;
                    }
                }
                else if(kontrol == 2)
                {
                busy = 1;
                    for(i=score-sayac-1;i>=0;i--)
                        rectangle(x+(i*10),y,x+10+(i*10),y+10);
                    for(j=sayac;j>=0;j--)
                    {
                        rectangle(x,y+(j*10),x+10,y+10+(j*10));
                        checker(randx,randy,x,y+(j*10));
                        dead(x,y+(j*10));
                    }

                    Sleep(250);
                    sayac++;
                    if(sayac == score)
                    {
                       y += (score-1)*10;
                       kontrol = 1;
                       sayac = 0;
                    }
                }
                else if(kontrol == 0)
                {
                    check = 0;
                    kontrol = 0;
                    continue;
                }
                else
                {
                    y+=10;
                       for(i=0;i<score;i++)
                       rectangle(x,y-(i*10),x+10,y+10-(i*10));
                   Sleep(250);
                   kontrol = 1;
                   busy = 0;
                }
            }
            else if(check == 2)
            {
                if(kontrol ==1)
                {
                    busy = 1;
                    for(i=score-sayac-1;i>=0;i--)
                        rectangle(x,y-(i*10),x+10,y+10-(i*10));
                    for(j=sayac;j>=0;j--)
                    {
                        rectangle(x-(j*10),y,x+10-(j*10),y+10);
                        checker(randx,randy,x-(j*10),y);
                        dead(x-(j*10),y);
                    }

                    Sleep(250);
                    sayac++;
                    if(sayac == score)
                    {
                       x -= (score-1)*10;
                       kontrol = 2;
                       sayac = 0;
                    }
                }
                else if(kontrol == 0)
                {
                    busy = 1;
                    for(i=score-sayac-1;i>=0;i--)
                        rectangle(x,y+(i*10),x+10,y+10+(i*10));
                    for(j=sayac;j>=0;j--)
                    {
                        rectangle(x-(j*10),y,x+10-(j*10),y+10);
                        checker(randx,randy,x-(j*10),y);
                        dead(x-(j*10),y);
                    }
                    Sleep(250);
                    sayac++;
                    if(sayac == score)
                    {
                       x -= (score-1)*10;
                       kontrol = 2;
                       sayac = 0;
                    }
                }
                else if(kontrol == 3)
                {
                    check = 3;
                    kontrol = 3;
                    continue;
                }
                else
                {
                   x-=10;
                   for(i=0;i<score;i++)
                   rectangle(x+(i*10),y,x+10+(i*10),y+10);
                   Sleep(250);
                   kontrol = 2;
                   busy = 0;
                }
            }
            else if(check == 3)
            {
                if(kontrol ==1)
                {
                    busy = 1;
                    for(i=score-sayac-1;i>=0;i--)
                        rectangle(x,y-(i*10),x+10,y+10-(i*10));
                    for(j=sayac;j>=0;j--)
                    {
                        rectangle(x+(j*10),y,x+10+(j*10),y+10);
                        checker(randx,randy,x+(j*10),y);
                        dead(x+(j*10),y);
                    }

                    Sleep(250);
                    sayac++;
                    if(sayac == score)
                    {
                       x += (score-1)*10;
                       kontrol = 3;
                       sayac = 0;
                    }
                }
                else if(kontrol == 0)
                {
                    busy = 1;
                    for(i=score-sayac-1;i>=0;i--)
                        rectangle(x,y+(i*10),x+10,y+10+(i*10));
                    for(j=sayac;j>=0;j--)
                    {
                        rectangle(x+(j*10),y,x+10+(j*10),y+10);
                        checker(randx,randy,x+(j*10),y);
                        dead(x+(j*10),y);
                    }

                    Sleep(250);
                    sayac++;
                    if(sayac == score)
                    {
                       x += (score-1)*10;
                       kontrol = 3;
                       sayac = 0;
                    }
                }
                else if(kontrol == 2)
                {
                    check = 2;
                    kontrol = 2;
                    continue;
                }

                else
                {
                      x+=10;
                      for(i=0;i<score;i++)
                      rectangle(x-(i*10),y,x+10-(i*10),y+10);
                      Sleep(250);
                      kontrol = 3;
                      busy = 0;
                }
            }

    dead(x,y);

        if (!kbhit())
            x = x;
        else if(busy == 0)
        {
            if ( GetAsyncKeyState ( VK_UP ) & SHRT_MAX )
              check = 0;
            else if ( GetAsyncKeyState ( VK_DOWN ) & SHRT_MAX )
              check = 1;
            else if ( GetAsyncKeyState ( VK_LEFT ) & SHRT_MAX )
              check = 2;
            else if ( GetAsyncKeyState ( VK_RIGHT ) & SHRT_MAX )
              check = 3;
        }

    checker(randx,randy,x,y);
    delay(5);
    cleardevice();
   }
   closegraph();
   return 0;
}


C ile görsel hesap makinesi

C ile görsel hesap makinesi. Ara yüzü aşağıdaki gibidir.




Source Code

#include<stdio.h>
#include<windows.h>
int secim;
void rengim(int renk)
{
 HANDLE hStdout;
 hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
 SetConsoleTextAttribute(hStdout, renk);
}
int topla(int sayi1 ,int sayi2)
{
 return (sayi1+sayi2);
}
int cikar(int sayi1 ,int sayi2)
{
 return (sayi1-sayi2);
}
int carp(int sayi1 ,int sayi2)
{
 return (sayi1*sayi2);
}
int bol(int sayi1 ,int sayi2)
{
 if(sayi2!=0)
 return (sayi1/sayi2);
}
void gotoxy(short x, short y)
{
 HANDLE hConsoleOutput;
 COORD Cursor_Pos={x-1,y-1};
 hConsoleOutput=GetStdHandle(STD_OUTPUT_HANDLE);
 SetConsoleCursorPosition(hConsoleOutput,Cursor_Pos);
}
void cerceve(int x1,int x2,int y1,int y2)
{
 int i,j;
 for(i=x1;i<=x2;i++)
 {
 gotoxy(i,y1);printf("%c",196);
 gotoxy(i,y2);printf("%c",196);
 }
 for(j=y1;j<=y2;j++)
 {
 gotoxy(x1,j);printf("%c",179);
 gotoxy(x2,j);printf("%c",179);
 }
 gotoxy(x1,y1);printf("%c",218);
 gotoxy(x2,y1);printf("%c",191);
 gotoxy(x2,y2);printf("%c",217);
 gotoxy(x1,y2);printf("%c",192);
}
void baslangic()
{
 int i,j;
 gotoxy(20,14);printf("HESAP MAKINASI YUKLENIYOR");
 for(j=15;j<=50;j++)
 {
 gotoxy(j,16);printf("%c",196);
 gotoxy(j,18);printf("%c",196);
 }
 for(i=15;i<=50;i++)
 {
 rengim(4);
 gotoxy(i,17);printf("%c",177);
 Sleep(100);
 rengim(7);
 }
}
void menu()
{
 system("cls");
 cerceve(1,15,1,15);
 rengim(4);
 gotoxy(2,2);printf("ISLEMLER\n");
 gotoxy(2,3);printf("--------");
 rengim(5);
 gotoxy(2,4);printf("1-TOPLAMA");
 rengim(6);
 gotoxy(2,6);printf("2-CIKARMA");
 rengim(3);
 gotoxy(2,8);printf("3-CARPMA");
 rengim(8);
 gotoxy(2,10);printf("4-BOLME");
 rengim(7);
 gotoxy(2,12);printf("Seciminiz:");
 scanf("%d",&secim);
}
main()
{
 int say1,say2;
 baslangic();
 Sleep(300);
 menu();
 cerceve(25,60,1,20);
 gotoxy(30,2);printf("1.sayiyi gir: ");scanf("%d",&say1);
 gotoxy(30,3);printf("2.sayiyi gir: ");scanf("%d",&say2);
 switch(secim)
 {
 case 1:
 {
 rengim(5);
 gotoxy(35,6);printf("%d",say1);
 gotoxy(35,8);printf("%d",say2);
 gotoxy(30,9);printf("+");
 gotoxy(30,10);printf("---------");
 gotoxy(35,11);printf("%d",topla(say1,say2));
 break;
 }
 case 2:
 {
 rengim(6);
 gotoxy(35,6);printf("%d",say1);
 gotoxy(35,8);printf("%d",say2);
 gotoxy(30,9);printf("-");
 gotoxy(30,10);printf("---------");
 gotoxy(35,11);printf("%d",cikar(say1,say2));
 break;
}
 case 3:
 rengim(7);
 {
 gotoxy(35,6);printf("%d",say1);
 gotoxy(35,8);printf("%d",say2);
 gotoxy(30,9);printf("x");
 gotoxy(30,10);printf("---------");
 gotoxy(35,11);printf("%d",carp(say1,say2));
 break;
 }
 case 4:
 {
 rengim(8);
 gotoxy(35,6);printf("%d",say1);
 gotoxy(34,7);printf("----");
 gotoxy(35,8);printf("%d",say2);
 gotoxy(30,9);printf("=");
 gotoxy(30,10);printf("---------");
 gotoxy(35,11);printf("%d",bol(say1,say2));
 break;
 }
 default:
 {
 printf("yanlis secim");
 }
 }
 gotoxy(1,24);
getchar();
getchar();
}