Source Code Game Cacat

Follow Us to Update News :

/* This is source code of my game, game cacat */
/* By Ahmad Jakfar, 2009*/

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>

int start();
int bonus();
int count();
int bmb();
int enemy();
int menu();
int pac();
int coor();
int move();  /* Variable declaration */
    char pnt='O';long sc=0,sc2=0,jml=0,e[100][2],life=3;
    int  arah[4]={0},way[100][100]={0},x=0,y=0,p=0,diff=0,df=1; 

    int wy[10000]={
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,0,0,
0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,0,1,1,
1,1,1,1,1,1,0,1,0,0,0,0,0,1,1,1,0,1,0,1,1,1,0,1,0,1,0,1,0,1,0,1,0,0,
1,0,1,1,1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,
1,0,1,0,1,0,1,0,1,0,1,0,1,1,1,1,0,1,0,0,0,1,0,1,0,1,1,0,1,1,1,1,1,1,
1,0,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,1,0,
1,0,1,0,1,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,1,1,0,
1,0,1,1,1,1,1,0,1,1,1,1,0,1,0,1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,
1,0,1,1,1,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,1,0,1,0,1,0,
1,0,1, 1,0,0,0,0,0,0,0,0,1,0,1,1,0,1,0,0,1,0,1,0,1,0,1,1,1,0,1,0,1,1,
1,0,1,1,0,0,1,1,0,1,0,1,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,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,
1,0,1,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                 };

int main()
{   arah[1]=arah[0]=17;
    menu();   
    coor();  
    pac();      
    count();
    system("cls");    
    start();
    return 0;
}
       
int move()   /* Moving the object */
{   switch(getch())
    {
    case 'w' : if(way[arah[0]][arah[1]-1]!=1){arah[1]--;} pnt=30; break;
    case 's' : if(way[arah[0]][arah[1]+1]!=1){arah[1]++;} pnt=31; break;
    case 'a' : if(way[arah[0]-1][arah[1]]!=1){arah[0]--;} pnt=17; break;
    case 'd' : if(way[arah[0]+1][arah[1]]!=1){arah[0]++;} pnt=16; break;
    } system("cls");
}

int coor()
{   int w=0;  /* Coordinating to x and y */
    srand( (unsigned)time( NULL ) );
    for(int i=1;i<df;i++)
    {   e[i][0]=(rand()+i*2)%46+1;
        e[i][1]=(rand()+i)%17+1;
    }              
    for(int y=0;y<20;y++){
            for(int x=0;x<49;x++){
                    way[x][y]=wy[w];w++;
}}}

int start()
{   int langkah=-1,X=75,Y=20;
    /* Display to monitor */
    while(jml>sc)
    {  printf("RC 1.6\t---- Created by Ahmad Jakfar ---");
       printf("%8d",diff);
       for(int y=0;y<Y;y++){printf("\n");
            for(int x=0;x<X;x++){
                    for(int i=1;i<df;i++){
                        if(arah[1]==e[i][1]&&arah[0]==e[i][0]||
                        arah[1]-1==e[i][1]&&arah[0]==e[i][0]||
                        arah[1]+1==e[i][1]&&arah[0]==e[i][0]||
                        arah[1]==e[i][1]&&arah[0]-1==e[i][0]||
                        arah[1]==e[i][1]&&arah[0]+1==e[i][0]                     
                        ){e[i][1]=e[i][0]=1;life--;
                    }}
                    if(y==arah[1]&&x==arah[0])
                      {    printf("%c",pnt);
                           if(way[x][y]==2){sc++;way[x][y]=0;}
                           if(way[x][y]==4){sc2+=3+sc2/2;way[x][y]=0;}
                           if(way[x][y]==3||diff>500){ life--;way[x][y]=0; }
                      }                  
                    else if(x==0&&y==0){printf("%c",177);}
                    else if(y==e[1][1]&&x==e[1][0]||y==e[2][1]&&x==e[2][0] //2
                          ||y==e[3][1]&&x==e[3][0]||y==e[4][1]&&x==e[4][0]
                          ||y==e[5][1]&&x==e[5][0]||y==e[6][1]&&x==e[6][0]
                          ||y==e[7][1]&&x==e[7][0]||y==e[8][1]&&x==e[8][0]
                          ||y==e[9][1]&&x==e[9][0]||y==e[10][1]&&x==e[10][0]
                          ||y==e[11][1]&&x==e[11][0]||y==e[12][1]&&x==e[12][0]
                          ||y==e[13][1]&&x==e[13][0]||y==e[14][1]&&x==e[14][0]
                          ||y==e[15][1]&&x==e[15][0]||y==e[16][1]&&x==e[16][0]
                          ||y==e[17][1]&&x==e[17][0]||y==e[18][1]&&x==e[18][0]
                          ||y==e[19][1]&&x==e[19][0]||y==e[20][1]&&x==e[20][0]
                          ) {printf("%c",1);}
                    else if(way[x][y]==4){printf("$");}                                           
                    else if(way[x][y]==3){printf("%c",15);}
                    else if(way[x][y]==1){printf("%c",177);} 
                    else if(way[x][y]==2)
                         {  printf(".");
                            if(way[arah[0]][arah[1]]==2)
                               {sc++;way[arah[0]][arah[1]]=0;}
                         }                                  
                    else{printf(" ");}
            }
       }langkah++; if(jml==sc){break;}
       if(life<=0){  system("cls");printf("\n\n\tYou Lose !!\n\n\n\t");
                     system("pause");return 0;  }       
       printf("\n Coordinate ( x , y ) = ( %d , %d )",arah[0],arah[1]);
       printf("\t");for(int i=0;i<life;i++){printf("%c",3);}
       printf("\n %d/%d - Score %d\n Steps : %d\t",sc,jml,sc+sc2,langkah);
       move(); enemy(); bonus(); bmb();
    } /* Finish */                          
    system("cls"); printf("\n\n\t\tYou win !!!\n\n\n\t");
    printf("\n\n\tYour Score : %d \n\n\n\t",sc*10/langkah+sc+sc2);
    printf("Get More Games At www.ajrlive.co.cc\n\n\n\n\t");system("pause");
}

int bonus(){   int random[10];
    srand( (unsigned)time( NULL ) );
    random[0]=rand()%7; random[3]=0;
    random[1]=rand()%19;
    random[2]=rand()%48;
    for(int y=0;y<20;y++){
            for(int x=0;x<49;x++){if(way[x][y]==4){ random[3]++; }}}
    if(random[0]==1&&way[random[2]][random[1]]==0&&random[3]<3)
       {way[random[2]][random[1]]=4;}
}

int pac(){  int random[10];int a=0;int b=0;int c=1;
while(a<p){printf("\n\n\tPlease Wait");for(int i=0;i<b;i++){printf(" .");}
    printf("\n\n\n\n\n\t\t%d of %d",a,p);b++;if(b%7==0){b=1;}
    printf(" => %d %% Complete",(a*100/p));printf("\n\n\n\n\n\n");
    printf("\n\n\n\n\tNow Loading...");
    printf("\n\n\t---------------------------------------\n\t");
    for(int i=0;i<a*40/p;i++){printf(">");}printf("\n");
    printf("\t---------------------------------------\n");   
    srand( (unsigned)time( NULL ) );
    random[1]=(rand()-a)%17;
    random[2]=(rand()*a+a)%48;
    if(p==1){way[15][17]=2;break;}
    if(way[random[2]][random[1]]==0){way[random[2]][random[1]]=2;a++;}
    else if(way[random[2]+1][random[1]]==0){way[random[2]+1][random[1]]=2;a++;}
    else if(way[random[2]][random[1]+1]==0){way[random[2]][random[1]+1]=2;a++;}
    else if(way[random[2]][random[1]-1]==0){way[random[2]][random[1]-1]=2;a++;}
    system("cls");
}}

int count(){
    int w=0;               
    for(int y=0;y<20;y++){
            for(int x=0;x<49;x++){
                    if(way[x][y]==2){jml++;}
}}}

int menu(){
    printf("\n\n\tInput : ");
    scanf("%d",&p);
    printf("\n\n\tDifficulity : ");
    scanf("%d",&diff);df=diff+1;system("cls");   
}

int bmb(){int random[10];
    srand( (unsigned)time( NULL ) );
    random[3]=0;
    random[1]=rand()%16;
    random[2]=rand()%47;
    for(int y=0;y<20;y++)
    { for(int x=0;x<49;x++){if(way[x][y]==3){random[3]++;} }}
  if(random[3]<(diff*2))
{   if(way[random[2]][random[1]]==0&&random[3]<2)
       {way[random[2]][random[1]]=3;}
    if(diff>2&&way[random[2]-1][random[1]]==0)
       {way[random[2]-1][random[1]]=3;}
    else if(diff>3&&way[random[2]+1][random[1]]==0)
            {way[random[2]+1][random[1]]=3;}
    else if(diff>4&&way[random[2]][random[1]-1]==0)
            {way[random[2]][random[1]-1]=3;}
    else if(diff>5&&way[random[2]][random[1]+1]==0)
            {way[random[2]][random[1]+1]=3;}
    else if(diff>7&&way[random[2]][random[1]+2]==0)
            {way[random[2]+2][random[1]+1]=3;}
    else if(diff>9&&way[random[2]][random[1]-2]==0)
            {way[random[2]-2][random[1]+1]=3;}
}}

int enemy(){
 for(int i=1;i<df;i++){ int a;
    srand( (unsigned)time( NULL ) );
    a=(rand()+i)%4;   
    switch(a) {
    case 0 : if(way[e[i][0]][e[i][1]-1]!=1){e[i][1]--;}
             else if(way[e[i][0]-1][e[i][1]]!=1){e[i][0]--;}break;
    case 1 : if(way[e[i][0]][e[i][1]+1]!=1){e[i][1]++;}
             else if(way[e[i][0]+1][e[i][1]]!=1){e[i][0]++;}break;
    case 2 : if(way[e[i][0]-1][e[i][1]]!=1){e[i][0]--;}
             else if(way[e[i][0]][e[i][1]-1]!=1){e[i][1]--;}break;
    case 3 : if(way[e[i][0]+1][e[i][1]]!=1){e[i][0]++;}
             else if(way[e[i][0]][e[i][1]+1]!=1){e[i][1]++;}break;
    }
}}
 
Tips dan Trik, Tips and Tricks © 2011 | Designed by Blogger Hacks | Blogger Template by ColorizeTemplates