// Snake // c Alex Kizub 8 March 2003 akizub@yahoo.com // Freeware // For my lovely daughter Lisa! #define left 7 #define right 8 #define end 0 #define direction 8 #define minx 4 #define miny 20 #define maxx 156 #define maxy 156 #define hit 20 #define around 16 #define bufer 8192 // 0 1 2 3 4 5 6 7 int ddx[direction]={1, 1, 0,-1,-1,-1,0,1}; int ddy[direction]={0,-1,-1,-1, 0, 1,1,1}; int dd=4; // start direction int x,y,oldX,oldY,k,e,px,py,pb,score; int shot=hit; pointer m; string s = ""; int sn=0; int xaround[around],yaround[around]; int iaround,iinsert; int snake_length; whereXY() { py=y%8; px=x*32+y/8; pb= 1<0) { x=xaround[iaround]; y=yaround[iaround]; xaround[iaround]=0; aroundXY(); } } } main() { if(dbopen("dsnake")) { s=dbread("s"); sn=dbread("i"); dbclose(); } hookhard(1); graph_on(); m=malloct(bufer,"c"); if (!m){ alert ("No memory! Try again :-)"); exit(); } while (getsd("Want to play?",s+" "+sn)) { title("Wait and relax for a moment..."); clearg(); for (iinsert=0;iinsert6&e<11) k=e; if (k==left) { if (dd0) dd--; else dd=direction-1; } k=0; oldX=x;oldY=y; // shot if (shot-- < 0 ) { beep(2); score++; snake_length=2; shot=random(hit); x=random(maxx-minx)+minx; y=random(maxy-miny)+miny; whereXY(); m[px]=m[px]|pb; x++;y++; whereXY(); m[px]=m[px]|pb; line (1,x,y,--x,--y); x=oldX;y=oldY; } if (--snake_length < 0 ) { lookaroundXY(); x=oldX;y=oldY; snake_length=0; } x=x+ddx[dd]; y=y+ddy[dd]; line(1,oldX,oldY,x,y); if (x==minx||x==maxx||y==miny||y==maxy) e=2; whereXY(); if ((m[px]&pb)) e=2; else m[px]=m[px]|pb; title("Score "+score); } while (e!=2); alert("Your score is "+score+ "\n Highest score was "+sn+ " for "+s); free(m); if(score>sn) { s=gets("What is your name?"); if(dbcreate("dsnake")){ dbwrite(s); dbwrite(score); dbclose(); }} } sleep(5000); hookhard(0); }