diff -u beasts-orig/beast.c beasts/beast.c --- beasts-orig/beast.c Mon Jul 27 22:36:59 1998 +++ beasts/beast.c Sat Mar 11 10:07:05 2000 @@ -4,7 +4,7 @@ #include "beasts.h" #include "beast.h" -#include "console.h" /* FIXME: should be draw.h */ +/*#include "console.h"*/ /* FIXME: should be draw.h */ /* Structure of a beast */ typedef struct { @@ -16,7 +16,7 @@ int lastmoved; } Beastie; -static Beastie *beast; +static Beastie *beast = NULL; static int totalbeasts; static int livebeasts; @@ -38,6 +38,7 @@ /************** Out with the beasties! ********************/ + totalbeasts=0; for(species=0; species < BEASTIETYPES; species++) totalbeasts+=numbeasties[species]; @@ -60,10 +61,14 @@ beastPtr->phobic=0; } - place_thing(beast_index, - fieldPtr, - &beastPtr->x, - &beastPtr->y); + if (!place_thing(beast_index, + fieldPtr, + &beastPtr->x, + &beastPtr->y)) + { + livebeasts--; + beastPtr->species=DEAD; + } beastPtr++; beast_index++; @@ -80,7 +85,7 @@ livebeasts--; if(livebeasts==0) - endlevel("All beasts dead."); + endlevel(NEXTLEVEL, "All beasts dead."); /* score++; */ } @@ -112,6 +117,12 @@ { signal(SIGALRM, beastie_call); } + +void +stop_timer() +{ + signal(SIGALRM, SIG_IGN); +} /*********** Beastie Behaviour ****************/ void @@ -130,8 +141,8 @@ move_beastie(i,turnnum, field, hero); /* } next beast */ - /* (*RefreshField)(); */ - ConsoleRefresh(); + (*field_refresh)(); + /*ConsoleRefresh();*/ } /* beastie_dance */ static void @@ -162,7 +173,7 @@ endpos=bpos + field->x * dy + dx; flub=field->map[endpos]; if (flub==HERO) { - endlevel("Hero is beastie snack."); + endlevel(GAMEOVER, "Hero is beastie snack."); } if (beast[bnum].phobic > int_rand(50,120)) { @@ -311,7 +322,8 @@ return; /* Nothing left to do if we didn't move. */ field->map[bpos]=EMPTY; - ConsoleDrawIcon(beast[bnum].x,beast[bnum].y,EMPTY); + /*ConsoleDrawIcon(beast[bnum].x,beast[bnum].y,EMPTY);*/ + (*draw_icon)(beast[bnum].x,beast[bnum].y,EMPTY); beast[bnum].x+=dx; beast[bnum].y+=dy; @@ -319,7 +331,8 @@ beast[bnum].phobic-=1; field->map[endpos]=BEAST0+bnum; - ConsoleDrawIcon(beast[bnum].x,beast[bnum].y,BEAST0+bnum); + /*ConsoleDrawIcon(beast[bnum].x,beast[bnum].y,BEAST0+bnum);*/ + (*draw_icon)(beast[bnum].x,beast[bnum].y,BEAST0+bnum); } static void @@ -340,9 +353,10 @@ case HOLE: break; case HERO: - endlevel("Hero blown to pieces."); + endlevel(GAMEOVER, "Hero blown to pieces."); default: - ConsoleDrawIcon(xx,yy,EMPTY); + /*ConsoleDrawIcon(xx,yy,EMPTY);*/ + (*draw_icon)(xx,yy,EMPTY); field->map[yoff+xx]=EMPTY; } /* end switch */ } /* next xx */ diff -u beasts-orig/beast.h beasts/beast.h --- beasts-orig/beast.h Mon Jul 27 01:35:25 1998 +++ beasts/beast.h Sat Mar 11 10:07:05 2000 @@ -20,3 +20,5 @@ void init_timer(long usecs); void start_timer(); +void stop_timer(); + diff -u beasts-orig/beasts.h beasts/beasts.h --- beasts-orig/beasts.h Mon Jul 27 22:07:47 1998 +++ beasts/beasts.h Sat Mar 11 10:12:30 2000 @@ -33,9 +33,22 @@ DOWN_RIGHT } Direction; +typedef enum { + LOOP = 0, + NEXTLEVEL, + GAMEOVER +} LoopValue; + +typedef void (*InitFunc) (); +typedef void (*FieldSizeFunc) (int *x, int *y); +typedef void (*LoopFunc) (Field *field, Hero *hero); typedef void (*DrawIconFunc) (int x, int y, Grounds thing); +typedef void (*RefreshFunc) (); +typedef void (*QuitFunc) (); /* in main.c */ +void endlevel(LoopValue NewStatus, char *msg); + gboolean place_thing(Grounds thing, Field *fieldPtr, int *thing_x, @@ -48,9 +61,11 @@ int dir_to_step(Direction thatway, int rowspan); -Hero *GlobalHeroPtr; -Field *GlobalFieldPtr; -gboolean StopLoop; +extern Hero *GlobalHeroPtr; +extern Field *GlobalFieldPtr; +extern LoopValue StopLoop; +extern DrawIconFunc draw_icon; +extern RefreshFunc field_refresh; #define float_rand() ((float)rand()/(float)RAND_MAX) #define int_rand(N,X) ((int)(((double)rand()/(double)RAND_MAX)*((X)-(N)+1)+(N))) diff -u beasts-orig/console.c beasts/console.c --- beasts-orig/console.c Mon Jul 27 22:10:28 1998 +++ beasts/console.c Sat Mar 11 10:07:05 2000 @@ -69,7 +69,7 @@ moveman(DOWN_RIGHT, field, hero); break; case 'q': - return; + endlevel(GAMEOVER, "Player quit"); break; default: break; @@ -141,3 +141,4 @@ *x=(COLS-2)/2; *y=LINES-4; } + diff -u beasts-orig/main.c beasts/main.c --- beasts-orig/main.c Mon Jul 27 22:38:20 1998 +++ beasts/main.c Sat Mar 11 10:10:37 2000 @@ -24,12 +24,19 @@ static void draw_field(Field *field); -/* extern DrawIconFunc ConsoleDrawIcon; */ +/***** Globals ******/ +Hero *GlobalHeroPtr; +Field *GlobalFieldPtr; +LoopValue StopLoop; /***** Defines ********/ -static DrawIconFunc (*draw_icon); -static void (*field_refresh)(); +InitFunc screen_init; +FieldSizeFunc field_size; +LoopFunc screen_loop; +DrawIconFunc draw_icon; +RefreshFunc field_refresh; +QuitFunc screen_quit; /*************** Functions *********************/ @@ -47,15 +54,23 @@ /* Determine interface mode (slang, gnome). */ - ConsoleInit(); +#ifndef NO_CONSOLE_INTERFACE + /* Ncurses interface */ + screen_init=&ConsoleInit; + field_size=&ConsoleFieldSize; + screen_loop=&ConsoleLoop; draw_icon=&ConsoleDrawIcon; field_refresh=&ConsoleRefresh; + screen_quit=&ConsoleQuit; +#endif + + (*screen_init)(); /* Get screen size. */ /* Calculate playing field size. */ - ConsoleFieldSize(&x,&y); + (*field_size)(&x,&y); srand(time(NULL)); field.map=g_new(Grounds,x*y); @@ -65,7 +80,7 @@ init_timer(1000000/6); /* Establish all the callbacks. */ - + do { level++; init_grounds(&field, @@ -77,25 +92,27 @@ /* Wait for a key or something, and...*/ /* Action! */ - StopLoop=FALSE; + StopLoop=LOOP; start_timer(); - ConsoleLoop(&field, &hero); + (*screen_loop)(&field, &hero); + stop_timer(); /* Hopefully everything is event based and we sleep for a while. */ /* Something caused the level to end. Who won? */ + } while (StopLoop != GAMEOVER); - ConsoleQuit(); + (*screen_quit)(); exit(0); } void -endlevel(char *msg) +endlevel(LoopValue NewStatus, char *msg) { - StopLoop=TRUE; + StopLoop=NewStatus; } static void @@ -137,6 +154,8 @@ field[yoff+xx] = WALL; else if (randfooy; yy++) { yoff=yy*field->x; for(xx=0; xx < field->x; xx++) { - if(field->map[yoff+xx] != EMPTY) { - /* (*draw_icon)(xx,yy,field->map[yoff+xx]); */ - ConsoleDrawIcon(xx,yy,field->map[yoff+xx]); - } /* endif not empty */ + /*if(field->map[yoff+xx] != EMPTY) {*/ + (*draw_icon)(xx,yy,field->map[yoff+xx]); + /*ConsoleDrawIcon(xx,yy,field->map[yoff+xx]);*/ + /*}*/ /* endif not empty */ } /* next xx */ } /* next yy */ (*field_refresh)(); @@ -234,8 +253,8 @@ end_y = (yoff + x + stepped) / field->x; end_x = (yoff + x + stepped) % field->x; - ConsoleDrawIcon(end_x, end_y, BLOCK); - /* (*draw_icon)(end_x,end_y,BLOCK); */ + /*ConsoleDrawIcon(end_x, end_y, BLOCK);*/ + (*draw_icon)(end_x,end_y,BLOCK); return TRUE; } @@ -257,8 +276,8 @@ } - /* (*draw_icon)(hero->x, hero->y, EMPTY); */ - ConsoleDrawIcon(hero->x, hero->y, EMPTY); + (*draw_icon)(hero->x, hero->y, EMPTY); + /*ConsoleDrawIcon(hero->x, hero->y, EMPTY);*/ switch (thatway) { case UP_LEFT: @@ -293,8 +312,8 @@ default: break; } - ConsoleDrawIcon(hero->x, hero->y, HERO); - /* (*draw_icon)(hero->x, hero->y, HERO); */ + /*ConsoleDrawIcon(hero->x, hero->y, HERO);*/ + (*draw_icon)(hero->x, hero->y, HERO); (*field_refresh)();