C Code For Snake Game

Snake

HTML Game code – If you have been looking for the HTML Game code to make Snake Game in notepad easily, then you are on the right page.

In fact, it is so easy to make Snake game in Notepad with just HTML code. You will basically be able to make the game in just 2 minutes.

C Games and Graphics Code Examples Snake Game Source Code in C C Sample Code Display Arrays Print Arrays C program will let you understand that how to print an array in C. Declare and define one array and then loop upto the length of array. At each iteration we shall print one index. The C Language While Loop Statement. Basic Snake HTML Game. Snake is a fun game to make as it doesn't require a lot of code (less than 100 lines with all comments removed). This is a basic implementation of the snake game, but it's missing a few things intentionally and they're left as further exploration for the reader.

The best part?

You don’t need any knowledge of coding/programming to do it. Everything has been done for you, including the CSS and JavaScript.

All you need is to copy and paste the HTML game code below and you can start playing for free!

PS: The notepad snake game code PDF is also available at the end of the article for future use.

Sweet right? Let’s start right away.

HTML Game Code to Make Snake Game In Notepad

I have also created a video tutorial if you prefer that, watch it below:

First, copy the code below.

Next, open note pad on your PC and paste the code.

Click CTRL + S to save the code.

Under file type, select All file, and save as .html.

NOTE: Whatever name you give to your game, make sure you save as .html.

Now, you can go to the folder where you saved the code file and open it with any browser that supports HTML 5.

Recommended browsers: Chrome/Firefox.

Enjoy!

Anyways, you can also download and copy the code in the Notepad snake game code PDF below.

If you found the article helpful, don’t forget to share by using the share buttons below.

Feel free to drop a comment below.

# include <stdio.h>
# include <graphics.h>

Snake In C

# include <stdlib.h>
# include <dos.h>
# include <conio.h>
int gdriver=DETECT,gmode,x1=0,y1=0,x2,y2,k=0,c,a,i=0;
int bufx[150],bufy[150],dist=7,delayspeed=100,d;
int rndx,rndy,tail=2,size,dash=0;C Code For Snake Game
int life=5;
int choice;
void randomnumber(void);
void move(int a);
void statusbar(void);
void main()
{
// registerfarbgidriver(EGAVGA_driver_far);
initgraph(&gdriver,&gmode,'c:tcbgi');
size=tail;
cleardevice();
printf('Devlopped By IDEAL BERG');
printf('Enter the speed:: n<1> for slow <2> for slower <3> for slowestn<4> for normaln<5> for fast <6> for faster <7> for fastest');
scanf('%d',&choice);
switch(choice)
{
case 1: delayspeed=250;break;
case 2: delayspeed=200;break;
case 3: delayspeed=160;break;
case 4: delayspeed=90;break;
case 5: delayspeed=60;break;
case 6: delayspeed=40;break;
case 7: delayspeed=20;break;
};
cleardevice();
randomnumber();
bar3d(rndx,rndy,rndx+dist,rndy+dist,0,0);
statusbar();
while((c=getch())!='033')
{
if (c'115') a=1;
if (c'113') a=2;
if (c'120') a=3;
if (c'110') a=4;
dash=0;
move(a);
}
}
void move(int a)
{
void checkcollision(int x1,int y1);
void checkcapture(int x1,int y1);
while(!kbhit())
{
if (!dash)
{
k=k++%size;
i++;
setfillstyle(1,7);
bar3d(x1,y1,x1+dist,y1+dist,0,0);
if(i>=size) // Style start
{
setfillstyle(0,0);
Gamesetcolor(0);
bar3d(bufx[k],bufy[k],bufx[k]+dist,bufy[k]+dist,0,0);
bufx[k]=x1;
bufy[k]=y1;
setcolor(15);
checkcapture(x1,y1);
}
else
{
bufx[1]=x1;
bufy[1]=y1;
}
if(a1) x1=x1+dist;
if(a2) x1=x1-dist;
if(a3) y1=y1+dist;
if(a4) y1=y1-dist;
checkcollision(x1,y1);
setfillstyle(1,14);
bar3d(x1,y1,x1+dist,y1+dist,0,0);
sound(300);
delay(delayspeed);
nosound();
delay(delayspeed);
}
}
}
void checkcollision(int x1,int y1)
{
int i;
for(i=1;i<=size;i++) if((bufx[i]x1)&&(bufy[i]y1)) dash=1; if((x1<0)||(x1>=400)||(y1<0)||(y1>400)) dash=1;
if(dash)
{
if(--life<0) exit(0); sound(700); delay(300); nosound(); if(size>25) life++;size=tail;
cleardevice();
}
statusbar();
}
void checkcapture(int x1,int y1)
{
int i;
if((x1rndx)&&(y1rndy))
{
size++;
sound(500);
delay(100);
randomnumber();
}
setfillstyle(11,14);
bar3d(rndx,rndy,rndx+dist,rndy+dist,0,0);
}
void statusbar()

C++ Code For Snake Games


{
char s[10];
s[1]=life;
setcolor(15);
rectangle(0,0,400,400);
gotoxy(55,2);
printf('Life: %d size: %d',life,size);
gotoxy(55,5);
printf('Down: ');
putchar(31);
printf('tUP');
putchar(30);
gotoxy(55,6);
printf('RIGHT :');
putchar(16);
printf('tLEFT :');
putchar(17);
}
void randomnumber()
{
int i,j;
randomize();
i=random(10000)%40;
i=i*dist;
j=random(10000)%40;
j=j*dist;
rndx=i;
rndy=j;
}
Kerala IT companies - webdevelopment webhosting application development Cochin