home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume13 / xsokoban / part01 / showscreen.c < prev    next >
C/C++ Source or Header  |  1992-01-12  |  5KB  |  208 lines

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