Snake game in C language using queue

Requirments: Turbo C++ compiler

If you face any graphics error ,follow these steps.

  1. Go to “BGI” folder. ( C:\TurboC++\Disk\TurboC3\BGI).
  2. Copy file “EGAVGA.BGI” 
  3. Got “BIN” folder. ( C:\TurboC++\Disk\TurboC3\BIN).
  4. Paste “EGAVGA.BGI” file .
  5. Close Turbo C++ and open it again and run program.

How snake game works?:

  1. Initialize the snake by inserting 4 nodes in queue
  2. Print the queue, these 4 nodes will create snake
  3. To move the snake, add new node in front of head and delete node from tail
  4. clear screen and redraw the screen
  5. This will create illusion of moving snake
  6. If snake hits the food then add extra node in queue
  7. if snake hits the wall or himself then end the game

Download .C file-> SNAKE ( Right click & Save link As). Copy paste code on your local machine

About Gaurav Vichare

Hi , I am Gaurav : author of this blog , Software engineer and a Photoshop lover . You can connect with me on Facebook , cirlce me on Google or follow on Twitter

  • Kunal Vichare

    Hi Gaurav

    I copied your program in turboc . It is working very nice.

    You have to be have bit more concentration on Programming style. Meaningful variable names and language indentation. Otherwise it is excellent.
    From all your program I concluded that you had good test of Programming.
    thanks you.

  • Tapish Rana

    can you please send me the line by line explanation of this program??

    • GAURAV G VICHARE

      @tapishrana:disqus Really sorry for late reply. Now I made few improvements in the program, added description about working of the game, gave meaningful names to the variables, added comments wherever required and refactored the code. Hope this helps, if you have problem regarding particular block of code please comment. I will also upload the video of screen recording.

  • Johnny

    Hi, amazing code, just have an answer about:” int delete(queue *t) “, when compile code, turbo c++ says declaration terminated incorrectly about this function, don’t know why, can you help ?

    • GAURAV G VICHARE

      Did you put semi colon after “int delete(queue *t)” by mistake? or any extra semi colon on the previous lines? Its working at my end.