increase snake length [closed]
-6
#include<graphics.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
const int width=600, height=950; int snakex[100],snakey[100],prevx,prevy,nextx,nexty,count=0,score=0;
int fx,fy , i , j ,k; int ci=250,cj=250,x=0,y=-1,ch,a=1 , c , w ;
main() {
fx=(rand()%886); fy=(rand()%485); initwindow (height,width); setcolor(WHITE);
while(a)
//infiniteloop
{
rectangle(11,11,889,489);
rectangle(12,12,888,488);
rectangle(13,13,887,487); rectangle(14,14,886,486); line(263,334,603,334);
line(263,335,603,335); line(263,336,603,336);
line(263,134,603,134); line(263,135,603,135); line(263,136,603,136);
prevx=snakex[0]; prevy=snakey[0]; snakex[0]=ci; snakey[0]=cj; for(i=1;i<count;c++) { nextx=snakex[i]; nexty=snakey[i];
snakex[i]=prevx; snakey[i]=prevy; prevx=nextx; prevy=nexty;
}
outtextxy(fx, fy, "@");
outtextxy(snakex[0],snakey[0],"O");
if(kbhit()) //check if a key is pressed
{
ch=getch();
if(ch==72) //move upward
{
x=0;
y=-1;
}
if(ch==75) //move left
{
x=-1;
y=0;
}
if(ch==77) //move right
{
x=1;
y=0;
}
if(ch==80) //move downward
{
x=0;
y=1;
}
}
if (ci<16||ci>880||cj<16||cj>480||(ci>=264&&ci<=603&&cj==136)||(ci>=264&&ci<=603&&cj==336))
{
a=0; }
if((ci==fx&&cj==fy) || (ci==fy&&cj==fx))
{
fx=(rand()%886);
fy=(rand()%485);
outtextxy(fx, fy, "@");
for(j=0;j<count;j++)
{
if(ci==snakex[k]&&j==snakey[k])
outtextxy(snakex[k],snakey[k],"O");
}
score=score+10;
count++;
outtextxy(900,500,"score = ");
outtextxy(snakex[w],snakey[w],"o");
}
ci=ci+x;
cj=cj+y;
delay(1);
cleardevice();
} }
c++
New contributor
future programmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
closed as off-topic by πάντα ῥεῖ, t3chb0t, Mast, Graipher, 1201ProgramAlarm Dec 23 at 19:39
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – πάντα ῥεῖ, t3chb0t, Mast, Graipher, 1201ProgramAlarm
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
-6
#include<graphics.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
const int width=600, height=950; int snakex[100],snakey[100],prevx,prevy,nextx,nexty,count=0,score=0;
int fx,fy , i , j ,k; int ci=250,cj=250,x=0,y=-1,ch,a=1 , c , w ;
main() {
fx=(rand()%886); fy=(rand()%485); initwindow (height,width); setcolor(WHITE);
while(a)
//infiniteloop
{
rectangle(11,11,889,489);
rectangle(12,12,888,488);
rectangle(13,13,887,487); rectangle(14,14,886,486); line(263,334,603,334);
line(263,335,603,335); line(263,336,603,336);
line(263,134,603,134); line(263,135,603,135); line(263,136,603,136);
prevx=snakex[0]; prevy=snakey[0]; snakex[0]=ci; snakey[0]=cj; for(i=1;i<count;c++) { nextx=snakex[i]; nexty=snakey[i];
snakex[i]=prevx; snakey[i]=prevy; prevx=nextx; prevy=nexty;
}
outtextxy(fx, fy, "@");
outtextxy(snakex[0],snakey[0],"O");
if(kbhit()) //check if a key is pressed
{
ch=getch();
if(ch==72) //move upward
{
x=0;
y=-1;
}
if(ch==75) //move left
{
x=-1;
y=0;
}
if(ch==77) //move right
{
x=1;
y=0;
}
if(ch==80) //move downward
{
x=0;
y=1;
}
}
if (ci<16||ci>880||cj<16||cj>480||(ci>=264&&ci<=603&&cj==136)||(ci>=264&&ci<=603&&cj==336))
{
a=0; }
if((ci==fx&&cj==fy) || (ci==fy&&cj==fx))
{
fx=(rand()%886);
fy=(rand()%485);
outtextxy(fx, fy, "@");
for(j=0;j<count;j++)
{
if(ci==snakex[k]&&j==snakey[k])
outtextxy(snakex[k],snakey[k],"O");
}
score=score+10;
count++;
outtextxy(900,500,"score = ");
outtextxy(snakex[w],snakey[w],"o");
}
ci=ci+x;
cj=cj+y;
delay(1);
cleardevice();
} }
c++
New contributor
future programmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
closed as off-topic by πάντα ῥεῖ, t3chb0t, Mast, Graipher, 1201ProgramAlarm Dec 23 at 19:39
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – πάντα ῥεῖ, t3chb0t, Mast, Graipher, 1201ProgramAlarm
If this question can be reworded to fit the rules in the help center, please edit the question.
I ran your code through visual studio's auto-formatting, but this is still far from perfect. Please fix the indentation. Please also add a description of your code, see: codereview.stackexchange.com/help/how-to-ask
– user673679
Dec 23 at 17:35
3
@user673679 Next time, don't modify the code in the question but review the indentation/formatting/etc in an answer. It's a perfectly reviewable point to make and it's important reviewers see the code in it's native form.
– Mast
Dec 23 at 18:22
add a comment |
-6
-6
-6
#include<graphics.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
const int width=600, height=950; int snakex[100],snakey[100],prevx,prevy,nextx,nexty,count=0,score=0;
int fx,fy , i , j ,k; int ci=250,cj=250,x=0,y=-1,ch,a=1 , c , w ;
main() {
fx=(rand()%886); fy=(rand()%485); initwindow (height,width); setcolor(WHITE);
while(a)
//infiniteloop
{
rectangle(11,11,889,489);
rectangle(12,12,888,488);
rectangle(13,13,887,487); rectangle(14,14,886,486); line(263,334,603,334);
line(263,335,603,335); line(263,336,603,336);
line(263,134,603,134); line(263,135,603,135); line(263,136,603,136);
prevx=snakex[0]; prevy=snakey[0]; snakex[0]=ci; snakey[0]=cj; for(i=1;i<count;c++) { nextx=snakex[i]; nexty=snakey[i];
snakex[i]=prevx; snakey[i]=prevy; prevx=nextx; prevy=nexty;
}
outtextxy(fx, fy, "@");
outtextxy(snakex[0],snakey[0],"O");
if(kbhit()) //check if a key is pressed
{
ch=getch();
if(ch==72) //move upward
{
x=0;
y=-1;
}
if(ch==75) //move left
{
x=-1;
y=0;
}
if(ch==77) //move right
{
x=1;
y=0;
}
if(ch==80) //move downward
{
x=0;
y=1;
}
}
if (ci<16||ci>880||cj<16||cj>480||(ci>=264&&ci<=603&&cj==136)||(ci>=264&&ci<=603&&cj==336))
{
a=0; }
if((ci==fx&&cj==fy) || (ci==fy&&cj==fx))
{
fx=(rand()%886);
fy=(rand()%485);
outtextxy(fx, fy, "@");
for(j=0;j<count;j++)
{
if(ci==snakex[k]&&j==snakey[k])
outtextxy(snakex[k],snakey[k],"O");
}
score=score+10;
count++;
outtextxy(900,500,"score = ");
outtextxy(snakex[w],snakey[w],"o");
}
ci=ci+x;
cj=cj+y;
delay(1);
cleardevice();
} }
c++
New contributor
future programmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
#include<graphics.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
const int width=600, height=950; int snakex[100],snakey[100],prevx,prevy,nextx,nexty,count=0,score=0;
int fx,fy , i , j ,k; int ci=250,cj=250,x=0,y=-1,ch,a=1 , c , w ;
main() {
fx=(rand()%886); fy=(rand()%485); initwindow (height,width); setcolor(WHITE);
while(a)
//infiniteloop
{
rectangle(11,11,889,489);
rectangle(12,12,888,488);
rectangle(13,13,887,487); rectangle(14,14,886,486); line(263,334,603,334);
line(263,335,603,335); line(263,336,603,336);
line(263,134,603,134); line(263,135,603,135); line(263,136,603,136);
prevx=snakex[0]; prevy=snakey[0]; snakex[0]=ci; snakey[0]=cj; for(i=1;i<count;c++) { nextx=snakex[i]; nexty=snakey[i];
snakex[i]=prevx; snakey[i]=prevy; prevx=nextx; prevy=nexty;
}
outtextxy(fx, fy, "@");
outtextxy(snakex[0],snakey[0],"O");
if(kbhit()) //check if a key is pressed
{
ch=getch();
if(ch==72) //move upward
{
x=0;
y=-1;
}
if(ch==75) //move left
{
x=-1;
y=0;
}
if(ch==77) //move right
{
x=1;
y=0;
}
if(ch==80) //move downward
{
x=0;
y=1;
}
}
if (ci<16||ci>880||cj<16||cj>480||(ci>=264&&ci<=603&&cj==136)||(ci>=264&&ci<=603&&cj==336))
{
a=0; }
if((ci==fx&&cj==fy) || (ci==fy&&cj==fx))
{
fx=(rand()%886);
fy=(rand()%485);
outtextxy(fx, fy, "@");
for(j=0;j<count;j++)
{
if(ci==snakex[k]&&j==snakey[k])
outtextxy(snakex[k],snakey[k],"O");
}
score=score+10;
count++;
outtextxy(900,500,"score = ");
outtextxy(snakex[w],snakey[w],"o");
}
ci=ci+x;
cj=cj+y;
delay(1);
cleardevice();
} }
c++
c++
New contributor
future programmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
future programmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Dec 23 at 19:07
Graipher
23.5k53585
23.5k53585
New contributor
future programmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Dec 23 at 16:49
future programmer
1
1
New contributor
future programmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
future programmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
future programmer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
closed as off-topic by πάντα ῥεῖ, t3chb0t, Mast, Graipher, 1201ProgramAlarm Dec 23 at 19:39
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – πάντα ῥεῖ, t3chb0t, Mast, Graipher, 1201ProgramAlarm
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by πάντα ῥεῖ, t3chb0t, Mast, Graipher, 1201ProgramAlarm Dec 23 at 19:39
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – πάντα ῥεῖ, t3chb0t, Mast, Graipher, 1201ProgramAlarm
If this question can be reworded to fit the rules in the help center, please edit the question.
I ran your code through visual studio's auto-formatting, but this is still far from perfect. Please fix the indentation. Please also add a description of your code, see: codereview.stackexchange.com/help/how-to-ask
– user673679
Dec 23 at 17:35
3
@user673679 Next time, don't modify the code in the question but review the indentation/formatting/etc in an answer. It's a perfectly reviewable point to make and it's important reviewers see the code in it's native form.
– Mast
Dec 23 at 18:22
add a comment |
I ran your code through visual studio's auto-formatting, but this is still far from perfect. Please fix the indentation. Please also add a description of your code, see: codereview.stackexchange.com/help/how-to-ask
– user673679
Dec 23 at 17:35
3
@user673679 Next time, don't modify the code in the question but review the indentation/formatting/etc in an answer. It's a perfectly reviewable point to make and it's important reviewers see the code in it's native form.
– Mast
Dec 23 at 18:22
I ran your code through visual studio's auto-formatting, but this is still far from perfect. Please fix the indentation. Please also add a description of your code, see: codereview.stackexchange.com/help/how-to-ask
– user673679
Dec 23 at 17:35
I ran your code through visual studio's auto-formatting, but this is still far from perfect. Please fix the indentation. Please also add a description of your code, see: codereview.stackexchange.com/help/how-to-ask
– user673679
Dec 23 at 17:35
3
3
@user673679 Next time, don't modify the code in the question but review the indentation/formatting/etc in an answer. It's a perfectly reviewable point to make and it's important reviewers see the code in it's native form.
– Mast
Dec 23 at 18:22
@user673679 Next time, don't modify the code in the question but review the indentation/formatting/etc in an answer. It's a perfectly reviewable point to make and it's important reviewers see the code in it's native form.
– Mast
Dec 23 at 18:22
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
I ran your code through visual studio's auto-formatting, but this is still far from perfect. Please fix the indentation. Please also add a description of your code, see: codereview.stackexchange.com/help/how-to-ask
– user673679
Dec 23 at 17:35
3
@user673679 Next time, don't modify the code in the question but review the indentation/formatting/etc in an answer. It's a perfectly reviewable point to make and it's important reviewers see the code in it's native form.
– Mast
Dec 23 at 18:22