home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume13 / xsokoban2 / part02 / showscreen.c < prev    next >
C/C++ Source or Header  |  1992-01-13  |  6KB  |  221 lines

  1. #include <stdio.h>
  2. #include <curses.h>
  3. #include "sokoban.h"
  4.  
  5. extern short rows, cols, level, moves, pushes, packets, savepack;
  6. extern char  map[MAXROW+1][MAXCOL+1];
  7.  
  8. showscreen() {
  9.  
  10.    register short i, j;
  11.  
  12.    move( 0, 0); clrtobot();
  13.    for( i = 0; i < rows; i++)
  14.       for( j = 0; map[i][j] != '\0'; j++)
  15.          mapchar( map[i][j], i, j);
  16.    move( MAXROW, 0);
  17.    printw( "Level:      Packets:      Saved:      Moves:       Pushes:");
  18.    displevel();
  19.    disppackets();
  20.    dispsave();
  21.    dispmoves();
  22.    disppushes();
  23.    move( MAXROW+2,0);
  24.    refresh();
  25. }
  26.  
  27. mapchar( c, i, j) 
  28. register char c; 
  29. register short i, j;
  30. {
  31.    OBJECT *obj, *get_obj_adr();
  32.    register short offset_row = (MAXROW - rows) / 2;
  33.    register short offset_col = MAXCOL - cols;
  34.  
  35.    obj = get_obj_adr( c);
  36.  
  37.    if( obj->invers) standout();
  38.    move( i + offset_row, 2*j + offset_col); 
  39.    printw( "%c%c", obj -> obj_display, obj -> obj_display);
  40.    if( obj->invers) standend();
  41. }
  42.  
  43. OBJECT *get_obj_adr( c)
  44. register char c;
  45. {
  46.    register OBJECT *ret;
  47.  
  48.    if(      c == player.obj_intern)        ret = &player;
  49.    else if( c == playerstore.obj_intern)    ret = &playerstore;
  50.    else if( c == store.obj_intern)        ret = &store;
  51.    else if( c == save.obj_intern)        ret = &save;
  52.    else if( c == packet.obj_intern)        ret = &packet;
  53.    else if( c == wall.obj_intern)        ret = &wall;
  54.    else if( c == ground.obj_intern)        ret = &ground;
  55.    else                                         ret = &ground;
  56.  
  57.    return( ret);
  58. }
  59.  
  60.  
  61. displevel() { 
  62.    move( MAXROW, 7); printw( "%3d", level); 
  63. }
  64.    
  65. disppackets() { 
  66.    move( MAXROW, 21); printw( "%3d", packets); 
  67. }
  68.    
  69. dispsave() { 
  70.    move( MAXROW, 33); printw( "%3d", savepack); 
  71. }
  72.    
  73. dispmoves() { 
  74.    move( MAXROW, 45); printw( "%5d", moves); 
  75. }
  76.       
  77. disppushes() { 
  78.    move( MAXROW, 59); printw( "%5d", pushes); 
  79. }
  80.  
  81. helpmessage() {
  82.  
  83.    move( MAXROW+2, 0); 
  84.    printw( "Press ? for help.%c", '\007');
  85.    refresh();
  86.    raw();            /* no input allowed while sleeping */
  87.    sleep( 2);
  88.    move( MAXROW+2, 0); deleteln();
  89.    refresh();
  90.    noraw();                /* end raw mode */
  91. }
  92.  
  93. static char *helppages[] = { /* be sure that there are max 9 lines per page */
  94.    "The problem is to push packets to",
  95.    "         saving positions.       ",
  96.    "                                 ",
  97.    "You can only push one packet at a",
  98.    "time,  so  watch  out  for  the  ",
  99.    "corners!                         ",
  100.    "                                 ",
  101.    "                                 ",
  102.    "                                 ",
  103.    NULL,                    /* end of page */
  104.    "Moving: You can move by using    ",
  105.    "           the vi-keys hjkl.     ",
  106.    "                                 ",
  107.    "              left right up down ",
  108.    "  Move/Push     h    l    k   j  ",
  109.    "  Run/Push      H    L    K   J  ",
  110.    "  Run only     ^H   ^L   ^K  ^J  ",
  111.    "                                 ",
  112.    "                                 ",
  113.    NULL,                    /* end of page */
  114.    "Other commands:                  ",
  115.    "   c:  temporary save            ",
  116.    "   q:  quit                      ",
  117.    "  ^R:  refresh the screen        ",
  118.    "   s:  save the game             ",
  119.    "   u:  undo last move/push       ",
  120.    "   U:  undo all                  ",
  121.    "  ^U:  reset to temp save        ",
  122.    "   ?:  this help scree           ",
  123.    NULL,                    /* end of page */
  124.    "Characters on screen are:        ",
  125.    "                                 ",
  126.    "  %@  player                     ",
  127.    "  %+  player on saving position  ",
  128.    "  %.  saving position for packet ",
  129.    "  %$  packet                     ",
  130.    "  %*  saved packet               ",
  131.    "  %#  wall                       ",
  132.    "                                 ",
  133.    NULL,                /* end of page */
  134.    "If you set a temporary  save, you",
  135.    "need not  undo  all when you  get",
  136.    "stuck. Just reset to this save.  ",
  137.    "                                 ",
  138.    "A temporary save is automatically",
  139.    "made at the start.",
  140.    "                                 ",
  141.    "                                 ",
  142.    "                                 ",
  143.    NULL,                    /* end of page */
  144.    NULL                        /* total end */
  145. };
  146.  
  147. static char *title[] = {
  148.    "          S O K O B A N          ",
  149.    "---------------------------------"
  150. };
  151.  
  152. static char *helphelp[] = {
  153.    "   (Press return to exit help,   ",
  154.    "    any other key to continue)   "
  155. };
  156.  
  157. #define HELPROWS    16
  158. #define HELPCOLS    37
  159.  
  160. showhelp() {
  161.  
  162.    register short line, i;
  163.    short goon = 1;
  164.    WINDOW *win, *makehelpwin();
  165.  
  166.    win = makehelpwin();
  167.    for( i = 0, line = 2; goon; i++, line++) {
  168.       if( helppages[i] != NULL) {
  169.      wmove( win, line+1, 2);
  170.      printhelpline( win, helppages[i]);
  171.       }
  172.       else {
  173.      wmove( win, HELPROWS-1, 0);
  174.      wrefresh( win);
  175.      if( (goon = (wgetch( win) != '\n'))) {
  176.         line = 1;
  177.         if( helppages[i+1] == NULL) i = -1;
  178.      }
  179.       }
  180.    }
  181.    werase( win);
  182.    wrefresh( win);
  183.    delwin( win);
  184. }
  185.  
  186. WINDOW *makehelpwin() {
  187.  
  188.    WINDOW *win, *newwin();
  189.  
  190.    win = newwin( HELPROWS, HELPCOLS, 2, 0);
  191.    box( win, '|', '-');
  192.    wmove( win, 1, 2);
  193.    wprintw( win, "%s", title[0]);
  194.    wmove( win, 2, 2);
  195.    wprintw( win, "%s", title[1]);
  196.    wmove( win, HELPROWS-3, 2);
  197.    wprintw( win, "%s", helphelp[0]);
  198.    wmove( win, HELPROWS-2, 2);
  199.    wprintw( win, "%s", helphelp[1]);
  200.  
  201.    return( win);
  202. }
  203.  
  204. printhelpline( win, line)
  205. WINDOW *win;
  206. char *line;
  207. {
  208.    OBJECT *obj, *get_obj_adr();
  209.  
  210.    for( ; *line != '\0'; line++) {
  211.       if( *line == '%') {
  212.      ++line;
  213.      obj = get_obj_adr( *line);
  214.          if( obj -> invers) wstandout( win);
  215.          waddch( win, obj -> obj_display); waddch( win, obj -> obj_display);
  216.          if( obj -> invers) wstandend( win);
  217.       }
  218.       else waddch( win, *line);
  219.    }
  220. }
  221.