Sunday, June 19, 2011

Mini project snake game in c

Mini project in C many Student do management project like library management ,Hotel management etc.But Snake Game is mini project of first semester build by my friend which is very different.It is console application without graphic library that's why it is more interesting.This game is perfect without any error and better user interface.It is complied in code::block using c language.Here goes a source code you can copy and compiled it in code::block.I hope it can help and become a reference for your project. Download Project from Github.

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
#include<time.h>
#include<ctype.h>
#include <time.h>
#include <windows.h>
#include <process.h>

#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77

int length;
int bend_no;
int len;
char key;
void record();
void load();
int life;
void Delay(long double);
void Move();
void Food();
int Score();
void Print();
void gotoxy(int x, int y);
void GotoXY(int x,int y);
void Bend();
void Boarder();
void Down();
void Left();
void Up();
void Right();
void ExitGame();
int Scoreonly();

struct coordinate{
    int x;
    int y;
    int direction;
};

typedef struct coordinate coordinate;

coordinate head, bend[500],food,body[30];

int main()
{

    char key;

    Print();

    system("cls");

    load();

    length=5;

    head.x=25;

    head.y=20;

    head.direction=RIGHT;

    Boarder();

    Food(); //to generate food coordinates initially

    life=3; //number of extra lives

    bend[0]=head;

    Move();   //initialing initial bend coordinate

    return 0;

}

void Move()
{
    int a,i;

    do{

        Food();
        fflush(stdin);

        len=0;

        for(i=0;i<30;i++)

        {

            body[i].x=0;

            body[i].y=0;

            if(i==length)

            break;

        }

        Delay(length);

        Boarder();

        if(head.direction==RIGHT)

            Right();

        else if(head.direction==LEFT)

            Left();

        else if(head.direction==DOWN)

            Down();

        else if(head.direction==UP)

            Up();

        ExitGame();

    }while(!kbhit());

    a=getch();

    if(a==27)

    {

        system("cls");

        exit(0);

    }
    key=getch();

    if((key==RIGHT&&head.direction!=LEFT&&head.direction!=RIGHT)||(key==LEFT&&head.direction!=RIGHT&&head.direction!=LEFT)||(key==UP&&head.direction!=DOWN&&head.direction!=UP)||(key==DOWN&&head.direction!=UP&&head.direction!=DOWN))

    {

        bend_no++;

        bend[bend_no]=head;

        head.direction=key;

        if(key==UP)

            head.y--;

        if(key==DOWN)

            head.y++;

        if(key==RIGHT)

            head.x++;

        if(key==LEFT)

            head.x--;

        Move();

    }

    else if(key==27)

    {

        system("cls");

        exit(0);

    }

    else

    {

        printf("\a");

        Move();

    }
}

void gotoxy(int x, int y)
{

 COORD coord;

 coord.X = x;

 coord.Y = y;

 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}
void GotoXY(int x, int y)
{
    HANDLE a;
    COORD b;
    fflush(stdout);
    b.X = x;
    b.Y = y;
    a = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(a,b);
 }
void load(){
    int row,col,r,c,q;
    gotoxy(36,14);
    printf("loading...");
    gotoxy(30,15);
    for(r=1;r<=20;r++){
    for(q=0;q<=100000000;q++);//to display the character slowly
    printf("%c",177);}
    getch();
}
void Down()
{
    int i;
    for(i=0;i<=(head.y-bend[bend_no].y)&&len<length;i++)
    {
        GotoXY(head.x,head.y-i);
        {
            if(len==0)
                printf("v");
            else
                printf("*");
        }
        body[len].x=head.x;
        body[len].y=head.y-i;
        len++;
    }
    Bend();
    if(!kbhit())
        head.y++;
}
void Delay(long double k)
{
    Score();
    long double i;
    for(i=0;i<=(10000000);i++);
}
void ExitGame()
{
    int i,check=0;
    for(i=4;i<length;i++)   //starts with 4 because it needs minimum 4 element to touch its own body
    {
        if(body[0].x==body[i].x&&body[0].y==body[i].y)
        {
            check++;    //check's value increases as the coordinates of head is equal to any other body coordinate
        }
        if(i==length||check!=0)
            break;
    }
    if(head.x<=10||head.x>=70||head.y<=10||head.y>=30||check!=0)
    {
        life--;
        if(life>=0)
        {
            head.x=25;
            head.y=20;
            bend_no=0;
            head.direction=RIGHT;
            Move();
        }
        else
        {
            system("cls");
            printf("All lives completed\nBetter Luck Next Time!!!\nPress any key to quit the game\n");
            record();
            exit(0);
        }
    }
}
void Food()
{
    if(head.x==food.x&&head.y==food.y)
    {
        length++;
        time_t a;
        a=time(0);
        srand(a);
        food.x=rand()%70;
        if(food.x<=10)
            food.x+=11;
        food.y=rand()%30;
        if(food.y<=10)

            food.y+=11;
    }
    else if(food.x==0)/*to create food for the first time coz global variable are initialized with 0*/
    {
        food.x=rand()%70;
        if(food.x<=10)
            food.x+=11;
        food.y=rand()%30;
        if(food.y<=10)
            food.y+=11;
    }
}
void Left()
{
    int i;
    for(i=0;i<=(bend[bend_no].x-head.x)&&len<length;i++)
    {
        GotoXY((head.x+i),head.y);
       {
                if(len==0)
                    printf("<");
                else
                    printf("*");
        }
        body[len].x=head.x+i;
        body[len].y=head.y;
        len++;
    }
    Bend();
    if(!kbhit())
        head.x--;

}
void Right()
{
    int i;
    for(i=0;i<=(head.x-bend[bend_no].x)&&len<length;i++)
    {
        //GotoXY((head.x-i),head.y);
        body[len].x=head.x-i;
        body[len].y=head.y;
        GotoXY(body[len].x,body[len].y);
        {
            if(len==0)
                printf(">");
            else
                printf("*");
        }
        /*body[len].x=head.x-i;
        body[len].y=head.y;*/
        len++;
    }
    Bend();
    if(!kbhit())
        head.x++;
}
void Bend()
{
    int i,j,diff;
    for(i=bend_no;i>=0&&len<length;i--)
    {
            if(bend[i].x==bend[i-1].x)
            {
                diff=bend[i].y-bend[i-1].y;
                if(diff<0)
                    for(j=1;j<=(-diff);j++)
                    {
                        body[len].x=bend[i].x;
                        body[len].y=bend[i].y+j;
                        GotoXY(body[len].x,body[len].y);
                        printf("*");
                        len++;
                        if(len==length)
                            break;
                    }
                else if(diff>0)
                    for(j=1;j<=diff;j++)
                    {
                        /*GotoXY(bend[i].x,(bend[i].y-j));
                        printf("*");*/
                        body[len].x=bend[i].x;
                        body[len].y=bend[i].y-j;
                        GotoXY(body[len].x,body[len].y);
                        printf("*");
                        len++;
                        if(len==length)
                            break;
                    }
            }
        else if(bend[i].y==bend[i-1].y)
        {
            diff=bend[i].x-bend[i-1].x;
            if(diff<0)
                for(j=1;j<=(-diff)&&len<length;j++)
                {
                    /*GotoXY((bend[i].x+j),bend[i].y);
                    printf("*");*/
                    body[len].x=bend[i].x+j;
                    body[len].y=bend[i].y;
                    GotoXY(body[len].x,body[len].y);
                        printf("*");
                   len++;
                   if(len==length)
                           break;
               }
           else if(diff>0)
               for(j=1;j<=diff&&len<length;j++)
               {
                   /*GotoXY((bend[i].x-j),bend[i].y);
                   printf("*");*/
                   body[len].x=bend[i].x-j;
                   body[len].y=bend[i].y;
                   GotoXY(body[len].x,body[len].y);
                       printf("*");
                   len++;
                   if(len==length)
                       break;
               }
       }
   }
}
void Boarder()
{
   system("cls");
   int i;
   GotoXY(food.x,food.y);   /*displaying food*/
       printf("F");
   for(i=10;i<71;i++)
   {
       GotoXY(i,10);
           printf("!");
       GotoXY(i,30);
           printf("!");
   }
   for(i=10;i<31;i++)
   {
       GotoXY(10,i);
           printf("!");
       GotoXY(70,i);
       printf("!");
   }
}
void Print()
{
   //GotoXY(10,12);
   printf("\tWelcome to the mini Snake game.(press any key to continue)\n");
  getch();
   system("cls");
   printf("\tGame instructions:\n");
   printf("\n-> Use arrow keys to move the snake.\n\n-> You will be provided foods at the several coordinates of the screen which you have to eat. Everytime you eat a food the length of the snake will be increased by 1 element and thus the score.\n\n-> Here you are provided with three lives. Your life will decrease as you hit the wall or snake's body.\n\n-> YOu can pause the game in its middle by pressing any key. To continue the paused game press any other key once again\n\n-> If you want to exit press esc. \n");
   printf("\n\nPress any key to play game...");
   if(getch()==27)
   exit(0);
}
void record(){
   char plname[20],nplname[20],cha,c;
   int i,j,px;
   FILE *info;
   info=fopen("record.txt","a+");
   getch();
   system("cls");
   printf("Enter your name\n");
   scanf("%[^\n]",plname);
   //************************
   for(j=0;plname[j]!='\0';j++){ //to convert the first letter after space to capital
   nplname[0]=toupper(plname[0]);
   if(plname[j-1]==' '){
   nplname[j]=toupper(plname[j]);
   nplname[j-1]=plname[j-1];}
   else nplname[j]=plname[j];
   }
   nplname[j]='\0';
   //*****************************
   //sdfprintf(info,"\t\t\tPlayers List\n");
   fprintf(info,"Player Name :%s\n",nplname);
    //for date and time

   time_t mytime;
  mytime = time(NULL);
  fprintf(info,"Played Date:%s",ctime(&mytime));
     //**************************
     fprintf(info,"Score:%d\n",px=Scoreonly());//call score to display score
     //fprintf(info,"\nLevel:%d\n",10);//call level to display level
   for(i=0;i<=50;i++)
   fprintf(info,"%c",'_');
   fprintf(info,"\n");
   fclose(info);
   printf("wanna see past records press 'y'\n");
   cha=getch();
   system("cls");
   if(cha=='y'){
   info=fopen("record.txt","r");
   do{
       putchar(c=getc(info));
       }while(c!=EOF);}
     fclose(info);
}
int Score()
{
   int score;
   GotoXY(20,8);
   score=length-5;
   printf("SCORE : %d",(length-5));
   score=length-5;
   GotoXY(50,8);
   printf("Life : %d",life);
   return score;
}
int Scoreonly()
{
int score=Score();
system("cls");
return score;
}
void Up()
{
   int i;
   for(i=0;i<=(bend[bend_no].y-head.y)&&len<length;i++)
   {
       GotoXY(head.x,head.y+i);
       {
           if(len==0)
               printf("^");
           else
               printf("*");
       }
       body[len].x=head.x;
       body[len].y=head.y+i;
       len++;
   }
   Bend();
   if(!kbhit())
       head.y--;
}

126 comments:

  1. "windows.h header file" is missing in my c software and c software is emulated c++ which is compatible with window7
    any one could please help me to solve this problem
    Thank you in advance

    ReplyDelete
  2. Sorry I am can't understand which compiler you use this code run only in gcc compiler.I think you are using turbo c then don't use it is old download codeblocks which support latest standard c language

    ReplyDelete
  3. i got 4 errors and 1 warning.i m using C Free5 to run .
    errors are:

    --------------------Configuration: mingw5 - CUI Debug, Builder Type: MinGW--------------------

    Checking file dependency...
    Compiling C:\Users\RAJEEVRAMAN\Documents\C-Free\Projects\snake game\main.c...
    [Error] C:\Users\RAJEEVRAMAN\Documents\C-Free\Projects\snake game\main.c:206: error: conflicting types for 'Food'
    [Error] C:\Users\RAJEEVRAMAN\Documents\C-Free\Projects\snake game\main.c:51: error: previous implicit declaration of 'Food' was here
    [Error] C:\Users\RAJEEVRAMAN\Documents\C-Free\Projects\snake game\main.c:364: error: conflicting types for 'Print'
    [Error] C:\Users\RAJEEVRAMAN\Documents\C-Free\Projects\snake game\main.c:43: error: previous implicit declaration of 'Print' was here
    [Warning] C:\Users\RAJEEVRAMAN\Documents\C-Free\Projects\snake game\main.c:454:2: warning: no newline at end of file

    Complete Make main: 4 error(s), 1 warning(s)

    ReplyDelete
    Replies
    1. use Code::Block... better compiler

      Delete
    2. I use Code:Blocks and it's better than C Free5 because Code:Blocks has more options like i don't know etc etc and it's a free compiler.I'm in the 7th class (sorry for my english) and my Computer teacher is impressed.My skills are so high,so i teach my collagues programming language.For me it's simple because i study a lot of programming language and i remember all the tricks of the programming language.If you want to ask me something about programming language i will leave the link of my facebook to talk.

      https://www.facebook.com/valcescu.eduard.3

      Delete
    3. Use Code Blocks is Best Compiler Ever

      Delete
  4. This program is compile in Code::Blocks IDE with MinGw I don't know about
    C Free5 so compile it in codeblocks if you don't have then download it form codeblocks.org

    ReplyDelete
  5. hey nice piece of code... but can any 1 plz tell me in this project do u use any data structure...if any plz tell me which one...

    ReplyDelete
    Replies
    1. yes....without data structure nothin can be formed into form.....itx before main....check it....

      Delete
    2. Are you a fucking retard?? "formed into form"???

      Delete
  6. thanks bro... it's working in codeblocks latest version.

    ReplyDelete
  7. any 1 help me plzzz....i got 10 errors nd 5 warnings..

    ReplyDelete
    Replies
    1. plz specify which compiler you use

      Delete
    2. Hello boss...can u give algorithm for this project..

      Delete
  8. i got 17 error and 5 warning
    using turbo c++ 4.5

    ReplyDelete
  9. i use codeblocks but it have 4 errors , help me soon, thanks

    ReplyDelete
  10. conio.h is not a standard C library. That's the reason it triggers errors.

    ReplyDelete
    Replies
    1. so how can we replace this library?

      Delete
  11. yr i got more than 17erros nd 8warnings

    ReplyDelete
  12. Works perfectly for me in code blocks

    ReplyDelete
  13. I get this error compiling with COdeBLocks

    x86)\CodeBlocks\ghd\Untitled2.cpp:43:11: error: 'Print' was not declared in this scope
    C:\Program Files (x86)\CodeBlocks\ghd\Untitled2.cpp:51:10: error: 'Food' was not declared in this scope
    C:\Program Files (x86)\CodeBlocks\ghd\Untitled2.cpp:42:10: warning: unused variable 'key' [-Wunused-variable]
    C:\Program Files (x86)\CodeBlocks\ghd\Untitled2.cpp: In function 'void Move()':
    C:\Program Files (x86)\CodeBlocks\ghd\Untitled2.cpp:62:14: error: 'Food' was not declared in this scope
    C:\Program Files (x86)\CodeBlocks\ghd\Untitled2.cpp: In function 'void load()':
    C:\Program Files (x86)\CodeBlocks\ghd\Untitled2.cpp:137:9: warning: unused variable 'row' [-Wunused-variable]
    C:\Program Files (x86)\CodeBlocks\ghd\Untitled2.cpp:137:13: warning: unused variable 'col' [-Wunused-variable]
    C:\Program Files (x86)\CodeBlocks\ghd\Untitled2.cpp:137:19: warning: unused variable 'c' [-Wunused-variable]
    C:\Program Files (x86)\CodeBlocks\ghd\Untitled2.cpp: In function 'void Delay(long double)':
    C:\Program Files (x86)\CodeBlocks\ghd\Untitled2.cpp:169:11: error: 'Score' was not declared in this scope


    Please help. Thanks

    ReplyDelete
    Replies
    1. EDIT : I solve the problem. IT WORKS GREAT.

      THANKS !!

      Delete
  14. Thanks! Had some errors but i fixed them!

    ReplyDelete
  15. what is the coding for loading?

    ReplyDelete
  16. what is the use of COORD coord ???

    ReplyDelete
    Replies
    1. COORD coord is the structure which is used to move the cursor so that the snake move on the screen by changing cursor with the help of this.

      Delete
    2. How can i change the speed and the word " F " which is for food .

      Delete
  17. Can any body explain this whole code line by line please .. -thanks in advance

    ReplyDelete
    Replies
    1. Who have the time to explain the code line by line. Just start learning from int main() function and step by step each function.

      Delete
  18. hi there,thanks to this coding..it can run perfectly..although it has a little bit of error,but after fix it,i can play the game..5star 4 u..

    ReplyDelete
  19. Really great share! Thanks:) Compiled in Dev C++ and it works grand.

    ReplyDelete
  20. |206|error: conflicting types for 'Food'|
    |51|error: previous implicit declaration of 'Food' was here|
    |364|error: conflicting types for 'Print'|
    |43|error: previous implicit declaration of 'Print' was here|
    ||=== Build finished: 4 errors, 0 warnings (0 minutes, 4 seconds) ===|



    What's going on?

    ReplyDelete
  21. write void in line 43 before Print and it should work

    ReplyDelete
  22. Error-1 error C3861: 'Food': identifier not found

    Error-2 error C3861: 'Food': identifier not found

    Error-3 error C3861: 'Score': identifier not found

    Warning-4 warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data

    ReplyDelete
  23. Error 1 error C3861: 'Print': identifier not found c:\users\dell\documents\visual studio 2010\projects\snack\snack\snack.cpp 43 1 snack
    Error 2 error C3861: 'Food': identifier not found c:\users\dell\documents\visual studio 2010\projects\snack\snack\snack.cpp 51 1 snack
    Error 3 error C3861: 'Food': identifier not found c:\users\dell\documents\visual studio 2010\projects\snack\snack\snack.cpp 62 1 snack
    Error 4 error C3861: 'Score': identifier not found c:\users\dell\documents\visual studio 2010\projects\snack\snack\snack.cpp 169 1 snack
    Warning 5 warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data c:\users\dell\documents\visual studio 2010\projects\snack\snack\snack.cpp 212 1 snack

    ReplyDelete
  24. Can I have a coding on TYPING TUTOR please?

    ReplyDelete
  25. To fix the problem

    Error-1 error C3861: 'Food': identifier not found

    Error-2 error C3861: 'Food': identifier not found

    Error-3 error C3861: 'Score': identifier not found

    Add:

    void Food();
    void Print();
    int Score();

    at the top with the other declared functions this should fix the issue.

    ReplyDelete
    Replies
    1. is not well explanatory please kindly explain the source code.

      Delete
  26. For those getting errors for food and print function, simply give a function prototype at the top where other function prototypes have been placed .....



    ReplyDelete
  27. pls help us....
    our errors are:
    [Error] D:\c\Untitled3.cpp:87:11: error: 'Print' was not declared in this scope
    [Error] D:\c\Untitled3.cpp:103:10: error: 'Food' was not declared in this scope
    [Error] D:\c\Untitled3.cpp:126:14: error: 'Food' was not declared in this scope
    [Error] D:\c\Untitled3.cpp:344:11: error: 'Score' was not declared in this scope
    [Error] D:\c\Untitled3.cpp:805:5: error: expected primary-expression before '<' token
    [Error] D:\c\Untitled3.cpp:805:6: error: 'span' was not declared in this scope
    [Error] D:\c\Untitled3.cpp:805:11: error: expected ';' before 'class'
    [Error] D:\c\Untitled3.cpp:807:5: error: expected primary-expression before '<' token
    [Error] D:\c\Untitled3.cpp:807:11: error: expected ';' before 'class'
    [Error] D:\c\Untitled3.cpp:809:5: error: expected primary-expression before '<' token
    [Error] D:\c\Untitled3.cpp:809:11: error: expected ';' before 'class'

    ReplyDelete
  28. hi....can u give algorithm for this project

    ReplyDelete
  29. It's very big code. Thanks for sharing.

    ReplyDelete
  30. i have got the output but i wasunable to play. The program quits immediately after pressing a key.

    ReplyDelete
  31. i use c-free 4.0 and it displays these errors
    [Error] C:\Users\DAVLEX\Desktop\game.c:339: parse error before `long'
    [Error] C:\Users\DAVLEX\Desktop\game.c:341: `i' undeclared (first use in this function)
    [Error] C:\Users\DAVLEX\Desktop\game.c:341: (Each undeclared identifier is reported only once
    [Error] C:\Users\DAVLEX\Desktop\game.c:341: for each function it appears in.)
    [Warning] C:\Users\DAVLEX\Desktop\game.c:411: warning: type mismatch with previous implicit declaration
    [Warning] C:\Users\DAVLEX\Desktop\game.c:123: warning: previous implicit declaration of `Food'
    [Warning] C:\Users\DAVLEX\Desktop\game.c:411: warning: `Food' was previously implicitly declared to return `int'
    [Error] C:\Users\DAVLEX\Desktop\game.c:419: parse error before `a'
    [Error] C:\Users\DAVLEX\Desktop\game.c:421: `a' undeclared (first use in this function)
    [Error] C:\Users\DAVLEX\Desktop\game.c:689: parse error before `int'
    [Error] C:\Users\DAVLEX\Desktop\game.c:695: `i' undeclared (first use in this function)
    [Warning] C:\Users\DAVLEX\Desktop\game.c:727: warning: type mismatch with previous implicit declaration
    [Warning] C:\Users\DAVLEX\Desktop\game.c:85: warning: previous implicit declaration of `Print'
    [Warning] C:\Users\DAVLEX\Desktop\game.c:727: warning: `Print' was previously implicitly declared to return `int'
    [Error] C:\Users\DAVLEX\Desktop\game.c:792: parse error before `mytime'
    [Error] C:\Users\DAVLEX\Desktop\game.c:794: `mytime' undeclared (first use in this function)

    ReplyDelete
  32. i m making program in embed c.same as this progrm.so help me.if any one knw something.pls mail me
    manindersingh640@gmail.com

    ReplyDelete
  33. Use microsoft visual c++ 6.0 and run it it should support

    ReplyDelete
  34. some things to ask....first how did u figure it out to use coordinates.....like gotoxy(10,i).......how?? where they came from....? i hav become a progammer too n now headin towardx a project...but i need sum help..how should i begin with it?.......like you set the border..which i hav got it somehow.....

    ReplyDelete
  35. You know ma project is entirely different n very less on internet...it is archery game project...and i m alone to work on it....otherwise itx a team work.....since that time i have been workin on it madly and testin and takin out each element to figure out what's a function's purpose is......till now i have successfully been able to figure out the frame of game, the loading function, and now finally the snake.........well...that's for sure that i will definitely get screw up and fucked up in developin another project.......but still i will do...and that's the thrill......... no one tells you how to get started on a project....just give you the code.....i finally have also solved this problem.....first download the already done project of somebody.....then try to figure out the functions if it is being developed by functions..each and every.....take out each function on a separate place and run it.....also collect all related elements from other functions which permit this function to run......do this with each one.....you will see what each function is doing......then take out the infomation that your own project needs......that's all....helping otherx is gud but dont know y it is not available on net....... buddy thankx for your code....its undoubtedly a helpful tool......

    ReplyDelete
  36. Compiled fine. After I got to a score of 26 the game starting freaking out and flashing fragmented parts of the snake on the screen. Strange...

    ReplyDelete
  37. These are the error i get after building this program. Can anybody help me solve them? Thanks!
    Compiling: main.cpp
    C:\CPP_Programs\Minigame\Minigame\main.cpp: In function 'int main()':
    C:\CPP_Programs\Minigame\Minigame\main.cpp:85: error: 'Print' was not declared in this scope
    C:\CPP_Programs\Minigame\Minigame\main.cpp:101: error: 'Food' was not declared in this scope
    C:\CPP_Programs\Minigame\Minigame\main.cpp:83: warning: unused variable 'key'
    C:\CPP_Programs\Minigame\Minigame\main.cpp: In function 'void Move()':
    C:\CPP_Programs\Minigame\Minigame\main.cpp:123: error: 'Food' was not declared in this scope
    C:\CPP_Programs\Minigame\Minigame\main.cpp: In function 'void load()':
    C:\CPP_Programs\Minigame\Minigame\main.cpp:273: warning: unused variable 'row'
    C:\CPP_Programs\Minigame\Minigame\main.cpp:273: warning: unused variable 'col'
    C:\CPP_Programs\Minigame\Minigame\main.cpp:273: warning: unused variable 'c'
    C:\CPP_Programs\Minigame\Minigame\main.cpp: In function 'void Delay(long double)':
    C:\CPP_Programs\Minigame\Minigame\main.cpp:337: error: 'Score' was not declared in this scope
    Process terminated with status 1 (0 minutes, 1 seconds)
    4 errors, 4 warnings

    ReplyDelete
  38. could u plase tolde me how 2 make the snake move sloly how i can control of its movement ?? ^_^

    ReplyDelete
  39. hey can we use tc for this

    ReplyDelete
  40. hey i want celebration animation project in computer graphics please help me

    ReplyDelete
  41. How to playing what controls??

    ReplyDelete
  42. the loading status bar keeps on saying that it is loading,although it has loaded to its maximum width and when i press any key it tells that all your three lives are completed and two more things,please tell me how to start the game after loading status bar has completely loaded in dev c++

    ReplyDelete
  43. the loading status bar keeps on saying that it is loading,although it has loaded to its maximum width and when i press any key it tells that all your three lives are completed and two more things,please tell me how to start the game after loading status bar has completely loaded in dev c++.

    please anyone help me out

    ReplyDelete
  44. Good Job, its half baked actually. But its a good game :)

    ReplyDelete
  45. @ umang just click on enter button

    ReplyDelete
  46. this is running properly in my pc but the problem is that the border keeps shaking!! how to stop this? please reply as soon as you can !

    ReplyDelete
  47. Mini project snake game is really good. thanks for sharing.
    backup software for windows free

    ReplyDelete
  48. Mini project snake game is really awesome and very useful.
    full version of windows

    ReplyDelete
  49. i phone 6 plus by only 7500 taka master king copy
    for details : 01711952849

    ReplyDelete
  50. I didn't understood please help me

    ReplyDelete
  51. Thanks a lot for sharing about Mini project, it's a very useful post.
    Software Download

    ReplyDelete
  52. Thanks a lot for sharing all codes. I'm new in this stuff and more educational like these mini projects. I compiled in Dev-C++ 4.9.9.2 and works fine. But I need to figure out keep window on the screen after press "y". :)

    ReplyDelete
  53. this has a trojan horse in the code

    ReplyDelete
  54. Wow amazing blog.I always love to read these kind of blogs.
    adobe after effects product key
    Free Download

    ReplyDelete
  55. can anyone post code without error

    ReplyDelete
  56. I am getting windows.h related error since there is no windows.h header file in include folder. So, how can I obtain the same?

    ReplyDelete
  57. works for me !!
    on dev c++ an C::B

    ReplyDelete
  58. Really like the code. I hope you are still active. I had a few doubts like what is
    1)COORD coord?
    2)bend_no?
    3)gotoxy and GotoXY?
    4) How is cursor mapped to the movement of the snake?

    Any reply would be great help.

    ReplyDelete
  59. I use codeblocks 10.05 and when I run this code there the notification appears- "Drawing operation was attempted when there was no current window"-What's the solution.

    ReplyDelete
  60. Error: 'Drawing operation was attempted when there was no current window' after displaying: 'Welcome to the mini Snake game.(press any key to continue)'. Code::Blocks 13.12 (Windows)

    ReplyDelete
  61. hello sir.... i am shubham deepankar and m new in programming field....awesome coding sir.... really m fan of yours.... i copy that code and run in code blocks it works awesome.... i wants to learn something like that ... plzzz sir help mee....

    ReplyDelete
  62. i am getting a error which says drawing opration attempted when there was no window . how can i solve this error.

    ReplyDelete
  63. owsam programing,thanks alot for this ,,

    ReplyDelete
  64. IT IS NOT WORKING WHEN I SRART THE GAME I AM DIEING !!!!!!!!!!!!!!!!!!! :( :(:(:(:(:(:(:(:(:(:(:(:(:(:(

    ReplyDelete
  65. IT IS NOT WORKING WHEN I SRART THE GAME I AM DIEING !!!!!!!!!!!!!!!!!!! :( :(:(:(:(:(:(:(:(:(:(:(:(:(:(

    ReplyDelete
  66. Int bend_no
    What do you used for?

    ReplyDelete
  67. int len; why you use it ?!(for example:(len<legth))
    Anyone can help me !

    ReplyDelete
  68. What is the use of this part of code...


    len=0;

    for(i=0;i<30;i++)

    {

    body[i].x=0;

    body[i].y=0;

    if(i==length)

    break;

    ReplyDelete
  69. can we use this code in turbo c++

    ReplyDelete
  70. lot of errors and also windows.h not working in turbo0 .......plz help

    ReplyDelete
  71. this code is perfect but unfortunatly i want c++ code of snake game . any one can help me in this reguard?

    ReplyDelete
  72. Thank you so much.... It's working

    ReplyDelete
  73. guyss run this program in Dev-C++ compiler ...

    ReplyDelete
  74. does this work in turbo c

    ReplyDelete
  75. I am beginner anyone help to enter world of codes
    I only know somethings on console in c++

    ReplyDelete
  76. I got some errors in the above code so i used the below given :
    http://www.infoopoint.com/snake-game-using-c-complete-code/

    ReplyDelete
  77. i tried this program using code blocks and worked perfectly. But the problem is if i make any changes in program like in printf i change the statement it doesnt reflects in the output ,it gives output of the previous code not the changed one . And yes i saved program and executed . How is that possible?

    ReplyDelete
  78. this is good, work very well, this site good for reference, thanks dude...

    ReplyDelete
  79. What is the algorithm

    ReplyDelete
  80. Can any one tell me the algorithm and some data structures used in this code

    ReplyDelete
  81. hey bro i also got 17 errors and 8 warning using c++ 4.0

    ReplyDelete