From 680effbd6839470844eb598022a4cb80904c66a2 Mon Sep 17 00:00:00 2001 From: me Date: Thu, 18 Aug 2022 03:54:10 +0430 Subject: [PATCH] add revenge --- Makefile | 4 +- nbsdgames.c | 1 + revenge.c | 482 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 485 insertions(+), 2 deletions(-) create mode 100644 revenge.c diff --git a/Makefile b/Makefile index a4768c5..b50bb5e 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,8 @@ LIBS_PKG_CONFIG!=pkg-config --libs --cflags ncurses LIBS=$(LIBS_PKG_CONFIG) -lm -ALL= nbsdgames jewels sudoku mines reversi checkers battleship rabbithole sos pipes fifteen memoblocks fisher muncher miketron redsquare darrt snakeduel tugow -SCORE_FILES= pipes_scores jewels_scores miketron_scores muncher_scores fisher_scores darrt_scores tugow_scores +ALL= nbsdgames jewels sudoku mines reversi checkers battleship rabbithole sos pipes fifteen memoblocks fisher muncher miketron redsquare darrt snakeduel tugow revenge +SCORE_FILES= pipes_scores jewels_scores miketron_scores muncher_scores fisher_scores darrt_scores tugow_scores revenge_scores SRC!=echo *.c *.h all: $(ALL) diff --git a/nbsdgames.c b/nbsdgames.c index 58f4ba7..6f442b0 100644 --- a/nbsdgames.c +++ b/nbsdgames.c @@ -62,6 +62,7 @@ char main_menu[]={ NB"darrt\n" NB"snakeduel\n" NB"tugow\n" + NB"revenge\n" }; char ascii_art[]={ " ###### ###### " diff --git a/revenge.c b/revenge.c new file mode 100644 index 0000000..e93bf09 --- /dev/null +++ b/revenge.c @@ -0,0 +1,482 @@ +/* +.-. +|_.' +| \EVENGE + +Authored by abakh +To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. + +You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see . + +*/ +#include "common.h" +enum {EMPTY=0,BLOCK,CAT_OLD,CAT,CAT_NEW,CAT_TRAPPED,CHEESE}; +/* The Plan9 compiler can not handle VLAs */ +#ifdef NO_VLA +#define size 20 +#else +byte size=20; +#endif +#define SAVE_TO_NUM 10 +long score=0; +byte py,px; +byte ey,ex; //the empty tile +chtype colors[6]={0}; +void rectangle(byte sy,byte sx){ + for(byte y=0;y<=size+1;++y){ + mvaddch(sy+y,sx,ACS_VLINE); + mvaddch(sy+y,sx+size*2,ACS_VLINE); + } + for(byte x=0;x<=size*2;++x){ + mvaddch(sy,sx+x,ACS_HLINE); + mvaddch(sy+size+1,sx+x,ACS_HLINE); + } + mvaddch(sy,sx,ACS_ULCORNER); + mvaddch(sy+size+1,sx,ACS_LLCORNER); + mvaddch(sy,sx+size*2,ACS_URCORNER); + mvaddch(sy+size+1,sx+size*2,ACS_LRCORNER); +} +void logo(byte sy,byte sx){ + mvaddstr(sy,sx, ".-."); + mvprintw(sy+1,sx,"|_.'"); + mvaddstr(sy+2,sx,"| \\EVENGE "); +} + +byte save_score(void){ + return fallback_to_home("revenge_scores",score,SAVE_TO_NUM); + +} + +void show_scores(byte playerrank){ + erase(); + logo(0,0); + if(playerrank==FOPEN_FAIL){ + mvaddstr(3,0,"Could not open score file"); + printw("\nHowever, your score is %ld.",score); + refresh(); + return; + } + if(playerrank == 0){ + char formername[60]={0}; + long formerscore=0; + rewind(score_file); + fscanf(score_file,"%*s : %*d\n"); + move(3,0); + byte b=0; + if ( fscanf(score_file,"%s : %ld\n",formername,&formerscore)==2){ + halfdelay(1); + printw("*****CONGRATULATIONS!****\n"); + printw(" You beat the\n"); + printw(" previous\n"); + printw(" record\n"); + printw(" of\n"); + printw(" %14ld\n",formerscore); + printw(" held by\n"); + printw(" %11s\n",formername); + printw(" \n"); + printw(" \n"); + printw("*************************\n"); + printw("Press a key to proceed:"); + Effect: + move(4,0); + mvprintw(4,0, " _____ "); + mvprintw(5,0, " .' |"); + mvprintw(6,0, " .' |"); + mvprintw(7,0, " | .| |"); + mvprintw(8,0, " |.' | |"); + mvprintw(9,0, " | |"); + mvprintw(10,0," ___| |___"); + mvprintw(11,0," | |"); + mvprintw(12,0," |____________|"); + b=(b+1)%6; + if(getch()==ERR) + goto Effect; + nocbreak(); + cbreak(); + erase(); + logo(0,0); + } + } + //scorefile is still open with w+ + move(3,0); + char pname[60] = {0}; + long pscore=0; + byte rank=0; + rewind(score_file); + printw(">*>*>Top %d<*<*<\n",SAVE_TO_NUM); + while( rank>>"); + printw("%d) %s : %ld\n",rank+1,pname,pscore); + ++rank; + } + addch('\n'); + refresh(); +} + +//display +void draw(byte sy,byte sx,byte board[size][size]){ + rectangle(sy,sx); + mvprintw(1,sx+12,"Score: %ld",score); + chtype prnt; + byte y,x; + for(y=0;y3 && y<17 && x>3 && x<17){ + board[y][x]= BLOCK; + } + else{ + board[y][x]= EMPTY; + } + } + } + py=size/2; + px=size/2; + board[py][px]=EMPTY; +} +void put_cats(byte board[size][size], byte number){ + byte y,x; + for(byte i=0;i=size || x+dx>=size)&&(board[y+dy][x+dx]==EMPTY)){\ + board[y][x]=EMPTY;\ + board[y+dy][x+dx]=CAT_NEW;\ + goto Next;\ + } +byte cat_life(byte board[size][size]){ + byte y,x,dy,dx,predy,predx; + byte only_old=1; + for(y=0;yy){ + dy=1; + } + if(px>x){ + dx=1; + } + MOVE_CAT; + + predy=dy; + predx=dx; + dy=0; + dx=predx; + MOVE_CAT; + + dy=predy; + dx=0; + MOVE_CAT; + + dx=-1+(rand()%3); + MOVE_CAT; + + dy=-1+(rand()%3); + MOVE_CAT; + + for(dy=-1;dy<2;++dy){ + for(dx=-1;dx<2;++dx){ + MOVE_CAT; + } + } + + } + Next: continue; + } + } + + for(y=0;y=0 && x>=0 && y0){ + tile_push(board,-1,0); + } + if( (input=='j' || (input==KEY_DOWN||input=='s')) && py0){ + tile_push(board,0,-1); + } + if( (input=='l' || (input==KEY_RIGHT||input=='d')) && px last_wave+300 && waves_count<5)){ + put_cats(board,2+(rand()%7)); + last_wave=time(0); + waves_count++; + } + if(no_cat_life){ + waves_count=0; + } + last_move=time(0); + } + if(board[py][px]==CAT){ + break; + } + } + flushinp(); + nocbreak(); + cbreak(); + logo(0,0); + draw(3,0,board); + refresh(); + move(25,0); + printw("You lost The Game. Press a key to see high scores:"); + getch(); + show_scores(save_score()); + if(!no_replay){ + printw("You lost The Game. Wanna play again?(y/n)"); + refresh(); + curs_set(1); + input=getch(); + while(input!='n'&&input!='N'&&input!='q'&&input!='Q'&&input!='y'&&input!='\n'){ + input=getch(); + } + + if(input != 'N' && input != 'n' && input != 'q') + goto Start; + } + else{ + printw(" Press any key on this computer's keyboard if you want to continue."); + getch(); + } + endwin(); + return EXIT_SUCCESS; +}