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