home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / DVD!FX17.LHA / FrexxEd / fpl / Snake.FPL < prev    next >
Encoding:
Text File  |  1994-11-18  |  3.0 KB  |  127 lines

  1. /***********************************************************
  2.  *
  3.  *  Snake
  4.  *
  5.  *  Play snake.  Control with '8' and '2' for up/down,
  6.  *               and '4' and '6' for left/right.
  7.  *
  8.  *********/
  9. {
  10.   int view_lines=ReadInfo("view_lines");
  11.   int view_columns=ReadInfo("view_columns");
  12.   string text[view_lines+1];
  13.   int col[4096], line[4096];
  14.   int length=10, count, game=1, delay=0, points=0;
  15.   int posy=view_lines/2, posx=view_columns/2, poscount=0;
  16.   int yspeed=0, xspeed=1;
  17.   int change;
  18.   string key;
  19.   int random1=posy, random2=posx, blipx, blipy;
  20.   int increase=(view_lines+view_columns)/10+1;
  21.   int cheat=0;
  22.  
  23.   CursorActive(0);
  24.  
  25.   for (count=view_columns-1; count>=0; count--) {
  26.     text[1]+="*";
  27.     text[2]+=" ";
  28.   }
  29.   text[view_lines]=text[1];
  30.   text[2][0]='*';
  31.   text[2][view_columns-1]='*';
  32.  
  33.   for (count=view_lines-1; count>1; count--)
  34.     text[count]=text[2];
  35.  
  36.   text[view_lines/3][view_columns/2]='+';
  37.  
  38.   for (count=view_lines; count>0; count--)
  39.     PrintLine(text[count], count);
  40.  
  41.   length=PromptInt("Length", 10, "Start length of your snake");
  42.   if (length<0) {
  43.     cheat=1;
  44.     length=abs(length);
  45.   }
  46.   length++;
  47.   points=length/5;
  48.   Status(0, joinstr("Points: ", ltostr(points)));
  49.   PrintLine("* Press a key to begin...", view_lines/2);
  50.   GetKey(0);
  51.  
  52.   while (game) {
  53.     random1+=random2-0x5431;
  54.     random2+=random2^random1;
  55.     key=GetKey(1);
  56.     if (strlen(key)) {
  57.       switch (key[0]) {
  58.       case '8':
  59.         yspeed=-1;
  60.         xspeed=0;
  61.         break;
  62.       case '2':
  63.         yspeed=1;
  64.         xspeed=0;
  65.         break;
  66.       case '4':
  67.         yspeed=0;
  68.         xspeed=-1;
  69.         break;
  70.       case '6':
  71.         yspeed=0;
  72.         xspeed=1;
  73.         break;
  74.       default:
  75.         length+=increase;
  76.         increase++;
  77.         points+=10;
  78.         Status(0, joinstr("Points: ", ltostr(points)));
  79.         break;
  80.       }
  81.     }
  82.     change=line[(poscount-length)&4095];
  83.     if (change>0)
  84.       text[line[(poscount-length)&4095]][col[(poscount-length)&4095]]=' ';
  85.     line[(poscount-length)&4095]=0;
  86.     posy+=yspeed;
  87.     posx+=xspeed;
  88.     switch (text[posy][posx]) {
  89.     default:
  90.       if (cheat && text[posy][posx]=='o') {
  91.         points-=110;
  92.       }
  93.       if (!cheat || points<0 || text[posy][posx]!='o') {
  94.         game=0;
  95.         break;
  96.       }
  97.     case '+':
  98.       points+=10;
  99.       Status(0, joinstr("Points: ", ltostr(points)));
  100.       length+=increase;
  101.       increase++;
  102.       do {
  103.         random1+=random2^0x12345431;
  104.         random2+=random2-random1;
  105.         blipx=abs((random1%(view_columns-2))+1);
  106.         blipy=abs((random2%(view_lines-2))+1);
  107.       } while (text[blipy][blipx]!=' ');
  108.       text[blipy][blipx]='+';
  109.       PrintLine(text[blipy], blipy);
  110.     case ' ':
  111.       text[posy][posx]='o';
  112.       col[poscount]=posx;
  113.       line[poscount]=posy;
  114.       PrintLine(text[posy], posy);
  115.       if (change>0)
  116.         PrintLine(text[change], change);
  117.       poscount=(poscount+1)&4095;
  118.       break;
  119.     }
  120.   }
  121.   Request(joinstr("Points: ", ltostr(points), "  "), "Game Over!", "I'm too stupid!");
  122.   RedrawScreen(0);
  123.   while (strlen(GetKey(1)));
  124. }
  125.  
  126.  
  127.