Snake game.c
#include<STDLIB.H> #include<stdio.h> #include<conio.h> #include<time.h> int height =23 ,width =78,x,y,fruitx,fruity,score,gameend,flag; int tailx[100],taily[100]; int piece=0; //x = height and y= width void makelogic(){ int i ; int prevx,prevy,prev2x,prev2y; prevx=tailx[0]; prevy=taily[0]; tailx[0]=x; taily[0]=y; for(i =1;i <=piece;i++){ prev2x=tailx[i]; prev2y=taily[i]; tailx[i]=prevx; taily[i]=prevy; prevx=prev2x; prevy=prev2y; } switch(flag){ case 1: x--; break; case 2: x++; break; case 3: y--; break; case 4: y++; break; } if(x==0||y==0||x==height||y==width){ gameend = 1; } if(x==fruitx && y == fruity){ label3: fruitx = rand ()%23 ; if (fruitx==0){ goto label3; } label4: fruity = rand ()%78 ; if (fruity==0) goto label4; score++; piece++; } } void input(){ ...
Comments
Post a Comment