home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
games
/
volume13
/
xsokoban
/
part01
/
showscreen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-12
|
5KB
|
208 lines
#include <stdio.h>
#include "sokoban.h"
#include "obj.h"
extern Display *dpy;
extern Window win;
extern GC gc,gclear;
extern short rows, cols, level, moves, pushes, packets, savepack;
extern char map[MAXROW+1][MAXCOL+1];
char line[80];
showscreen() {
register short i, j;
for( i = 0; i < rows; i++) {
for( j = 0; map[i][j] != '\0'; j++)
mapchar(map[i][j], i, j);
}
dispstatus();
}
mapchar( c, i, j)
register char c;
register short i, j;
{
OBJECT *obj, *get_obj_adr();
obj = get_obj_adr(c);
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);
}
clearscreen() {
register short i, j;
for( i = 0; i < rows; i++) {
for( j = 0; map[i][j] != '\0'; j++)
clearchar(map[i][j], i, j);
}
dispstatus();
}
clearchar( c, i, j)
register char c;
register short i, j;
{
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);
}
OBJECT *get_obj_adr(c)
register char c;
{
register OBJECT *ret;
if (c == player.obj_intern) return &player;
if (c == playerstore.obj_intern) return &playerstore;
if (c == store.obj_intern) return &store;
if (c == save.obj_intern) return &save;
if (c == packet.obj_intern) return &packet;
if (c == wall.obj_intern) return &wall;
if (c == ground.obj_intern) return &ground;
return &ground;
}
dispstatus()
{
XDrawString(dpy,win,gclear,10,MAXROW*PIXMAPY,line,strlen(line));
sprintf(line," %3d %3d %3d %5d %5d ",level,packets,savepack,moves,pushes);
XDrawString(dpy,win,gc,10,MAXROW*PIXMAPY,line,strlen(line));
}
helpmessage() {
fprintf( stdout,"Press ? for help.\n");
}
/*
static char *helppages[] = {
"The problem is to push packets to",
"saving positions by moving around",
"and pushing only one packet at a",
" time if possible. ",
" ",
" ",
" ",
" ",
" ",
NULL,
"Moving: You can move by using ",
" the vi-keys hjkl. ",
" ",
" left right up down ",
" Move/Push h l k j ",
" Run/Push H L K J ",
" Run only ^H ^L ^K ^J ",
" ",
" ",
NULL,
"Other commands: ",
" c: temporary save ",
" q: quit ",
" ^R: refresh the screen ",
" s: save the game ",
" u: undo last move/push ",
" U: undo all ",
" ^U: reset to temp save ",
" ?: this help scree ",
NULL,
"Characters on screen are: ",
" ",
" %@ player ",
" %+ player on saving position ",
" %. saving position for packet ",
" %$ packet ",
" %* saved packet ",
" %# wall ",
" ",
NULL,
"If you set a temporary save, you",
"need not undo all when you get",
"stucked. Just reset to this save.",
" ",
"A temporary save is automatically",
"made at the start.",
" ",
" ",
" ",
NULL,
NULL
};
static char *title[] = {
" S O K O B A N ",
"---------------------------------"
};
static char *helphelp[] = {
" (Press return to exit help, ",
" any other key to continue) "
};
#define HELPROWS 16
#define HELPCOLS 37
showhelp() {
register short line, i;
short goon = 1;
WINDOW *win, *makehelpwin();
win = makehelpwin();
for( i = 0, line = 2; goon; i++, line++) {
if( helppages[i] != NULL) {
wmove( win, line+1, 2);
printhelpline( win, helppages[i]);
}
else {
wmove( win, HELPROWS-1, 0);
wrefresh( win);
if( (goon = (wgetch( win) != '\n'))) {
line = 1;
if( helppages[i+1] == NULL) i = -1;
}
}
}
werase( win);
wrefresh( win);
delwin( win);
}
WINDOW *makehelpwin() {
WINDOW *win, *newwin();
win = newwin( HELPROWS, HELPCOLS, 2, 0);
box( win, '|', '-');
wmove( win, 1, 2);
wprintw( win, "%s", title[0]);
wmove( win, 2, 2);
wprintw( win, "%s", title[1]);
wmove( win, HELPROWS-3, 2);
wprintw( win, "%s", helphelp[0]);
wmove( win, HELPROWS-2, 2);
wprintw( win, "%s", helphelp[1]);
return( win);
}
printhelpline( win, line)
WINDOW *win;
char *line;
{
OBJECT *obj, *get_obj_adr();
for( ; *line != '\0'; line++) {
if( *line == '%') {
++line;
obj = get_obj_adr( *line);
if( obj -> invers) wstandout( win);
waddch( win, obj -> obj_display); waddch( win, obj -> obj_display);
if( obj -> invers) wstandend( win);
}
else waddch( win, *line);
}
}
*/