/* .-. |_.' | \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; }