home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************
- *
- * Snake
- *
- * Play snake. Control with '8' and '2' for up/down,
- * and '4' and '6' for left/right.
- *
- *********/
- {
- int view_lines=ReadInfo("view_lines");
- int view_columns=ReadInfo("view_columns");
- string text[view_lines+1];
- int col[4096], line[4096];
- int length=10, count, game=1, delay=0, points=0;
- int posy=view_lines/2, posx=view_columns/2, poscount=0;
- int yspeed=0, xspeed=1;
- int change;
- string key;
- int random1=posy, random2=posx, blipx, blipy;
- int increase=(view_lines+view_columns)/10+1;
- int cheat=0;
-
- CursorActive(0);
-
- for (count=view_columns-1; count>=0; count--) {
- text[1]+="*";
- text[2]+=" ";
- }
- text[view_lines]=text[1];
- text[2][0]='*';
- text[2][view_columns-1]='*';
-
- for (count=view_lines-1; count>1; count--)
- text[count]=text[2];
-
- text[view_lines/3][view_columns/2]='+';
-
- for (count=view_lines; count>0; count--)
- PrintLine(text[count], count);
-
- length=PromptInt("Length", 10, "Start length of your snake");
- if (length<0) {
- cheat=1;
- length=abs(length);
- }
- length++;
- points=length/5;
- Status(0, joinstr("Points: ", ltostr(points)));
- PrintLine("* Press a key to begin...", view_lines/2);
- GetKey(0);
-
- while (game) {
- random1+=random2-0x5431;
- random2+=random2^random1;
- key=GetKey(1);
- if (strlen(key)) {
- switch (key[0]) {
- case '8':
- yspeed=-1;
- xspeed=0;
- break;
- case '2':
- yspeed=1;
- xspeed=0;
- break;
- case '4':
- yspeed=0;
- xspeed=-1;
- break;
- case '6':
- yspeed=0;
- xspeed=1;
- break;
- default:
- length+=increase;
- increase++;
- points+=10;
- Status(0, joinstr("Points: ", ltostr(points)));
- break;
- }
- }
- change=line[(poscount-length)&4095];
- if (change>0)
- text[line[(poscount-length)&4095]][col[(poscount-length)&4095]]=' ';
- line[(poscount-length)&4095]=0;
- posy+=yspeed;
- posx+=xspeed;
- switch (text[posy][posx]) {
- default:
- if (cheat && text[posy][posx]=='o') {
- points-=110;
- }
- if (!cheat || points<0 || text[posy][posx]!='o') {
- game=0;
- break;
- }
- case '+':
- points+=10;
- Status(0, joinstr("Points: ", ltostr(points)));
- length+=increase;
- increase++;
- do {
- random1+=random2^0x12345431;
- random2+=random2-random1;
- blipx=abs((random1%(view_columns-2))+1);
- blipy=abs((random2%(view_lines-2))+1);
- } while (text[blipy][blipx]!=' ');
- text[blipy][blipx]='+';
- PrintLine(text[blipy], blipy);
- case ' ':
- text[posy][posx]='o';
- col[poscount]=posx;
- line[poscount]=posy;
- PrintLine(text[posy], posy);
- if (change>0)
- PrintLine(text[change], change);
- poscount=(poscount+1)&4095;
- break;
- }
- }
- Request(joinstr("Points: ", ltostr(points), " "), "Game Over!", "I'm too stupid!");
- RedrawScreen(0);
- while (strlen(GetKey(1)));
- }
-
-
-