#include <allegro.h>/*80x24 Snake by James Stanley - for the #maximilian thing*/
volatile int t;void c(void){t++;}int main(){int b,i,x,y,e=2,s=0,d=1,l=2,a=95,D=1
,v[64][2]={{20,15},{20,14},{20,13}},f[4]={10,10,0,0};allegro_init();srand(time(0
)) ;install_timer( ) ;install_keyboard( ) ;LOCK_VARIABLE(t ) ;LOCK_FUNCTION( c);
set_color_depth(24);set_window_title("80x24 Snake");set_gfx_mode(2,320,240,0,0);
b=create_bitmap(320, 240);install_int(c,100);while(!key[59]){if(t){t--;s--;if(s<
0)s=e;e--;if(e<0)e=l;switch(d){case 0:v[e][1]=v[s][1]-1;if(v[e][1]<0)v[e][1]=29;
v[e][0]=v[s][0];break;case 1:v[e][1]=v[s][1]+1;if(v[e][1]>29)v[e][1]=0;v[e][0]=v
[s][0];break;case 2:v[e][0]=v[s][0]-1;if(v[e] [0]<0)v[e][0]=39;v[e][1]=v[s][ 1];
break;case 3:v[e][0]=v[s][0]+1;if(v[e][0]>39)v[e][0]=0;v[e][1]=v[s][1];break;}if
(key[84]&&(d!=1))d=0;else if(key[85]&&d)d=1;else if(key[82]&&(d!=3))d=2;else if(
key[83]&&(d!=2))d=3;if(D)a--;else a++;if(a>94)D=1;if(!a)D=0;if((v[s][0]==f[0])&&
(v[s][1]==f[1])){if(l<62)l++;v[l][0]=f[0];v[l][1]=f[1];f[2]=f[0];f[3]=f[1];f[0]=
rand()%40;f[1]=rand()%30;}}else{clear_bitmap(b);for(y=0;y<30;y++){for(x=0;x<40;x
++){rectfill(b,8*x,8*y,8*x+8,8*y+8,makecol(a+4*x,v[s][1]*8,6*y));}}rectfill(b,8*
f[0]+1,8*f[1]+1,8*f[0]+7,8*f[1]+7,makecol(0,95+4*f[0],(95-a)+4*f[ 1]));for(i=0;i
<=l;i++){rectfill(b,8*v[i][0]+1,8*v[i][1]+1,8*v[i][0]+7,8*v[i][1]+7,makecol(6*v[
i] [0 ],(95 -a)+ 4*v[i][1],a+150/ l*i));}for(i=0;i<=l;i ++ ){if(i!=s){if(( v[ i]
[0 ]!=f[ 2]) || (v[i] [1]!=f[3])){ if((v [s][0]== v[i][0])&&(v[s][1]==v[i][1])){
textprintf_centre_ex(screen,font,160,120,0,-1,"GAME OVER - Length %d - Press an\
y key",l);clear_keybuf();readkey();exit(0);}}}}textprintf_ex(b,font,8,8,0,-1,"L\
ength: %d",l);textout_ex(b,font,"80x24 Snake by James Stanley",8,224,makecol(v[s
][0]*6,65+a*2,0),-1);blit(b, screen,0,0, 0,0, 320,240);}}return 0;}END_OF_MAIN()
/*     Use  your  arrow  keys  to  control  the  snake  and  ESC  to  quit    */