home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / TextEditors&Viewers / Texteditors / FFRED10.LHA / fpl / Snake.FPL < prev    next >
Encoding:
Text File  |  1994-09-22  |  3.0 KB  |  125 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.   for (count=view_columns-1; count>=0; count--) {
  24.     text[1]+="*";
  25.     text[2]+=" ";
  26.   }
  27.   text[view_lines]=text[1];
  28.   text[2][0]='*';
  29.   text[2][view_columns-1]='*';
  30.  
  31.   for (count=view_lines-1; count>1; count--)
  32.     text[count]=text[2];
  33.  
  34.   text[view_lines/3][view_columns/2]='+';
  35.  
  36.   for (count=view_lines; count>0; count--)
  37.     PrintLine(text[count], count);
  38.  
  39.   length=PromptInt("Length", 10, "Start length of your snake");
  40.   if (length<0) {
  41.     cheat=1;
  42.     length=abs(length);
  43.   }
  44.   length++;
  45.   points=length/5;
  46.   Status(0, joinstr("Points: ", ltostr(points)));
  47.   PrintLine("* Press a key to begin...", view_lines/2);
  48.   GetKey(0);
  49.  
  50.   while (game) {
  51.     random1+=random2-0x5431;
  52.     random2+=random2^random1;
  53.     key=GetKey(1);
  54.     if (strlen(key)) {
  55.       switch (key[0]) {
  56.       case '8':
  57.         yspeed=-1;
  58.         xspeed=0;
  59.         break;
  60.       case '2':
  61.         yspeed=1;
  62.         xspeed=0;
  63.         break;
  64.       case '4':
  65.         yspeed=0;
  66.         xspeed=-1;
  67.         break;
  68.       case '6':
  69.         yspeed=0;
  70.         xspeed=1;
  71.         break;
  72.       default:
  73.         length+=increase;
  74.         increase++;
  75.         points+=10;
  76.         Status(0, joinstr("Points: ", ltostr(points)));
  77.         break;
  78.       }
  79.     }
  80.     change=line[(poscount-length)&4095];
  81.     if (change>0)
  82.       text[line[(poscount-length)&4095]][col[(poscount-length)&4095]]=' ';
  83.     line[(poscount-length)&4095]=0;
  84.     posy+=yspeed;
  85.     posx+=xspeed;
  86.     switch (text[posy][posx]) {
  87.     default:
  88.       if (cheat && text[posy][posx]=='o') {
  89.         points-=110;
  90.       }
  91.       if (!cheat || points<0 || text[posy][posx]!='o') {
  92.         game=0;
  93.         break;
  94.       }
  95.     case '+':
  96.       points+=10;
  97.       Status(0, joinstr("Points: ", ltostr(points)));
  98.       length+=increase;
  99.       increase++;
  100.       do {
  101.         random1+=random2^0x12345431;
  102.         random2+=random2-random1;
  103.         blipx=abs((random1%(view_columns-2))+1);
  104.         blipy=abs((random2%(view_lines-2))+1);
  105.       } while (text[blipy][blipx]!=' ');
  106.       text[blipy][blipx]='+';
  107.       PrintLine(text[blipy], blipy);
  108.     case ' ':
  109.       text[posy][posx]='o';
  110.       col[poscount]=posx;
  111.       line[poscount]=posy;
  112.       PrintLine(text[posy], posy);
  113.       if (change>0)
  114.         PrintLine(text[change], change);
  115.       poscount=(poscount+1)&4095;
  116.       break;
  117.     }
  118.   }
  119.   Request(joinstr("Points: ", ltostr(points), "  "), "Game Over!", "I'm too stupid!");
  120.   RedrawScreen(0);
  121.   while (strlen(GetKey(1)));
  122. }
  123.  
  124.  
  125.