home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff216.lzh / Wanderer / src / edit.c < prev    next >
C/C++ Source or Header  |  1989-06-02  |  5KB  |  227 lines

  1. #include "wand_head.h"
  2.  
  3. extern char *playscreen();
  4.  
  5. extern int debug_disp;
  6. extern char *edit_screen;
  7. extern char screen[NOOFROWS][ROWLEN+1];
  8.  
  9. static char *inst[] = { "O   Boulder",
  10.             "< > Arrows",
  11.             "^   Balloon",
  12.             ":   Earth",
  13.             "!   Landmine",
  14.             "*   Treasure",
  15.             "/ \\ Deflectors",
  16.             "+   Cage",
  17.             "= # Rock",
  18.             "T   Teleport",
  19.             "A   Arrival (1 max)",
  20.             "X   Exit (always 1)",
  21.             "@   Start (always 1)",
  22.             "M   Big Monster (1 max)",
  23.             "S   Baby Monster",
  24.             "-   Alternative space",
  25.             "C   Time Capsule",
  26.             NULL };
  27. /* Print instructions around the screen */
  28. void instruct()
  29. {
  30. int loop;
  31. for(loop = 0; inst[loop] ; loop++)
  32.     {
  33.     move(loop+1,55);
  34.     addstr(inst[loop]);
  35.     }
  36. move(20,0);
  37. addstr("Use wanderer keys to move. m = change no. of moves, p = play game\n");
  38. addstr("n = play game with full screen, q = quit, x = quit without save.");
  39. }
  40.  
  41. void noins()
  42. {
  43. int loop;
  44. for(loop =0; inst[loop] ; loop++)
  45.     {
  46.     move(loop+1,55);
  47.     addstr("                       ");
  48.     }
  49. move(20,0);
  50. addstr("                                                                            \n");
  51. addstr("                                                                            ");
  52. }
  53.  
  54. /* Actual edit function */
  55.  
  56. void editscreen(num,score,bell,maxmoves,keys)
  57. int  num, maxmoves,
  58.      *bell,
  59.      *score;
  60. char keys[10];
  61. {
  62. int  x,y,sx=0,sy=0,quit=0,nx,ny,nosave =0;
  63. char (*frow)[ROWLEN+1] = screen,
  64.      ch;
  65. char buffer[50];
  66. char *howdead;
  67.  
  68. for(x=0;x<=ROWLEN;x++)
  69.     for(y=0;y<NOOFROWS;y++)
  70.     {
  71.         if(screen[y][x] == '@')
  72.         {
  73.         sx = x;
  74.         sy = y;
  75.         }
  76.         if(screen[y][x] == '-')
  77.             screen[y][x] = ' ';
  78.         };
  79. x=sx;
  80. y=sy;
  81. if(maxmoves != 0)
  82. (void) sprintf(buffer,"Moves remaining = %d   ",maxmoves);
  83. else
  84. (void) strcpy(buffer,"     Unlimited moves     ");
  85. debug_disp=1;
  86. map(frow);
  87. move(18,0);
  88. addstr(buffer);
  89.  
  90. /* ACTUAL EDIT FUNCTION */
  91.  
  92. instruct();
  93. while(!quit)
  94. {
  95. move(y+1,x+1);
  96. refresh();
  97. cursor(1);
  98. ch = (char)getchar();
  99. cursor(0);
  100.  
  101. nx=x;
  102. ny=y;
  103.  
  104. if(ch == keys[3]||ch == keys[2]||ch == keys[1]||ch == keys[0])
  105.     {
  106.     if(ch == keys[3])
  107.         nx++;
  108.     if(ch == keys[2])
  109.         nx--;
  110.     if(ch == keys[1])
  111.         ny++;
  112.     if(ch == keys[0])
  113.             ny--;
  114.     }
  115. else if(ch == 'q')
  116.     {
  117.     noins();
  118.     break;
  119.     }
  120. else if(ch == 'x')
  121.     {
  122.     noins();
  123.     move(20,0);
  124.     addstr("You will lose any changes made this session - are you sure? (y/n)");
  125.     refresh();
  126.     ch = getch();
  127.     if(ch != 'y')
  128.     {
  129.     noins();
  130.     instruct();
  131.     refresh();
  132.         }
  133.     else
  134.     {
  135.     nosave = 1;
  136.     addstr("\n");
  137.     refresh();
  138.     break;
  139.         }
  140.     }
  141. else if(ch == 'm')              /* change to number of moves for the screen */
  142.     {
  143.     move(19,0);
  144.     addstr("How many moves for this screen? :");
  145.     refresh();echo();
  146.     gets(buffer);
  147.     noecho();
  148.     maxmoves = atoi(buffer);
  149.     if(maxmoves < 0 ) maxmoves = 0;
  150.     move(19,0);
  151.     addstr("                                           ");
  152.     if(maxmoves != 0)
  153.         (void) sprintf(buffer,"Moves remaining = %d   ",maxmoves);
  154.     else
  155.         (void) strcpy(buffer,"     Unlimited moves     ");
  156.     move(18,0);
  157.     addstr(buffer);
  158.     refresh();            /* for some reason, this seems to add a '.' to */
  159.               /* the map... Ive no idea why yet... */
  160.     }
  161. else if(ch == 'p' || ch == 'n')       /* play the game (test) */
  162.     {
  163.     noins();
  164.         wscreen(num,maxmoves);
  165.     if(ch == 'p')
  166.         {
  167.         debug_disp = 0;
  168.         clear();
  169.         }
  170.     *score = 0;
  171.     howdead = playscreen(&num,score,bell,maxmoves,keys);
  172.     move(20,0);
  173.     if(howdead!=0)
  174.         addstr(howdead);
  175.     else
  176.         addstr("DONE!");
  177.     printw("; hit any key to continue\n");
  178.     refresh();
  179.     ch = (char)getchar();
  180.     clear();
  181.     rscreen(num,&maxmoves);
  182.     debug_disp = 1;
  183.     map(frow);
  184.     instruct();
  185.     }
  186. else
  187.     {
  188.     if(ch >= 'a' && ch <= 'z') ch = ch - 'a' + 'A';
  189.     if(ch < ' ' || ch == (char)127) ch = '.';  /* no ctrl codes, thankyou */
  190.     if(ch == '"') ch = (char)getchar();
  191.     screen[y][x] = ch;
  192.     move(y+1,x+1);
  193.     draw_map_symbol(ch);
  194.     nx++;
  195.     }
  196. if(nx < 0)
  197.     {
  198.     nx = ROWLEN-1;
  199.     ny--;
  200.     }
  201. if(nx >= ROWLEN)
  202.     {
  203.     nx = 0;
  204.     ny++;
  205.     }
  206. if(ny < 0) ny = NOOFROWS-1;
  207. if(ny >= NOOFROWS) ny = 0;
  208. move(ny+1,nx+1);
  209. x=nx;
  210. y=ny;
  211. }
  212.  
  213. if(! nosave)
  214.     {
  215.     for(y = 0; y<=NOOFROWS;y++) /* certain editors - eg ded - have a */
  216.                                 /* habit of truncating trailing spaces*/
  217.                             /* so this should stop them! */
  218.         if(screen[y][ROWLEN-1] == ' ')
  219.         screen[y][ROWLEN-1] = '-';
  220.     wscreen(num,maxmoves);
  221.     }
  222. noins();
  223. move(20,0);
  224. refresh();
  225. }
  226.  
  227.