Add to Favorites    Make Home Page 22489 Online  
 Language Categories  
 Our Services  

Home » C Home » Games and Graphics Home » Simple Snake game.


Search Projects & Source Codes:

Title Simple Snake game.
Author Rudra Dev G
Author Email kakatiyarudra [at]
Description This game contains one white colored object which is under user control and runs over the screen, and we need to touch the target object, which is in red color with out touching the border lines.
Category C » Games and Graphics
Hits 46435
Code Select and Copy the Code
#include <graphics.h> #include <stdio.h> #include <stdlib.h> #define T 2000 int n=0,px,py; main() { int gd=DETECT,gm,i,j; clrscr(); gotoxy(25,4); printf("DON'T TUCH THE BORDER"); gotoxy(25,6); printf("Press < p > for pause"); gotoxy(17,8); printf("IN MIDDLE OF GAME, PRESS < Esc > TO EXIT"); x: gotoxy(26,10); printf("press < s > to start "); gotoxy(26,12); printf(" Use SMALL case only"); gotoxy(34,10); if(getch()=='s') initgraph(&gd,&gm,"c:\tc\bgi"); else { clrscr(); goto x; } line(0,0,0,479); line(0,0,639,0); line(639,0,639,479); line(0,479,639,479); pause(); print(); right(100,100); } right(int x,int y) { char ch,fu='r'; int i,j; for(i=x;i<=652;i++){ for(j=y;j<=y+10;j++){ putpixel(i,j,4); putpixel(i-10,j,16); } delay(T-n); check(i,j-1); if(kbhit()){ ch=getch(); if(ch=='p') pause(); else choice(i,j-1,ch,fu); } } } left(int x,int y) { char ch,fu='l'; int i,j; for(i=x;i>-12;i--){ for(j=y;j<=y+10;j++){ putpixel(i,j,4); putpixel(i+10,j,16); } delay(T-n); check(i,j-1); if(kbhit()){ ch=getch(); if(ch=='p') pause(); else choice(i,j-1,ch,fu); } } } down(int x,int y) { char ch,fu='d'; int i,j; for(j=y;j<=492;j++){ for(i=x;i<=x+10;i++){ putpixel(i,j,4); putpixel(i,j-10,16); } delay(T-n); check(i-1,j); if(kbhit()){ ch=getch(); if(ch=='p') pause(); else choice(i-1,j,ch,fu); } } } up(int x,int y) { char ch,fu='u'; int i,j; for(j=y;j>=-12;j--){ for(i=x;i<=x+10;i++){ putpixel(i,j,4); putpixel(i,j+10,16); } delay(T-n); check(i-1,j); if(kbhit()){ ch=getch(); if(ch=='p') pause(); else choice(i-1,j,ch,fu); } } } choice(int i,int j,char ch,char fu) { if(fu=='r'){ if(ch=='K'){ j-=10; i-=10; left(i,j); } else if(ch=='P'){ i-=10; down(i,j); } else if(ch=='H'){ j-=10; i-=10; up(i,j); } else if(ch==27) esc(); else { j-=10; right(i,j); } } else if(fu=='l'){ if(ch=='M'){ j-=10; /*i+=-10; no comments here free me*/ right(i,j); } else if(ch=='P') down(i,j); else if(ch=='H'){ j-=10; up(i,j); } else if(ch==27) esc(); else { j-=10; left(i,j); } } else if(fu=='d'){ if(ch=='H'){ j-=10; i-=10; up(i,j); } else if(ch=='K'){ i-=10; j-=10; left(i,j); } else if(ch=='M'){ j-=10; right(i,j); } else if(ch==27) esc(); else { i-=10; down(i,j); } } else if(fu=='u'){ if(ch=='P'){ j+=10; i-=10; down(i,j); } else if(ch=='M') right(i,j); else if(ch=='K'){ i-=10; left(i,j); } else if(ch==27) esc(); else { i-=10; up(i,j); } } } check(int i,int j) { if (n>T-1750) { gotoxy(7,5); printf("U r Great U got Good Score, If possible Please Develop this game"); gotoxy(24,7); printf("Press ENTER Key To Continue"); getchar(); esc(); } if(i<3 || i>637 || j<3 || j>477){ outtextxy(240,240,"YOU HAVE TOUUCHED THE BORDER"); outtextxy(280,280,"GAME OVER"); outtextxy(240,370,"Better Luck Next Time"); outtextxy(200,310,"<press ENTER Key to continue>"); getchar(); esc(); } else if(tuch(i,j)){ rub(); bell(); n+=10; stage(); print(); } } int tuch(int i,int j) { int x=px,y=py,t,s,flag=0; for(t=x;t<=x+15;t++){ for(s=y;s<=y+15;s++) if(j==s && i==t) flag=1; } return(flag); } rub() { setcolor(16); outtextxy(px,py,"?"); setcolor(15); } bell() { int i; for(i=1;i<=5;i++){ sound(200*i); delay(10000); nosound(); } } stage() { gotoxy(60,5); printf("U got %d points",n); sleep(1); gotoxy(60,5); printf(" "); } print() { px=random(636); py=random(460); if(px<10) px+=10; if(py<10) py+=10; outtextxy(px,py,"?"); } pause() { outtextxy(200,470,"< Press Any Key To Continue >"); getch(); setcolor(16); outtextxy(200,470,"< Press Any Key To Continue >"); setcolor(15); } esc() { gotoxy(20,18); printf(" THANK YOU "); gotoxy(20,20); printf(" < Press any key to continue > "); getch(); closegraph(); exit(0); }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi դ ? ??
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy


Google Groups Subscribe to SourceCodesWorld - Techies Talk

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!

ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page


Google Search


Source Codes is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions
Copyright ©2003-2017, All Rights Reserved.
Page URL:

Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review