Wednesday, September 19, 2012

Simple Hello World Game In C

         Do you want to publish source codes in your blog or web site as follows.
                              Visit Source Code Formatter
 ////////////////////////////A Hello World for game/////////////////////////////////  
 ///////////////////////////////By croosetech///////////////////////////////////////  
 /////////////////Visit croosetech.blogspot.com for more////////////////////////////  
 #include <stdio.h>  
 #include <stdlib.h>  
 #include <string.h>  
 #include <time.h>  
 int main(){  
        int a=0,i=0,answer=0,last=0,x=0,exit=0;  
        last=10;  
        unsigned int iseed = (unsigned int)time(NULL);  
     srand (iseed);  
        while(x<5){  
             i=3;  
             a=rand()%last;   
             printf("\n****************************************\n");  
           printf("\tThis is a Hello World Game\n");  
           printf("****************************************\n");  
             printf("I have a number between 0 to %d.\n\n",last-1);  
             while(i>0){  
                  printf("Try to guess my number(%i attemps remaining): ",i);   
                  scanf("%d", &answer);  
                  if(answer<a){  
                       printf("\nYours %d is too small...\n", answer);   
                       i--;  
                       continue;  
                  }  
                  if(answer>a){  
                       printf("\nYours %d is too big...\n", answer);   
                       i--;  
                       continue;  
                  }  
                  if(answer==a){  
                       printf("\nYou're Right! My number is %d!\n\n\t\tCongratz...", a);   
                       break;  
                  }  
             }  
             if(i==0){  
                  printf("\n\t\tYou are looser !!!.\n\t\t GAME OVER\n");  
                  printf("****************************************\n");  
                  printf("To try again press 1(any other to exit): ");  
                  scanf("%d", &exit);  
                  if(exit==1){  
                       x=0;  
                       last=10;  
                       continue;  
                  }  
                  else {  
                       printf("Good bye!!!");  
                       return 0;  
                  }  
             }  
             else{  
                  printf("Now you are move on to next level\n\n");  
                  x++;  
                  last=last+10;  
                  continue;  
             }  
       }  
       if(x==5){  
            system("clear");  
            printf("\t\tAWESOME PERFORMANCE\n\n\n");  
       }  
      return 0;    
 }  

0 comments:

Post a Comment