home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
games
/
volume13
/
xsokoban3
/
part02
/
screen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-11
|
2KB
|
75 lines
#include <stdio.h>
#include "externs.h"
#include "globals.h"
extern char *malloc();
extern FILE *fopen();
extern short level, packets, savepack, rows, cols;
extern char map[MAXROW + 1][MAXCOL + 1];
extern POS ppos;
/* reads in the current screen level (wheee, exciting. NOT) */
short ReadScreen(void)
{
FILE *screen;
char *fnam;
int y, x;
short j, c, ret = 0;
for (y = 0; y < MAXROW; y++)
for (x = 0; x < MAXCOL; x++)
map[y][x] = ground;
fnam = malloc(strlen(SCREENPATH) + 12);
sprintf(fnam, "%s/screen.%d", SCREENPATH, level);
if ((screen = fopen(fnam, "r")) == NULL)
ret = E_FOPENSCREEN;
else {
packets = savepack = rows = j = cols = 0;
ppos.x = -1;
ppos.y = -1;
while ((ret == 0) && ((c = getc(screen)) != EOF)) {
if (c == '\n') {
map[rows++][j] = '\0';
if (rows > MAXROW)
ret = E_TOMUCHROWS;
else {
if (j > cols)
cols = j;
j = 0;
}
} else if ((c == player) || (c == playerstore)) {
if (ppos.x != -1)
ret = E_PLAYPOS1;
else {
ppos.x = rows;
ppos.y = j;
map[rows][j++] = c;
if (j > MAXCOL)
ret = E_TOMUCHCOLS;
}
} else if ((c == save) || (c == packet) ||
(c == wall) || (c == store) ||
(c == ground)) {
if (c == save) {
savepack++;
packets++;
}
if (c == packet)
packets++;
map[rows][j++] = c;
if (j > MAXCOL)
ret = E_TOMUCHCOLS;
} else
ret = E_ILLCHAR;
}
fclose(screen);
if ((ret == 0) && (ppos.x == -1))
ret = E_PLAYPOS2;
}
return (ret);
}