home *** CD-ROM | disk | FTP | other *** search
Wrap
Newsgroups: alt.sources Path: sparky!uunet!mcsun!news.funet.fi!ousrvr.oulu.fi!phoenix!yaz From: yaz@phoenix.oulu.fi Subject: hexa - hexagonal sokoban for curses Message-ID: <1993Jan25.011042.13800@ousrvr.oulu.fi> Lines: 635 Sender: news@ousrvr.oulu.fi Organization: Phoenix Lab., University of Oulu, Finland X-Newsagent: :: uutimet -- news-agent by yaz@phoenix.oulu.fi :: Date: Mon, 25 Jan 1993 01:10:42 GMT #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: hexa.txt Makefile hexa.c screen.0 screen.1 screen.2 # screen.3 screen.4 hexa.6 # Wrapped by yaz@phoenix on Mon Jan 25 03:07:29 1993 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f hexa.txt -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"hexa.txt\" else echo shar: Extracting \"hexa.txt\" \(3677 characters\) sed "s/^X//" >hexa.txt <<'END_OF_hexa.txt' X X X X January 25, 1993 HEXA(6) X X X X NAME X HEXA - The hexagonal sokoban for curses X X SYNOPSIS X hexa [<screen_number>] X X DESCRIPTION X A game where you try to push the moneybags to the safe. X X OPTIONS X X If you give screen_number then you will first edit that screen and save X the editings by quit (q). Read further below for the movement keys. X Place any of the ascii character symbols (bag, wall, safe, you) to any- X where you want, but try to maintain at least one logical solution. X Please e-mail your best screens to the author, because he really can't X invent good levels. X X FILES X screen.0 level zero X screen.1 level one X screen.2 level two X . X . X . X screen.n level n X X CHARACTERS X Ascii characters symbolize: X X # wall X . safe X $ bag of gold (dollars) * bag in safe X @ you + you in safe X >--< the hexagonal grid X < >-- X X RULES X The rules are simple. Move around the hexagonal grid blocked by walls X (#) and push the bags ($) to the safe area (.) using as few moves as X possible. The movement keys are defined in the source code by the ori- X ginal creator (yaz@phoenix.oulu.fi) but you can change them if you have X the source code file. Keys: X X up k up X upleft u | i upright X >@< X downleft n | m downright X down j down X X X X X X X 1 X X X X X X X HEXA(6) January 25, 1993 X X X SAMPLE X X This is a sample snapshot of the game all variables zero (level, score, X moves, pushes): X --< # >--< # >--< # >--< # >--< # >--< # >--< # >--< # X # >--< # >--< # >--< # >--< # >--< # >--< # >--< # >-- MOV 0 X --< >--< >--< >--< >--< >--< >--< >--< # PUS 0 X >--< >--< >--< >--< >--< >--< >--< >-- SCO 0 X --< >--< >--< >--< >--< >--< >--< >--< # LVL 0 X $ >--< # >--< >--< $ >--< # >--< >--< >--< >-- X --< >--< >--< >--< >--< # >--< >--< >--< # X >--< # >--< >--< # >--< $ >--< # >--< >--< >-- X --< # >--< $ >--< # >--< # >--< @ >--< >--< >--< # X # >--< >--< # >--< >--< $ >--< # >--< >--< >-- X --< >--< # >--< $ >--< # >--< $ >--< >--< >--< # X >--< >--< >--< >--< >--< >--< >--< >-- X --< >--< >--< >--< # >--< >--< >--< >--< # X >--< >--< >--< $ >--< >--< # >--< >--< >-- X --< >--< >--< >--< # >--< >--< >--< >--< # X >--< >--< >--< >--< >--< # >--< >--< >-- X --< >--< >--< # >--< >--< # >--< # >--< >--< # X >--< >--< # >--< # >--< # >--< # >--< # >--< >-- X --< >--< >--< >--< # >--< >--< . >--< . >--< # X >--< >--< >--< >--< >--< # >--< . >--< . >-- X --< >--< >--< >--< >--< >--< . >--< . >--< # X >--< >--< >--< >--< >--< # >--< . >--< . >-- X --< # >--< # >--< # >--< # >--< # >--< # >--< # >--< # X # >--< # >--< # >--< # >--< # >--< # >--< # >--< # >-- X X AUTHOR X yaz@phoenix.oulu.fi (Tuomas K Kaikkonen) wishes to get feedback: X Design your own levels, improve the program (top-10 list), do graphical X (Xwindows) version, write better manual pages. X X X X X X X X X X X X X X X X X X X X X X X X 2 X END_OF_hexa.txt if test 3677 -ne `wc -c <hexa.txt`; then echo shar: \"hexa.txt\" unpacked with wrong size! fi # end of overwriting check fi if test -f Makefile -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"Makefile\" else echo shar: Extracting \"Makefile\" \(90 characters\) sed "s/^X//" >Makefile <<'END_OF_Makefile' XOBJS=hexa.c X XCC=cc -O X Xall: hexa X Xhexa: $(OBJS) X $(CC) $(OBJS) -o hexa -lcurses -ltermcap END_OF_Makefile if test 90 -ne `wc -c <Makefile`; then echo shar: \"Makefile\" unpacked with wrong size! fi # end of overwriting check fi if test -f hexa.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"hexa.c\" else echo shar: Extracting \"hexa.c\" \(6752 characters\) sed "s/^X//" >hexa.c <<'END_OF_hexa.c' X#include <curses.h> X#include <stdio.h> X#include <ctype.h> X X#define FLOOR ' ' X#define ME '@' X#define WALL '#' X#define PACKET '$' X#define SAVE '.' X#define ME_SAVE '+' X#define PA_SAVE '*' X#define UP 'k' X#define DN 'j' X#define UPL 'u' X#define UPR 'i' X#define DNL 'n' X#define DNR 'm' X#define QUIT 'q' X#define XMAX 18 X#define YMAX 12 X#define XHEX 8 X#define YHEX 2 X Xint mvpos[6]={-XMAX,XMAX,-1,1,XMAX-1,XMAX+1}; X Xint pos[YMAX*XMAX][2]; X Xint game[YMAX*XMAX],player=0,moves=0,pushes=0,score=0,maxscore=0,level=0; Xchar hex[YHEX][XHEX+1]={ X " >--< ", X "< >--"}; X Xvoid gotoxy(x, y) Xint x,y; X{ X move(y-1,x-1); X} X Xvoid do_screen() X{ X int x,y; X X maxscore=0; X X for(y=0;y<YMAX*YHEX;y++) for(x=0;x<XMAX/2;x++) { X mvaddstr(y,x*XHEX,hex[y%YHEX]); X } X for(x=0;x<XMAX*YMAX;x++) { X mvaddch(pos[x][0],pos[x][1],game[x]); X if (game[x]==ME) game[player=x]=FLOOR; X if (game[x]==SAVE) maxscore++; X } X refresh(); X} X Xvoid reset_all() X{ X int i; X X for(i=0;i<XMAX*YMAX;game[i++]=FLOOR); X for(i=0;i<XMAX*YMAX;i++) { X pos[i][0]=YHEX*(i/XMAX)+YHEX/2*((i+1)%2); X pos[i][1]=XHEX/2*(i%XMAX)+XHEX/3; X } X} X Xvoid load_screen(lvl) Xint lvl; X{ X FILE *fileptr; X int i; X char filename[16]; X sprintf(filename,"screen.%d",lvl); X if ((fileptr=fopen(filename, "r"))==NULL) { X printf("Cannot read %s", filename); X exit(-10); X } else { X for (i=0;i<XMAX*YMAX;game[i++]=fgetc(fileptr)); X fclose(fileptr); X } X refresh(); X} X Xvoid save_screen(lvl) Xint lvl; X{ X FILE *fileptr; X int i; X char filename[16]; X sprintf(filename,"screen.%d",lvl); X if ((fileptr=fopen(filename, "w"))==NULL) { X printf("Cannot write %s", filename); X exit(-10); X } else { X for (i=0;i<XMAX*YMAX;fputc(game[i++],fileptr)) X ; X fclose(fileptr); X } X refresh(); X} X Xvoid mv_cur(d) Xint d; X{ X mvaddch(pos[player][0],pos[player][1],game[player]); X if (player%2==1 && abs(d) != XMAX ) d-=XMAX; X if (player+d<0) d=XMAX*YMAX+d; X player=(player+d)%(XMAX*YMAX); X mvaddch(pos[player][0],pos[player][1],ME); X refresh(); X} X Xvoid put_cur(c) Xchar c; X{ X game[player]=c; X} X Xvoid edit_screen() X{ X char key; X X do_screen(); X put_cur(ME); X for(key=0;key!=QUIT;key=getch()) { X switch(key) { X case UP:mv_cur(mvpos[0]); break; X case DN:mv_cur(mvpos[1]); break; X case UPL:mv_cur(mvpos[2]); break; X case UPR:mv_cur(mvpos[3]); break; X case DNL:mv_cur(mvpos[4]); break; X case DNR:mv_cur(mvpos[5]); break; X case FLOOR:put_cur(FLOOR); break; X case ME:put_cur(ME); break; X case WALL:put_cur(WALL); break; X case PACKET:put_cur(PACKET); break; X case SAVE:put_cur(SAVE); break; X } X } X} X Xint look_at(lp, d) Xint lp,d; X{ X if (lp%2==1 && abs(d) != XMAX ) d-=XMAX; X if (lp+d<0) d=XMAX*YMAX+d; X return (game[(lp+d)%(XMAX*YMAX)]); X} X Xvoid mv_player(dir) Xint dir; X{ X int x,y,pplayer,ddir; X X if (look_at(player, mvpos[dir])==FLOOR || X look_at(player, mvpos[dir])==SAVE) { X y=pos[player][0]; X x=pos[player][1]; X mvaddch(y,x,game[player]); X if (player%2==1 && abs(mvpos[dir]) != XMAX) player-=XMAX; X if (player+mvpos[dir]<0) player=player+XMAX*YMAX; X player=(player+mvpos[dir])%(XMAX*YMAX); X y=pos[player][0]; X x=pos[player][1]; X mvaddch(y,x,game[player]==SAVE?ME_SAVE:ME); X moves++; X } else if (look_at(player, mvpos[dir])==PACKET || X look_at(player, mvpos[dir])==PA_SAVE) { X pplayer=player; X if (pplayer%2==1 && abs(mvpos[dir]) != XMAX) pplayer-=XMAX; X if (pplayer+mvpos[dir]<0) pplayer=pplayer+XMAX*YMAX; X pplayer=(pplayer+mvpos[dir])%(XMAX*YMAX); X if (look_at(pplayer, mvpos[dir])==FLOOR || X look_at(pplayer, mvpos[dir])==SAVE) { X y=pos[player][0]; X x=pos[player][1]; X mvaddch(y,x,game[player]); X if (player%2==1 && abs(mvpos[dir]) != XMAX) player-=XMAX; X if (player+mvpos[dir]<0) player=player+XMAX*YMAX; X player=(player+mvpos[dir])%(XMAX*YMAX); X y=pos[player][0]; X x=pos[player][1]; X mvaddch(y,x,game[player]==PA_SAVE?ME_SAVE:ME); X if (game[player]==PA_SAVE) { X game[player]=SAVE; X } else game[player]=FLOOR; X if (pplayer%2==1 && abs(mvpos[dir]) != XMAX) pplayer-=XMAX; X if (pplayer+mvpos[dir]<0) pplayer=pplayer+XMAX*YMAX; X pplayer=(pplayer+mvpos[dir])%(XMAX*YMAX); X y=pos[pplayer][0]; X x=pos[pplayer][1]; X mvaddch(y,x,game[pplayer]==SAVE?PA_SAVE:PACKET); X if (game[pplayer]==SAVE) { X game[pplayer]=PA_SAVE; X } else game[pplayer]=PACKET; X pushes++; X moves++; X if (game[player]==SAVE && game[pplayer]==PACKET) X score--; X if (game[pplayer]==PA_SAVE && game[player]==FLOOR) score++; X } X } X refresh(); X} X Xmain(argc, argv) Xint argc; Xchar **argv; X{ X int i,j,k,a,b; X FILE *save_file; X char c,key,line[80]; X X reset_all(); X X initscr(); X noecho(); X raw(); X X if (argc>1) { X level=atoi(argv[1]); X printf("Editing level %d", level); X sprintf(line, "screen.%d", level); X if ((save_file=fopen(line, "r"))==NULL) { X fclose(save_file); X } else { X fclose(save_file); X load_screen(level); X } X edit_screen(); X save_screen(level); X } X X load_screen(level); X do_screen(); X X for(key=0;key!=QUIT;key=getch()) { X switch(key) { X case UP:mv_player(0); break; X case DN:mv_player(1); break; X case UPL:mv_player(2); break; X case UPR:mv_player(3); break; X case DNL:mv_player(4); break; X case DNR:mv_player(5); break; X } X sprintf(line,"MOV %d",moves); X mvaddstr(1,73,line); X sprintf(line,"PUS %d",pushes); X mvaddstr(2,73,line); X sprintf(line,"SCO %d ",score); X mvaddstr(3,73,line); X sprintf(line,"LVL %d",level); X mvaddstr(4,73,line); X if (score==maxscore) { X load_screen(++level); X do_screen(); X score=0; X } X refresh(); X } X noraw(); X echo(); X endwin(); X return(0); X} END_OF_hexa.c if test 6752 -ne `wc -c <hexa.c`; then echo shar: \"hexa.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f screen.0 -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"screen.0\" else echo shar: Extracting \"screen.0\" \(217 characters\) sed "s/^X//" >screen.0 <<'END_OF_screen.0' X################### ## $ # $ # ## # # $## ## ## $## #$@# ### # $ # $ ## $# # ## # # ## ### ##### ## # #....## #....################### END_OF_screen.0 if test 217 -ne `wc -c <screen.0`; then echo shar: \"screen.0\" unpacked with wrong size! fi # end of overwriting check fi if test -f screen.1 -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"screen.1\" else echo shar: Extracting \"screen.1\" \(217 characters\) sed "s/^X//" >screen.1 <<'END_OF_screen.1' X######################## ########### $$ ######### $ $ ####### #####. @ .####. .##### ####### ######### ########### ######################## END_OF_screen.1 if test 217 -ne `wc -c <screen.1`; then echo shar: \"screen.1\" unpacked with wrong size! fi # end of overwriting check fi if test -f screen.2 -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"screen.2\" else echo shar: Extracting \"screen.2\" \(217 characters\) sed "s/^X//" >screen.2 <<'END_OF_screen.2' X # ##### ##..# ## ###.$ ### # @ # # #$ $# # ## # ## ## # ## ### END_OF_screen.2 if test 217 -ne `wc -c <screen.2`; then echo shar: \"screen.2\" unpacked with wrong size! fi # end of overwriting check fi if test -f screen.3 -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"screen.3\" else echo shar: Extracting \"screen.3\" \(217 characters\) sed "s/^X//" >screen.3 <<'END_OF_screen.3' X # ## ## # @ # # # # $ # #$ $# # . # #. .# ### END_OF_screen.3 if test 217 -ne `wc -c <screen.3`; then echo shar: \"screen.3\" unpacked with wrong size! fi # end of overwriting check fi if test -f screen.4 -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"screen.4\" else echo shar: Extracting \"screen.4\" \(217 characters\) sed "s/^X//" >screen.4 <<'END_OF_screen.4' X @ $ . END_OF_screen.4 if test 217 -ne `wc -c <screen.4`; then echo shar: \"screen.4\" unpacked with wrong size! fi # end of overwriting check fi if test -f hexa.6 -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"hexa.6\" else echo shar: Extracting \"hexa.6\" \(3278 characters\) sed "s/^X//" >hexa.6 <<'END_OF_hexa.6' X.TH "HEXA" 6 "January 25, 1993" X.SH NAME XHEXA \- The hexagonal sokoban for curses X.SH SYNOPSIS Xhexa [<screen_number>] X.SH DESCRIPTION XA game where you try to push the moneybags to the safe. X.SH OPTIONS X.PP XIf you give screen_number then you will first edit that screen and save the editings by quit (q). Read further below for the movement keys. XPlace any of the ascii character symbols (bag, wall, safe, you) to anywhere you want, but try to maintain at least one logical solution. XPlease e-mail your best screens to the author, because he really can't invent good levels. X.SH FILES Xscreen.0 level zero X.br Xscreen.1 level one X.br Xscreen.2 level two X.br X . X . X . X.br Xscreen.n level n X.SH CHARACTERS XAscii characters symbolize: X.PP X # wall X.br X . safe X.br X $ bag of gold (dollars) * bag in safe X.br X @ you + you in safe X.br X >--< the hexagonal grid X.br X < >-- X.SH RULES XThe rules are simple. Move around the hexagonal grid blocked by walls (#) and push the bags ($) to the safe area (.) using as few moves as possible. XThe movement keys are defined in the source code by the original creator (yaz@phoenix.oulu.fi) but you can change them if you have the source code file. XKeys: X.PP X up k up X.br X upleft u | i upright X.br X >@< X.br Xdownleft n | m downright X.br X down j down X.SH SAMPLE X.PP XThis is a sample snapshot of the game all variables zero (level, score, moves, pushes): X.br X--< # >--< # >--< # >--< # >--< # >--< # >--< # >--< # X.br X# >--< # >--< # >--< # >--< # >--< # >--< # >--< # >-- MOV 0 X.br X--< >--< >--< >--< >--< >--< >--< >--< # PUS 0 X.br X >--< >--< >--< >--< >--< >--< >--< >-- SCO 0 X.br X--< >--< >--< >--< >--< >--< >--< >--< # LVL 0 X.br X$ >--< # >--< >--< $ >--< # >--< >--< >--< >-- X.br X--< >--< >--< >--< >--< # >--< >--< >--< # X.br X >--< # >--< >--< # >--< $ >--< # >--< >--< >-- X.br X--< # >--< $ >--< # >--< # >--< @ >--< >--< >--< # X.br X# >--< >--< # >--< >--< $ >--< # >--< >--< >-- X.br X--< >--< # >--< $ >--< # >--< $ >--< >--< >--< # X.br X >--< >--< >--< >--< >--< >--< >--< >-- X.br X--< >--< >--< >--< # >--< >--< >--< >--< # X.br X >--< >--< >--< $ >--< >--< # >--< >--< >-- X.br X--< >--< >--< >--< # >--< >--< >--< >--< # X.br X >--< >--< >--< >--< >--< # >--< >--< >-- X.br X--< >--< >--< # >--< >--< # >--< # >--< >--< # X.br X >--< >--< # >--< # >--< # >--< # >--< # >--< >-- X.br X--< >--< >--< >--< # >--< >--< . >--< . >--< # X.br X >--< >--< >--< >--< >--< # >--< . >--< . >-- X.br X--< >--< >--< >--< >--< >--< . >--< . >--< # X.br X >--< >--< >--< >--< >--< # >--< . >--< . >-- X.br X--< # >--< # >--< # >--< # >--< # >--< # >--< # >--< # X.br X# >--< # >--< # >--< # >--< # >--< # >--< # >--< # >-- X.SH AUTHOR Xyaz@phoenix.oulu.fi (Tuomas K Kaikkonen) wishes to get feedback: X.br XDesign your own levels, improve the program (top-10 list), do graphical (Xwindows) version, write better manual pages. END_OF_hexa.6 if test 3278 -ne `wc -c <hexa.6`; then echo shar: \"hexa.6\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of shell archive. exit 0 -- Tuomas K.Kaikkonen yaz@phoenix.oulu.fi ,._/\ " % man woman " Taidonkaari 1 E 36 Tel:+358-81-5546081 `. | " woman not found " SF-90570 OULU (_/ _ __ /FI| " % wife ? " FINLAND I I-I /_ |___/ " wife: No match. "