home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / wanderer2.t.Z / wanderer2.t / edit.c < prev    next >
C/C++ Source or Header  |  1988-11-23  |  4KB  |  222 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. ch = (char)getchar();
  98.  
  99. nx=x;
  100. ny=y;
  101.  
  102. if(ch == keys[3]||ch == keys[2]||ch == keys[1]||ch == keys[0])
  103.     {
  104.     if(ch == keys[3])
  105.         nx++;
  106.     if(ch == keys[2])
  107.         nx--;
  108.     if(ch == keys[1])
  109.         ny++;
  110.     if(ch == keys[0])
  111.             ny--;
  112.     }
  113. else if(ch == 'q')
  114.     {
  115.     noins();
  116.     break;
  117.     }
  118. else if(ch == 'x')
  119.     {
  120.     noins();
  121.     move(20,0);
  122.     addstr("You will lose any changes made this session - sre you sure? (y/n)");
  123.     refresh();
  124.     ch = getch();
  125.     if(ch != 'y')
  126.     {
  127.     noins();
  128.     instruct();
  129.     refresh();
  130.         }
  131.     else
  132.     {
  133.     nosave = 1;
  134.     addstr("\n");
  135.     refresh();
  136.     break;
  137.         }
  138.     }
  139. else if(ch == 'm')              /* change to number of moves for the screen */
  140.     {
  141.     move(19,0);
  142.     addstr("How many moves for this screen? :");
  143.     refresh();echo();
  144.     scanf("%d",&maxmoves);noecho();
  145.     if(maxmoves < 0 ) maxmoves = 0;
  146.     move(19,0);
  147.     addstr("                                           ");
  148.     if(maxmoves != 0)
  149.         (void) sprintf(buffer,"Moves remaining = %d   ",maxmoves);
  150.     else
  151.         (void) strcpy(buffer,"     Unlimited moves     ");
  152.     move(18,0);
  153.     addstr(buffer);
  154.     refresh();            /* for some reason, this seems to add a '.' to */
  155.               /* the map... Ive no idea why yet... */
  156.     }
  157. else if(ch == 'p' || ch == 'n')       /* play the game (test) */
  158.     {
  159.     noins();
  160.         wscreen(num,maxmoves);
  161.     if(ch == 'p')
  162.         {
  163.         debug_disp = 0;
  164.         clear();
  165.         }
  166.     *score = 0;
  167.     howdead = playscreen(&num,score,bell,maxmoves,keys);
  168.     move(20,0);
  169.     if(howdead!=0)
  170.         addstr(howdead);
  171.     else
  172.         addstr("DONE!");
  173.     printw("; hit any key to continue\n");
  174.     refresh();
  175.     ch = (char)getchar();
  176.     clear();
  177.     rscreen(num,&maxmoves);
  178.     debug_disp = 1;
  179.     map(frow);
  180.     instruct();
  181.     }
  182. else
  183.     {
  184.     if(ch >= 'a' && ch <= 'z') ch = ch - 'a' + 'A';
  185.     if(ch < ' ' || ch == (char)127) ch = '.';  /* no ctrl codes, thankyou */
  186.     if(ch == '"') ch = (char)getchar();
  187.     screen[y][x] = ch;
  188.     move(y+1,x+1);
  189.     addch(ch);
  190.     nx++;
  191.     }
  192. if(nx < 0)
  193.     {
  194.     nx = ROWLEN-1;
  195.     ny--;
  196.     }
  197. if(nx >= ROWLEN)
  198.     {
  199.     nx = 0;
  200.     ny++;
  201.     }
  202. if(ny < 0) ny = NOOFROWS-1;
  203. if(ny >= NOOFROWS) ny = 0;
  204. move(ny+1,nx+1);
  205. x=nx;
  206. y=ny;
  207. }
  208.  
  209. if(! nosave)
  210.     {
  211.     for(y = 0; y<=NOOFROWS;y++) /* certain editors - eg ded - have a */
  212.                                 /* habit of truncating trailing spaces*/
  213.                             /* so this should stop them! */
  214.         if(screen[y][ROWLEN-1] == ' ')
  215.         screen[y][ROWLEN-1] = '-';
  216.     wscreen(num,maxmoves);
  217.     }
  218. noins();
  219. move(20,0);
  220. refresh();
  221. }
  222.