From a5e83d6a56eea48debc054444434546d121adc5f Mon Sep 17 00:00:00 2001 From: untakenstupdnick Date: Mon, 18 May 2020 23:29:29 +0430 Subject: [PATCH] Going for version 3! --- README.md | 31 +- sources/.#mines.c | 1 + sources/.jewels.c.swp | Bin 0 -> 16384 bytes sources/Makefile | 20 +- sources/battleship.c | 190 ++++++------ sources/checkers.c | 79 ++--- sources/config.h | 3 + sources/fifteen.c | 70 ++--- sources/fisher.c | 415 +++++++++++++++++++++++++++ sources/jewels.c | 77 ++--- sources/memoblocks.c | 102 +++---- sources/miketron.c | 538 ++++++++++++++++++++++++++++++++++ sources/mines.c | 98 +++---- sources/muncher.c | 451 +++++++++++++++++++++++++++++ sources/pipes.c | 230 +++++++-------- sources/rabbithole.c | 95 +++--- sources/redsquare.c | 650 ++++++++++++++++++++++++++++++++++++++++++ sources/reversi.c | 61 ++-- sources/sos.c | 184 ++++++------ sources/sudoku.c | 118 ++++---- 20 files changed, 2745 insertions(+), 668 deletions(-) create mode 120000 sources/.#mines.c create mode 100644 sources/.jewels.c.swp create mode 100644 sources/fisher.c create mode 100644 sources/miketron.c create mode 100644 sources/muncher.c create mode 100644 sources/redsquare.c diff --git a/README.md b/README.md index 7389672..eea0ab9 100644 --- a/README.md +++ b/README.md @@ -24,22 +24,10 @@ These include: * Pipes (Same as the famous Pipe Mania, unplayable on the environments that don't support the line characters) * Fifteen * Memoblocks (or Memory blocks. A similar game was included in Windows 7) - -## Features -* Modern looking TUI -* Color -* Mouse support -* Multiplayer (not network) -* Each game containing help pages on the controls and the gameplay -* Very permissive license (Public Domain equivalent) -* Clean code with documentation -* Small size, with the deb package being less than 50 KB as I write this -* Low in dependencies and very simple build, even in comparison to bsdgames -* Low in CPU usage (Low if you are playing against AI, virtually nothing otherwise) -* Low as possible in memory footprint -* Diversity, you will like one at least -* Portability -* Flexiblity +* Fisher +* Muncher +* Miketron +* Redsquare They natively run on Linux, BSD, MacOS and are known to work on Windows as well (using PDCurses, thanks to Laura Michaels for providing advice). @@ -81,10 +69,9 @@ It's been made available for openSUSE thanks to Jan Brezina: https://build.opens ## How to contribute -Oh, so kind! You can... * Share these with your friends -* Tell me your feature requests, bug reports, games you want to be added etc. (Think of games in spirit of those already included and look if there is not a good terminal game for it already) -* Make a package for your distro (or put it on repos and tell me afterwards) -* Tell me if you're interested in porting it to non-Unix (Possible in theory since there is PDCurses for SDL, and SDL for everything) -* With mouse support, PDCurses, SDL and NDK existing, now it is possible to port it to Android proper, feel free to tell me if you are doing it. -* Pull requests are of course, welcome too! +* Tell me your feature requests, bug reports, etc. +* Tell me the games you want to be added (in the same genre, i can't port Angry Birds to curses! :) +* Make a package for your distro (or put it on repos if it's not there) + +Also thank to all the people who helped in the previous versions, i didn't expect such assistance <3 diff --git a/sources/.#mines.c b/sources/.#mines.c new file mode 120000 index 0000000..0428973 --- /dev/null +++ b/sources/.#mines.c @@ -0,0 +1 @@ +user@laptop.7227:1577913591 \ No newline at end of file diff --git a/sources/.jewels.c.swp b/sources/.jewels.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..ba71b0cac2804c7269f7a359bb4021bf4829e859 GIT binary patch literal 16384 zcmeI2TZ|-C8OIAjq!heh7UPRK(=a>T(>;9|c84spwQ-njmVw@$buPd%JG9kZr>3jB zx~i$Fo}OlB0aqW?7kGkz0*UcPM59C!FQ6t~6E#sEcu)fR=tdvB1dNI3|2uW*>X}|w zo`^|R=GWDI>YP*O{Lgnzo$s5f7w=p;$!^LYl5o6Nl3u>!jm_7uctLtKCrLe*JCuB> z!&JMT-Mv&UNqT@PEc9)sZCG0ctL|!BYKOZ8*X}tDoLjulO*h}TbWKT)M1e$sH?P1o z(v7pFB9*&7HNoD0?fRRqA}Nt5kSLHSkSLHSkSLHSkSLHSkSOqftAN+NTzU|#e_POl z`-1ajd(Qt3ju(RTFfb72yF5t0J2>Zq3*q%3IXNW?Bnl)7Bnl)7Bnl)7Bnl)7Bnl)7 zBnl)7BnrF*3aFYSk&pfd`oRDHL;wFz?~$b6f}eorz*FGU;4Cn~8Bhkt!2-A$906B> zC*CbdkAw5zW8eVz<~5R}f_uRxSOi&c09*!Mz8d!ckAMwuJ2(KY1TVfzlD-bU3cd&) z2X*k%cOo4;3!VXA1`mM^a1WRO7i3BLBltOZ20Q{D29w~=S4q;h!IR*#zyT}ZHZTwV z`3_0?JNO}Z4m<=}U<>G=4D#SQZ~(k`C9Z)Fg1^08l70og2m0Ux;2QAPDr1>Ry8axPU;4mnGJjjBpz+W(yVm!&7WYe~` zSl4aX4p)lvlH6#j4(nQY^I~JJxXBcDws;Q7g@VYU8zyIl%UsVeO=fqw#rlTVWc{op zpOa)6e{_<&j$wIvIyHT<9*71 z4)tcw-9*Od17Dil)L4Bm=DztU=GQw}I%I0YT7@8cszt`UpPA|o4_n_~Eo$`-k)6Ie z9D_jh@2L}2`gwz#U59TQc8~hEFDD}vYBj3vwB2KM?lG^)_vJieiE&w6uAW#~SX-|w ztSv29S0^Yj%xmZ@&2+b+T6#Jf`dn(#WjC|QxC|t2?w~KUFNvbeX3k=4$CREH#iyfQ zI=pXK+VBRVL&79u6$-ob4Rbi2WSxp{n}(k5n(BZ%j%u};qOc-vzik^DbDMTww8>4^ z2Oej`Y{+p=BAMuLxYu(mI?YQW0Ux?<_T1)3%fd^;f?-N{)&sl0h+rgDy{GFNrrl6I z!?reaBIjrtGzjYp&*))T_4a;ERt9ydI8@F0t>8=k|}Mw4rqebrpN z;Xy@8Y5%>$Hb5OEyvfCLT|$8^?s027omyWlucR`5@5lFdBG$L4^T(8^cWif;3Gt38 z<1}O#;IQQ|ny3cYQrL;3vC85CjuAL2lg*;usN%Y9n=F(Li)VO4VQbI}tLIEiQIQ;V zASR~2cJdv=OPB9nTC1(DFD{l>SH)xqSJE@qT9Y%e{$fsAwui|r7GSP11FLX0AIx0X z%0y&;Xss+qztA3?*6egR47cA^TU}gUDX(HISgM~*Wf&G^yk*CuzKkgymCA`C^MwNH zV-DtkWi)`|}Xf4v$0I zVK7h@O$z4O%=S0Bewo?USW3@s{wE%euB}&?A->M~9o@aZ5wv zHC2z+sg_^5wUcWN=2@Yj8;2AywQj49 zwoxfpH#hEDIu6sMypWE$#+HS(T39kQ97a1`kSYdjYmIx3;pS+^)~9{7X`|1ykkSj# ztlz{gn|?L8<#8umWP9B%cRDs2?bvj%PGfY}Ostv>oGq z2##M=1}Yr#dn`t3;NP6@bWK|$gV&ggoe#s(p01=RrI_;WpcKIjrgywcYd#)iHGR{is^U z&kuV&Pt6Ux@K)bq__BWZBLkT0HQ8t9lin&ufDKAO_#k;arp{{MOS zu5ZBKCI3JC|NRB{@!to}g3o}D109?I2f=Ib>0bih0#Abn!C9~a`rsaL9OS{(-~xR7 zSHZ8r3*ZajQSeFd2`~U1pn;R12tEX^1{V+m_!;;v_zHLoJPOW(9`L|NK^5Er6mTuL z47`Lm!H>a{;9<}QMKA&02QCM%Ax`jn@H_A$@H}`5oCiH%0*WV8!4fzIj(|LP1#yJm zfFFS8!8gFyz?Z-ifMN|gm;=`V36R$RBE6F%Q6NzuQ6NzuQ6N#^El>ddR1g}Bhh^Yz z#o~%FKS+GdkWUu|ZD>c|geTJYSK;}yKR%}9tHnJ4HQL`ng5S~SVM$&F1v6M zgwKlDKQ+o#{H9TBLO&MYM)C!Lm2^Bmyx_0|gM({W-JYi?Q*25k%Ud?K^rT8uZ#>t1 zelEX7P1V#jc!-0v*oh0DT$bT4H=2Qja!hG7ZA5wecDN4zBg)*_hTDWuOIMbv<<*(l z+~RU&wJ=a7CbzyCIJ!mPp!G_i22+{;WeG0tRRv3~@fke?GHleWc%1TD$@KY2P8>gYAyFx2r zE(k1;Im*I!R|20MF5v9uu9#aJ;(M5*6w6VHFnnt1%;a2AD{asw;lYMGbRpXS&8KG1%f4tsKz*jL^qUJj(rM=fXqIX z!qicvT%jX5pXus)rIMLkU#hOvPA=RH1C6a@L3=FvS0pCV@=ER0!qQ6G3XG9r`=Wje zQdvjm<}DGThtXJuSED#ZdX6R_$}OH=sD}1Gym~medb(VxEZ?>N`k~=0 ) || (!ingame && minput.x-1<20) ){//it most be on the trackboard if ingame is true - py=minput.y-4; - px=(minput.x-1-(ingame*2)) /2; + py=minput.y-4; + px=(minput.x-1-(ingame*2)) /2; } - } + } else return; } - if(minput.bstate & (BUTTON1_CLICKED|BUTTON1_RELEASED)) - ungetch('\n'); - if(minput.bstate & (BUTTON2_CLICKED|BUTTON2_RELEASED|BUTTON3_CLICKED|BUTTON3_RELEASED) ) - ungetch('r'); + if(minput.bstate & (BUTTON1_CLICKED|BUTTON1_RELEASED)) + ungetch('\n'); + if(minput.bstate & (BUTTON2_CLICKED|BUTTON2_RELEASED|BUTTON3_CLICKED|BUTTON3_RELEASED) ) + ungetch('r'); } void rectangle(byte sy,byte sx){ for(byte y=0;y<=10+1;y++){ @@ -138,9 +138,17 @@ void header(bool side){ mvaddch(0,1, '_'); mvprintw(1,0,"|_) %2d:%2d",score[side],score[!side]); mvprintw(2,0,"|_)ATTLESHIP "); + if(multiplayer){ + attron(colors[side]); + if(side) + printw("Yellow's turn"); + else + printw("Green's turn"); + attroff(colors[side]); + } } -void draw(bool side,byte sy,byte sx){//the game's board +void draw(bool side,byte sy,byte sx,bool regular){//the game's board rectangle(sy,sx); chtype ch ; byte y,x; @@ -151,12 +159,14 @@ void draw(bool side,byte sy,byte sx){//the game's board ch |= A_STANDOUT; if(game[side][y][x] == HIT) ch |= 'X'|colors[RED]; - else if(game[side][y][x] > 0 ) + else if(game[side][y][x] > 0 && !(multiplayer&®ular) ) ch |= ACS_BLOCK|colors[side]; else if(game[side][y][x]== MISS) ch |= 'O'|colors[CYAN]; - else + else if(!(multiplayer&®ular)) ch |= '~'|colors[CYAN]; + else + ch |=' '; mvaddch(sy+1+y,sx+x*2+1,ch); } @@ -164,25 +174,25 @@ void draw(bool side,byte sy,byte sx){//the game's board } void draw_trackboard(bool side,byte sy,byte sx){ rectangle(sy,sx); - chtype ch ; - byte y,x; - for(y=0;y<10;y++){ - for(x=0;x<10;x++){ - ch =A_NORMAL; - if(y==py && x==px-10) - ch |= A_STANDOUT; + chtype ch ; + byte y,x; + for(y=0;y<10;y++){ + for(x=0;x<10;x++){ + ch =A_NORMAL; + if(y==py && x==px-10) + ch |= A_STANDOUT; - if(game[!side][y][x] == HIT) - ch |= '*'|colors[RED]; - else if(game[!side][y][x]== MISS) - ch |= '~'|colors[CYAN]; - else - ch |= '.'; + if(game[!side][y][x] == HIT) + ch |= '*'|colors[RED]; + else if(game[!side][y][x]== MISS) + ch |= '~'|colors[CYAN]; + else + ch |= '.'; - mvaddch(sy+1+y,sx+x*2+1,ch); - } - } - refresh(); + mvaddch(sy+1+y,sx+x*2+1,ch); + } + } + refresh(); } void autoset(bool side){ @@ -237,19 +247,19 @@ void set_the_board(bool side){ addstr(" in its position: "); SetLocation: while(1){ - draw(side,3,0); + draw(side,3,0,false); refresh(); input = getch(); if( input == KEY_MOUSE ) mouseinput(0); if( (input=='k' || input==KEY_UP) && py>0) - py--; - if( (input=='j' || input==KEY_DOWN) && py<9) - py++; - if( (input=='h' || input==KEY_LEFT) && px>0) - px--; - if( (input=='l' || input==KEY_RIGHT) && px<9) - px++; + py--; + if( (input=='j' || input==KEY_DOWN) && py<9) + py++; + if( (input=='h' || input==KEY_LEFT) && px>0) + px--; + if( (input=='l' || input==KEY_RIGHT) && px<9) + px++; if( input=='\n' ) break; if( input=='q' ) @@ -280,7 +290,7 @@ void set_the_board(bool side){ } while(1){ invain=0; - draw(side,3,0); + draw(side,3,0,false); input=getch(); if( input== 'r' || input == 'R' ){ genocide(side,type); @@ -480,41 +490,41 @@ void decide(bool side){// sink_announce is responsible for unsetting the global } } void help(bool side){//side is only there to feed header() - erase(); + erase(); header(side); - attron(A_BOLD); - mvprintw(3,0," **** THE CONTROLS ****"); - mvprintw(9,0,"YOU CAN ALSO USE THE MOUSE!"); - attroff(A_BOLD); - mvprintw(4,0,"RETURN/ENTER : Shoot"); - mvprintw(5,0,"R : Rotate"); - mvprintw(6,0,"hjkl/ARROW KEYS : Move cursor"); - mvprintw(7,0,"q : Quit"); + attron(A_BOLD); + mvprintw(3,0," **** THE CONTROLS ****"); + mvprintw(9,0,"YOU CAN ALSO USE THE MOUSE!"); + attroff(A_BOLD); + mvprintw(4,0,"RETURN/ENTER : Shoot"); + mvprintw(5,0,"R : Rotate"); + mvprintw(6,0,"hjkl/ARROW KEYS : Move cursor"); + mvprintw(7,0,"q : Quit"); mvprintw(8,0,"F1 & F2 : Help on controls & gameplay"); - mvprintw(11,0,"Press a key to continue"); - getch(); + mvprintw(11,0,"Press a key to continue"); + getch(); erase(); } void gameplay(bool side){//side is only there to feed header() - erase(); - header(side); - attron(A_BOLD); - mvprintw(3,0," **** THE GAMEPLAY ****"); - attroff(A_BOLD); + erase(); + header(side); + attron(A_BOLD); + mvprintw(3,0," **** THE GAMEPLAY ****"); + attroff(A_BOLD); move(4,0); printw("Guess the location of your opponet's\n"); printw("ships and sink them! The player\n"); printw("who sinks all the opponet's ships wins."); - getch(); - erase(); + getch(); + erase(); } int main(void){ initscr(); mousemask(ALL_MOUSE_EVENTS,NULL); - curs_set(0); - noecho(); - cbreak(); - keypad(stdscr,1); + curs_set(0); + noecho(); + cbreak(); + keypad(stdscr,1); if( has_colors() ){ start_color(); use_default_colors(); @@ -526,23 +536,23 @@ int main(void){ colors[b]=COLOR_PAIR(b+1); } int input; - printw("Choose type of the game:\n"); + printw("Choose type of the game:\n"); printw("1 : Single Player*\n"); printw("2 : Multi Player\n"); refresh(); - input=getch(); - if(input == '2'){ + input=getch(); + if(input == '2'){ multiplayer=1; - computer[1]=computer[0]=0; - } - else{ + computer[1]=computer[0]=0; + } + else{ multiplayer=0; - computer[1]=1; + computer[1]=1; computer[0]=0; - } + } Start: firstinrowy=firstinrowx=lastinrowy=lastinrowx=goindirection=NOTHING; - shotinvain=0; + shotinvain=0; sunk[0]=sunk[1]=0; memset(game,SEA,200); srand(time(NULL)%UINT_MAX); @@ -558,16 +568,16 @@ int main(void){ py=0; sink_announce(turn); if( sunk[0]==ALL ){ - won=1; - goto End; - } - else if( sunk[1]==ALL ){ - won=0; - goto End; - } + won=1; + goto End; + } + else if( sunk[1]==ALL ){ + won=0; + goto End; + } //the turn starts HERE turn=!turn; - turn_shift(); + //turn_shift(); if( computer[turn] ){ decide(turn); goto Turn; @@ -577,7 +587,7 @@ int main(void){ you_sunk(turn); while(1){ header(turn); - draw(turn,3,0); + draw(turn,3,0,true); draw_trackboard(turn,3,22); refresh(); input=getch(); @@ -588,14 +598,14 @@ int main(void){ if(input == KEY_MOUSE) mouseinput(1); if( (input=='k' || input==KEY_UP) && py>0) - py--; - if( (input=='j' || input==KEY_DOWN) && py<9) - py++; - if( (input=='h' || input==KEY_LEFT) && px>10) - px--; - if( (input=='l' || input==KEY_RIGHT) && px<19) - px++; - if( input=='q') + py--; + if( (input=='j' || input==KEY_DOWN) && py<9) + py++; + if( (input=='h' || input==KEY_LEFT) && px>10) + px--; + if( (input=='l' || input==KEY_RIGHT) && px<19) + px++; + if( input=='q') sigint_handler(EXIT_SUCCESS); if( input=='\n'){ byte r=shoot(turn,py,px-10); @@ -608,7 +618,7 @@ int main(void){ End: erase(); header(won); - draw(won,3,0); + draw(won,3,0,false); draw_trackboard(won,3,22); if( computer[won] ) mvaddstr(15,0,"Hahaha! I won! "); diff --git a/sources/checkers.c b/sources/checkers.c index 0bd4a2d..5068ee8 100644 --- a/sources/checkers.c +++ b/sources/checkers.c @@ -37,10 +37,10 @@ byte jumpagainy , jumpagainx; bool kinged;//if a piece jumps over multiple others and becomes a king it cannot continue jumping bool in(byte A[4],byte B[4],byte a,byte b){ - for(byte c=0;c<4;c++) - if(A[c]==a && B[c]==b) - return true; - return false; + for(byte c=0;c<4;c++) + if(A[c]==a && B[c]==b) + return true; + return false; } void rectangle(byte sy,byte sx){ byte y,x; @@ -97,7 +97,7 @@ void draw(byte sy,byte sx){//the game's board else ch |='K'; } - else if( (y%2) != (x%2) ) + else if( (y%2) != (x%2) ) ch|='.'; else ch|=' '; @@ -439,44 +439,44 @@ void sigint_handler(int x){ } void mouseinput(void){ - MEVENT minput; + MEVENT minput; #ifdef PDCURSES nc_getmouse(&minput); #else getmouse(&minput); #endif - if( minput.y-4 <8 && minput.x-1<16){ - py=minput.y-4; - px=(minput.x-1)/2; - } - else - return; - if(minput.bstate & (BUTTON1_CLICKED|BUTTON1_PRESSED|BUTTON1_RELEASED) ) - ungetch('\n'); + if( minput.y-4 <8 && minput.x-1<16){ + py=minput.y-4; + px=(minput.x-1)/2; + } + else + return; + if(minput.bstate & (BUTTON1_CLICKED|BUTTON1_PRESSED|BUTTON1_RELEASED) ) + ungetch('\n'); } void help(void){ - erase(); + erase(); header(); - attron(A_BOLD); - mvprintw(3,0," **** THE CONTROLS ****"); - mvprintw(9,0,"YOU CAN ALSO USE THE MOUSE!"); - attroff(A_BOLD); - mvprintw(4,0,"RETURN/ENTER : Select or move the piece"); - mvprintw(5,0,"SPACE : Flag/Unflag"); - mvprintw(6,0,"hjkl/ARROW KEYS : Move cursor"); - mvprintw(7,0,"q : quit"); + attron(A_BOLD); + mvprintw(3,0," **** THE CONTROLS ****"); + mvprintw(9,0,"YOU CAN ALSO USE THE MOUSE!"); + attroff(A_BOLD); + mvprintw(4,0,"RETURN/ENTER : Select or move the piece"); + mvprintw(5,0,"SPACE : Flag/Unflag"); + mvprintw(6,0,"hjkl/ARROW KEYS : Move cursor"); + mvprintw(7,0,"q : quit"); mvprintw(8,0,"F1 & F2 : Help on controls & gameplay"); - mvprintw(11,0,"Press a key to continue"); + mvprintw(11,0,"Press a key to continue"); refresh(); - getch(); + getch(); erase(); } void gameplay(void){ - erase(); - header(); - attron(A_BOLD); - mvprintw(3,0," **** THE GAMEPLAY ****"); - attroff(A_BOLD); + erase(); + header(); + attron(A_BOLD); + mvprintw(3,0," **** THE GAMEPLAY ****"); + attroff(A_BOLD); move(4,0); printw("1) The game starts with each player having 12 men;\n"); printw(" men can only diagonally move forwards \n"); @@ -490,9 +490,9 @@ void gameplay(void){ printw("4) You have to do a jump if you can.\n\n"); printw("5) A player wins when the opponet can't do a move e. g. \n"); printw(" all of their pieces are captured.\n\n"); - refresh(); - getch(); - erase(); + refresh(); + getch(); + erase(); } int main(int argc,char** argv){ dpt=4; @@ -525,7 +525,7 @@ int main(int argc,char** argv){ computer[0]=0; printw("Human.\n"); } - printw("Choose type of the light player(h/C)\n"); + printw("Choose type of the bright player(h/C)\n"); refresh(); input=getch(); if(input=='h'){ @@ -604,6 +604,15 @@ int main(int argc,char** argv){ erase(); draw(3,0); header(); + if(!(computer[0]||computer[1])){ + if(t) + addstr(" Bright's turn"); + else{ + attron(COLOR_PAIR(1)); + addstr(" Dark's turn"); + attroff(COLOR_PAIR(1)); + } + } refresh(); input=getch(); if( input == KEY_F(1) || input=='?' ) @@ -661,7 +670,7 @@ int main(int argc,char** argv){ printw("Draw."); break; case 1: - printw("The light side has won the game."); + printw("The bright side has won the game."); break; case 2: printw("You resigned."); diff --git a/sources/config.h b/sources/config.h index 28283a5..ee193af 100644 --- a/sources/config.h +++ b/sources/config.h @@ -1,3 +1,6 @@ #define PP_SCORES "/usr/games/pp_scores" #define JW_SCORES "/usr/games/jw_scores" +#define FSH_SCORES "/usr/games/fsh_scores" +#define MNCH_SCORES "/usr/games/mnch_scores" +#define MT_SCORES "/usr/games/mt_scores" //for easier access diff --git a/sources/fifteen.c b/sources/fifteen.c index 410fda0..7f4b751 100644 --- a/sources/fifteen.c +++ b/sources/fifteen.c @@ -42,13 +42,13 @@ void logo(byte sy,byte sx){ char int2sgn(byte num){ if(!num) return ' '; - else if(0< num && num <= 9) - return num+'0'; - else if(10<=num && num <=35) - return num-10+'a'; - else if(36<=num && num <=51) - return num-36+'A'; - return 0; + else if(0< num && num <= 9) + return num+'0'; + else if(10<=num && num <=35) + return num-10+'a'; + else if(36<=num && num <=51) + return num-36+'A'; + return 0; } /*bool isinorder(byte board[size][size],byte y,byte x){ using check[][] is much cheaper return (board[y][x] == y*size+x+1); @@ -150,38 +150,38 @@ void mouseinput(void){ ungetch('\n'); } void help(void){ - erase(); + erase(); logo(0,0); - attron(A_BOLD); - mvprintw(3,0," **** THE CONTROLS ****"); + attron(A_BOLD); + mvprintw(3,0," **** THE CONTROLS ****"); mvprintw(8,0,"YOU CAN ALSO USE THE MOUSE!"); - attroff(A_BOLD); + attroff(A_BOLD); mvprintw(4,0,"RETURN/ENTER : Slide"); - mvprintw(5,0,"hjkl/ARROW KEYS : Move cursor"); - mvprintw(6,0,"q : Quit"); + mvprintw(5,0,"hjkl/ARROW KEYS : Move cursor"); + mvprintw(6,0,"q : Quit"); mvprintw(7,0,"F1 & F2 : Help on controls & gameplay"); - mvprintw(10,0,"Press a key to continue"); + mvprintw(10,0,"Press a key to continue"); refresh(); - getch(); + getch(); erase(); } void gameplay(void){ - erase(); + erase(); logo(0,0); - attron(A_BOLD); - mvprintw(3,0," **** THE GAMEPLAY ****"); - attroff(A_BOLD); + attron(A_BOLD); + mvprintw(3,0," **** THE GAMEPLAY ****"); + attroff(A_BOLD); mvprintw(4,0,"Slide the tiles until the numbers and characters are\n"); printw("in the right order.\n"); - refresh(); - getch(); - erase(); + refresh(); + getch(); + erase(); } int main(int argc, char** argv){ size=4; if(argc==2){ if(!strcmp("help",argv[1])){ - printf("Usage: %s [size]\n",argv[0]); + printf("Usage: %s [size]\n",argv[0]); return EXIT_SUCCESS; } size=atoi(argv[1]); @@ -193,20 +193,20 @@ int main(int argc, char** argv){ signal(SIGINT,sigint_handler); srand(time(NULL)%UINT_MAX); initscr(); - mousemask(ALL_MOUSE_EVENTS,NULL); - noecho(); - cbreak(); - keypad(stdscr,1); - if(has_colors()){ - start_color(); - use_default_colors(); - init_pair(1,COLOR_GREEN,-1); - green=COLOR_PAIR(1); - } - char board[size][size]; + mousemask(ALL_MOUSE_EVENTS,NULL); + noecho(); + cbreak(); + keypad(stdscr,1); + if(has_colors()){ + start_color(); + use_default_colors(); + init_pair(1,COLOR_GREEN,-1); + green=COLOR_PAIR(1); + } + char board[size][size]; char check[size][size]; fill(check); - int input; + int input; Start: py=px=0; ey=ex=size-1; diff --git a/sources/fisher.c b/sources/fisher.c new file mode 100644 index 0000000..80d700e --- /dev/null +++ b/sources/fisher.c @@ -0,0 +1,415 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#define SAVE_TO_NUM 11 +#define HOOKS 10 +#define LEN 24 +#define HLEN LEN/2 +#define WID 80 +#define HWID WID/2 +typedef signed char byte; +chtype colors[4]={A_NORMAL,A_STANDOUT}; +byte fish[10]={0};//positions +byte caught=-1; +bool stop[10]={0}; +unsigned int count[10]={0}; +unsigned long score=0; +const char sym[]="~:=!@+><;&"; +byte hook=0, hooknum=0; +char error [150]={0}; +byte clb,clbtime=0; +FILE* scorefile; + +int input; +/* + O__/| + ___|_/ | __ +| / | |__ + | ISHER*/ +// 12 lines of water +// 80 columns +byte digit_count(int num){ + byte ret=0; + do{ + ret++; + num/=10; + }while(num); + return ret; +} +void filled_rect(byte sy,byte sx,byte ey,byte ex){ + byte y,x; + for(y=sy;y=itreached || score>=scorebuff[location]) ){ + fprintf(scorefile,"%s : %ld\n",getenv("USER"),score); + ret=location; + wroteit=1; + } + if(location0){ + byte a = (LEN-9)/2; + star_line(1); + star_line(LEN-2); + mvaddstr(1,WID/2-8,"CONGRATULATIONS!!"); + mvprintw(a+1,HWID-10," _____ You bet the"); + mvprintw(a+2,HWID-10," .' | previous"); + mvprintw(a+3,HWID-10," .' | record"); + mvprintw(a+4,HWID-10," | .| | of"); + mvprintw(a+5,HWID-10," |.' | |%11ld",formerscore); + mvprintw(a+6,HWID-10," | | held by"); + mvprintw(a+7,HWID-10," ___| |___%7s!",formername); + mvprintw(a+8,HWID-10," | |"); + mvprintw(a+9,HWID-10," |____________|"); + mvprintw(LEN-3,HWID-11,"Press a key to continue"); + refresh(); + do{ + input=getch(); + }while(input==KEY_UP || input==KEY_DOWN); + filled_rect(0,0,LEN,WID); + green_border(); + } + + } + //scorefile is still open with w+ + char pname[60] = {0}; + long pscore=0; + byte rank=0; + rewind(scorefile); + mvaddstr(1,WID/2-4,"HIGH SCORES"); + attron(colors[3]); + while( rank>>"); + printw("%s",pname); + mvprintw(2+2*rank,WID-1-digit_count(pscore),"%d",pscore); + rank++; + } + attroff(colors[3]); + refresh(); +} +void help(void){ + nocbreak(); + cbreak(); + attron(colors[3]); + filled_rect(0,0,LEN,WID); + green_border(); + mvprintw(1,HWID-4,"GAME PLAY"); + mvprintw(3,1,"Catch a fish and reel it in for points"); + mvprintw(4,1,"The deeper the fish, the more points it is worth."); + mvprintw(5,1,"If a fish hits your line, you lose a hook."); + mvprintw(6,1,"When you run out of hooks, the game is over!"); + mvprintw(8,HWID-4,"CONTROLS"); + mvprintw(10,1,"UP & DOWN: Control the hook"); + mvprintw(11,1,"q: Quit"); + mvprintw(13,1,"This is a port of \"Deep Sea Fisher\", a MikeOS game."); + attroff(colors[3]); + refresh(); + getch(); + halfdelay(1); +} +void sigint_handler(int x){ + endwin(); + puts("Quit."); + exit(x); +} +int main(void){ + signal(SIGINT,sigint_handler); + initscr(); + noecho(); + cbreak(); + keypad(stdscr,1); + srand(time(NULL)%UINT_MAX); + for(byte n=0;n<10;n++) + fish[n]=rand()%80; + if(has_colors()){ + start_color(); + init_pair(1,COLOR_BLACK,COLOR_CYAN); + init_pair(2,COLOR_BLACK,COLOR_BLUE); + init_pair(3,COLOR_WHITE,COLOR_GREEN); + init_pair(4,COLOR_BLACK,COLOR_WHITE); + for(byte b=0;b<4;b++) + colors[b]=COLOR_PAIR(b+1); + } + byte n; + Start: + halfdelay(1); + curs_set(0); + hook=0; + hooknum=HOOKS; + score=0; + while(1){ + draw(); + refresh(); + input=getch(); + for(n=0;n<10;n++){ + if(stop[n]){ + if(rand()%(n+15)==0)//this is to make the fish move + stop[n]=0; + continue; + } + if(n%2) + fish[n]--; + else + fish[n]++; + if(fish[n]<0) + fish[n]=79; + if(fish[n]>79) + fish[n]=0;//appear on the other end + if(fish[n]==40){ + if(hook>n+1){ + caught= -1; + hook=0; + hooknum--; + } + if(hook==n+1 && caught==-1){ + caught=n; + if(n%2) + fish[n]=79; + else + fish[n]=0; + } + } + if(rand()%(14-n)==0)//this is to make it stop + stop[n]=1; + } + if(input==KEY_UP) + if(hook>0) + hook--; + if(hook==0 && caught!=-1){ + count[caught]++; + score+=(caught+1)*(caught+1); + clb=caught; + clbtime=10;//celebrate catching the fish + caught=-1; + } + + if(input==KEY_DOWN){ + if(hook<11) + hook++; + if(fish[hook-1]==40 && caught==-1){ + caught=hook-1; + if(n%2) + fish[hook-1]=0; + else + fish[hook-1]=79; + } + } + if(input=='?' || input==KEY_F(1)) + help(); + if(input=='q') + break; + if(!hooknum) + break; + if(input!=ERR){ + usleep(100000); + flushinp(); + } + } + End: + flushinp(); + nocbreak(); + cbreak(); + curs_set(1); + showscores(scorewrite()); + attron(colors[2]); + mvprintw(LEN-1,HWID-11,"Wanna play again? (y/n)"); + attroff(colors[2]); + do{ + input=getch(); + }while(input==KEY_UP || input==KEY_DOWN); + if(input!='q' && input!='n' && input!='N') + goto Start; + endwin(); +} diff --git a/sources/jewels.c b/sources/jewels.c index 81f5c0f..f1816e9 100644 --- a/sources/jewels.c +++ b/sources/jewels.c @@ -33,7 +33,7 @@ char* controls = "j,l-Move k-Rotate p-Pause q-Quit"; FILE* scorefile; byte scorewrite(long score){// only saves the top 10 bool deforno; - if( !getenv("JW_SCORES") && (scorefile= fopen(JW_SCORES,"r")) ){ + if( !getenv("JW_SCORES") && (scorefile= fopen(JW_SCORES,"r")) ){ deforno=1; } else{ @@ -44,26 +44,26 @@ byte scorewrite(long score){// only saves the top 10 } } - char namebuff[SAVE_TO_NUM][60]; - long scorebuff[SAVE_TO_NUM]; + char namebuff[SAVE_TO_NUM][60]; + long scorebuff[SAVE_TO_NUM]; - memset(namebuff,0,SAVE_TO_NUM*60*sizeof(char) ); - memset(scorebuff,0,SAVE_TO_NUM*sizeof(long) ); + memset(namebuff,0,SAVE_TO_NUM*60*sizeof(char) ); + memset(scorebuff,0,SAVE_TO_NUM*sizeof(long) ); - long fuckingscore =0; - char fuckingname[60]={0}; - byte location=0; + long fuckingscore =0; + char fuckingname[60]={0}; + byte location=0; - while( fscanf(scorefile,"%59s : %ld\n",fuckingname,&fuckingscore) == 2 && location=itreached || score>=scorebuff[location]) ){ - fprintf(scorefile,"%s : %ld\n",getenv("USER"),score); - ret=location; - wroteit=1; - } - if(location=itreached || score>=scorebuff[location]) ){ + fprintf(scorefile,"%s : %ld\n",getenv("USER"),score); + ret=location; + wroteit=1; + } + if(location=3 && y==LEN-1){ y++; goto VrExplsn; } } - else if(n>=3){ + else if(n>=3){ VrExplsn: score+=n*10*(n-2)*combo; ret=1; diff --git a/sources/memoblocks.c b/sources/memoblocks.c index aa6df3d..2e3d9e8 100644 --- a/sources/memoblocks.c +++ b/sources/memoblocks.c @@ -41,15 +41,15 @@ void logo(byte sy,byte sx){ } //convert integer to representing sign char int2sgn(byte num){ - if(0< num && num <= 9) - return num+'0'; - else if(10<=num && num <=35) - return num-10+'a'; - else if(36<=num && num <=51) - return num-36+'A'; + if(0< num && num <= 9) + return num+'0'; + else if(10<=num && num <=35) + return num-10+'a'; + else if(36<=num && num <=51) + return num-36+'A'; else if(52<=num && num<=64) return num-52+'!'; - return 0; + return 0; } //display void draw(byte sy,byte sx,chtype board[size][size2],bool show[size][size2]){ @@ -131,79 +131,79 @@ void mouseinput(void){ ungetch('\n'); } void help(void){ - erase(); + erase(); logo(0,0); - attron(A_BOLD); - mvprintw(3,0," **** THE CONTROLS ****"); + attron(A_BOLD); + mvprintw(3,0," **** THE CONTROLS ****"); mvprintw(8,0,"YOU CAN ALSO USE THE MOUSE!"); - attroff(A_BOLD); + attroff(A_BOLD); mvprintw(4,0,"RETURN/ENTER : Reveal"); - mvprintw(5,0,"hjkl/ARROW KEYS : Move cursor"); - mvprintw(6,0,"q : Quit"); + mvprintw(5,0,"hjkl/ARROW KEYS : Move cursor"); + mvprintw(6,0,"q : Quit"); mvprintw(7,0,"F1 & F2 : Help on controls & gameplay"); - mvprintw(10,0,"Press a key to continue"); + mvprintw(10,0,"Press a key to continue"); refresh(); - getch(); + getch(); erase(); } void gameplay(void){ - erase(); + erase(); logo(0,0); - attron(A_BOLD); - mvprintw(3,0," **** THE GAMEPLAY ****"); - attroff(A_BOLD); + attron(A_BOLD); + mvprintw(3,0," **** THE GAMEPLAY ****"); + attroff(A_BOLD); mvprintw(4,0,"Click on a tile to see the gylph it contains,\n"); printw( "then try to find a matching gylph the same way.\n"); printw( "They form a pair only when you click a tile\n"); printw( "directly after the match. The game ends when \n"); printw( "you have found all the matching pairs.\n"); - refresh(); - getch(); - erase(); + refresh(); + getch(); + erase(); } int main(int argc, char** argv){ size=8; if(argc>=2){ - size=atoi(argv[1]); - if(size<3 || size>19){ - fprintf(stderr,"3<=size<=19\n"); - return EXIT_FAILURE; - } - if(!strcmp("help",argv[1])){ - printf("Usage: %s [size]\n",argv[0]); + size=atoi(argv[1]); + if(size<3 || size>19){ + fprintf(stderr,"3<=size<=19\n"); + return EXIT_FAILURE; + } + if(!strcmp("help",argv[1])){ + printf("Usage: %s [size]\n",argv[0]); return EXIT_SUCCESS; } - } + } signal(SIGINT,sigint_handler); srand(time(NULL)%UINT_MAX); initscr(); - mousemask(ALL_MOUSE_EVENTS,NULL); - noecho(); - cbreak(); - keypad(stdscr,1); - if(has_colors()){ - start_color(); - use_default_colors(); + mousemask(ALL_MOUSE_EVENTS,NULL); + noecho(); + cbreak(); + keypad(stdscr,1); + if(has_colors()){ + start_color(); + use_default_colors(); if( has_colors() ){ - start_color(); - use_default_colors(); - init_pair(1,COLOR_YELLOW,-1); - init_pair(2,COLOR_GREEN,-1); - init_pair(3,COLOR_BLUE,-1); - init_pair(4,COLOR_CYAN,-1); - init_pair(5,COLOR_MAGENTA,-1); - init_pair(6,COLOR_RED,-1); - for(byte b=0;b<6;b++){ - colors[b]=COLOR_PAIR(b+1); - } + start_color(); + use_default_colors(); + init_pair(1,COLOR_YELLOW,-1); + init_pair(2,COLOR_GREEN,-1); + init_pair(3,COLOR_BLUE,-1); + init_pair(4,COLOR_CYAN,-1); + init_pair(5,COLOR_MAGENTA,-1); + init_pair(6,COLOR_RED,-1); + for(byte b=0;b<6;b++){ + colors[b]=COLOR_PAIR(b+1); + } } - } + } else if(size>8)//big sizes depend on color display size=8; size2=size*2; - chtype board[size][size2]; + chtype board[size][size2]; bool show[size][size2]; - int input; + int input; time_t tstart,now; Start: tstart=time(NULL); diff --git a/sources/miketron.c b/sources/miketron.c new file mode 100644 index 0000000..fd29200 --- /dev/null +++ b/sources/miketron.c @@ -0,0 +1,538 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#define SAVE_TO_NUM 10 +#define MINLEN 10 +#define MAXLEN 24 +#define MINWID 40 +#define MAXWID 80 +enum {UP=1,RIGHT,DOWN,LEFT,FLIGHT,NOTRAIL,BOMB,SPAWN,STOP,SUPERFOOD,TRAIL}; +/* +|\/| +| |IKETRON + +Authored by Hossein Bakhtiarifar +No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law. + +compile with -lncurses +*/ +typedef signed char byte; +int len,wid,py,px; +int immunity,flight,notrail; +byte direction; +long score; +chtype colors[6]={0}; +FILE *scorefile,*lol; +char error[150]={0}; +void move_tron(void){ + switch(direction){ + case UP: + py--; + break; + case DOWN: + py++; + break; + case LEFT: + px--; + break; + case RIGHT: + px++; + break; + } + if(py==-1) + py=len-1; + else if(py==len) + py=0; + if(px==-1) + px=wid-1; + else if(py==len) + py=0; +} +void logo(void){ + mvaddstr(1,0,"|\\/|"); + mvaddstr(2,0,"| |IKETRON"); +} +byte scorewrite(void){// only saves the top 10, returns the place in the chart + bool deforno; + if( !getenv("MT_SCORES") && (scorefile= fopen(MT_SCORES,"r")) ){ + deforno=1; + } + else{ + deforno=0; + if( !(scorefile = fopen(getenv("MT_SCORES"),"r")) ){ + sprintf(error,"No accessible score files found. You can make an empty text file in %s or set MT_SCORES to such a file to solve this.",MT_SCORES); + return -1; + } + } + + char namebuff[SAVE_TO_NUM][60]; + long scorebuff[SAVE_TO_NUM]; + + memset(namebuff,0,SAVE_TO_NUM*60*sizeof(char) ); + memset(scorebuff,0,SAVE_TO_NUM*sizeof(long) ); + + long fuckingscore=0; + char fuckingname[60]={0}; + byte location=0; + + while( fscanf(scorefile,"%59s : %ld\n",fuckingname,&fuckingscore) == 2 && location=itreached || score>=scorebuff[location]) ){ + fprintf(scorefile,"%s : %ld\n",getenv("USER"),score); + ret=location; + wroteit=1; + } + if(location*>*>Top %d<*<*<\n",SAVE_TO_NUM); + while( rank>>"); + printw("%d) %s : %ld\n",rank+1,pname,pscore); + rank++; + } + addch('\n'); + refresh(); +} +void put_stuff(byte board[len][wid],byte num){ + byte y,x; + for(byte n=0;n=len) + ey-=len; + if(ex>=wid) + ex-=wid; + if(sy<0) + sy+=len; + if(sx<0) + sx+=wid; + int y=sy; + int x=sx; + while(y!=ey){ + while(x!=ex){ + x++; + if(x==wid) + x=0; + if(board[y][x]==BOMB) + explode(board,y,x); + board[y][x]=-10; + fprintf(lol,"y:%d x:%d\n",y,x); + fflush(lol); + } + x=sx; + y++; + if(y==len) + y=0; + fprintf(lol,"y:%d x:%d\n",y,x); + fflush(lol); + + } +} +void help(void){ + nocbreak(); + cbreak(); + erase(); + logo(); + attron(A_BOLD); + mvprintw(3,0," **** THE CONTROLS ****"); + attroff(A_BOLD); + mvprintw(4,0,"hjkl/ARROW KEYS : Change direction"); + mvprintw(5,0,"q : Quit"); + mvprintw(6,0,"F1 & F2: Help on controls & gameplay"); + mvprintw(8,0,"Press a key to continue"); + refresh(); + getch(); + erase(); + halfdelay(1); +} +void gameplay(void){ + nocbreak(); + cbreak(); + erase(); + logo(); + attron(A_BOLD); + mvprintw(3,0," **** THE GAMEPLAY ****"); + attroff(A_BOLD); + move(4,0); + printw("You are controlling a strange vechile which can \n"); + printw("survive explosions but cannot cross the trail it has\n"); + printw("left behind. Keep it running as much as you can."); + refresh(); + erase(); + getch(); + halfdelay(1); +} +void sigint_handler(int x){ + endwin(); + puts("Quit."); + exit(x); +} +int main(int argc, char** argv){ + bool autoset=0; + signal(SIGINT,sigint_handler); + if(argc>3 || (argc==2 && !strcmp("help",argv[1])) ){ + printf("Usage: %s [len wid]\n",argv[0]); + return EXIT_FAILURE; + } + if(argc==2){ + puts("Give both dimensions."); + return EXIT_FAILURE; + } + if(argc==3){ + bool lool = sscanf(argv[1],"%d",&len) && sscanf(argv[2],"%d",&wid); + if(!lool){ + puts("Invalid input."); + return EXIT_FAILURE; + } + if(len500 || wid>500){ + puts("At least one of your given dimensions is either too small or too big."); + return EXIT_FAILURE; + } + + } + else{ + autoset=1; + } + initscr(); + if(autoset){ + len=LINES-7; + if(lenMAXLEN) + len=MAXLEN; + + wid=COLS-5; + if(widMAXWID) + wid=MAXWID; + } + srand(time(NULL)%UINT_MAX); + byte board[len][wid]; + byte predirection; + int prex,prey; + bool halfspeed=0; + int constant=150*(80*24)/(len*wid); + initscr(); + noecho(); + cbreak(); + keypad(stdscr,1); + if(has_colors()){ + start_color(); + use_default_colors(); + + init_pair(1,COLOR_BLUE,-1); + init_pair(2,COLOR_GREEN,-1); + init_pair(3,COLOR_YELLOW,-1); + init_pair(4,COLOR_CYAN,-1); + init_pair(5,COLOR_MAGENTA,-1); + init_pair(6,COLOR_RED,-1); + for(byte b= 0;b<6;b++){ + colors[b]=COLOR_PAIR(b+1); + } + + } + lol=fopen("lol","w"); + Start: + curs_set(0); + halfdelay(1); + score=0; + direction=LEFT; + py=len/2; + px=wid/2; + memset(board,0,len*wid); + put_stuff(board,20); + int prepreinput,preinput,input; + while(1){ + erase(); + logo(); + mvprintw(1,12,"Score:%ld",score); + draw(board); + refresh(); + prepreinput=preinput; + preinput=input; + input = getch(); + if(immunity) + mvprintw(2,12,"Immunity:%ld",immunity); + else if(flight) + mvprintw(2,12,"Flight:%ld",flight); + else if(notrail) + mvprintw(2,12,"NoTrail:%ld",notrail); + if(board[py][px]==SPAWN) + put_stuff(board,5); + else if(board[py][px]==BOMB){ + explode(board,py,px); + for(byte b=0;b<10;b++){ + draw(board); + refresh(); + usleep(100000); + } + } + else if(board[py][px]==STOP){ + nocbreak(); + cbreak(); + ungetch(getch()); + halfdelay(1); + } + else if(board[py][px]==SUPERFOOD) + immunity+=len+wid; + else if(board[py][px]==FLIGHT) + flight+=5; + else if(board[py][px]==NOTRAIL) + notrail+=15; + else + goto ElseJump; + board[py][px]=0;//if one of conditions is true, it executes! keep nagging about goto being redundant! + ElseJump: + if(board[py][px]==TRAIL){ + if(immunity) + board[py][px]=0; + else if(!flight) + break; + } + if( input == KEY_F(1) || input=='?' ) + help(); + halfspeed=!halfspeed; + predirection=direction; + if( (input=='k' || input==KEY_UP) ){ + direction=UP; + halfspeed=1; + } + else if( (input=='j' || input==KEY_DOWN) ){ + direction=DOWN; + halfspeed=1; + } + else if( (input=='h' || input==KEY_LEFT) ) + direction=LEFT; + else if( (input=='l' || input==KEY_RIGHT) ) + direction=RIGHT; + if( input=='q') + sigint_handler(0); + + if(input!=ERR){ + if(preinput==input){//if it wasn't there, hitting two keys in less than 0.1 sec would not work + //the i part is there to prevent it from working too often =) you could just move diagonally that way and get a big score + //just hitting UP and LEFT repeatedly. the trick works in the original, but not very well because of it's limitations. + usleep(100000); + flushinp(); + } + if(prepreinput==input) + usleep(100000); + + } + + if( !((direction==UP||direction==DOWN)&&!halfspeed) && !immunity && !flight && !notrail) + board[py][px]=TRAIL; + + if(direction==UP && halfspeed){ + py--; + if(py==-1) + py=len-1; + halfspeed=1; + } + else if(direction==DOWN && halfspeed){ + py++; + if(py==len) + py=0; + } + else if(direction==LEFT){ + px--; + if(px==-1) + px=wid-1; + } + else if(direction==RIGHT){ + px++; + if(px==wid) + px=0; + } + score++; + if(!(score%100)) + put_stuff(board,5); + if(immunity) + immunity--; + else if(flight) + flight--; + else if(notrail) + notrail--; + } + nocbreak(); + cbreak(); + draw(board); + refresh(); + mvprintw(len+5,0,"Game over! Press a key to see the high scores:"); + getch(); + showscores(scorewrite()); + printw("Game over! Wanna play again?(y/n)"); + curs_set(1); + input=getch(); + if( input!= 'N' && input!= 'n' && input!='q') + goto Start; + endwin(); + return EXIT_SUCCESS; +} diff --git a/sources/mines.c b/sources/mines.c index b850e82..9e1dfe6 100644 --- a/sources/mines.c +++ b/sources/mines.c @@ -165,31 +165,31 @@ void mouseinput(int sy, int sx){ ungetch(' '); } void help(void){ - erase(); + erase(); mvprintw(1,0,"|\\/|"); mvprintw(2,0,"| |INES"); - attron(A_BOLD); - mvprintw(3,0," **** THE CONTROLS ****"); + attron(A_BOLD); + mvprintw(3,0," **** THE CONTROLS ****"); mvprintw(10,0,"YOU CAN ALSO USE THE MOUSE!"); - attroff(A_BOLD); + attroff(A_BOLD); mvprintw(4,0,"RETURN/ENTER : Examine for bombs"); - mvprintw(5,0,"SPACE : Flag/Unflag"); - mvprintw(6,0,"hjkl/ARROW KEYS : Move cursor"); - mvprintw(7,0,"q : Quit"); + mvprintw(5,0,"SPACE : Flag/Unflag"); + mvprintw(6,0,"hjkl/ARROW KEYS : Move cursor"); + mvprintw(7,0,"q : Quit"); mvprintw(8,0,"F1 & F2 : Help on controls & gameplay"); mvprintw(9,0,"PgDn,PgUp,<,> : Scroll"); - mvprintw(12,0,"Press a key to continue"); + mvprintw(12,0,"Press a key to continue"); refresh(); - getch(); + getch(); erase(); } void gameplay(void){ - erase(); - mvprintw(1,0,"|\\/|"); - mvprintw(2,0,"| |INES"); - attron(A_BOLD); - mvprintw(3,0," **** THE GAMEPLAY ****"); - attroff(A_BOLD); + erase(); + mvprintw(1,0,"|\\/|"); + mvprintw(2,0,"| |INES"); + attron(A_BOLD); + mvprintw(3,0," **** THE GAMEPLAY ****"); + attroff(A_BOLD); mvprintw(4,0,"Try to find the landmines in the field\n"); printw("with logical reasoning: When you click\n"); printw("on a tile ( a '.' here), numbers may show\n"); @@ -198,9 +198,9 @@ void gameplay(void){ printw("avoid the landmines based on them; and\n"); printw("clicking on a landmine would make you\n"); printw("lose the game."); - refresh(); - getch(); - erase(); + refresh(); + getch(); + erase(); } int main(int argc, char** argv){ signal(SIGINT,sigint_handler); @@ -240,34 +240,34 @@ int main(int argc, char** argv){ mscount = len*wid/6; srand(time(NULL)%UINT_MAX); initscr(); - mousemask(ALL_MOUSE_EVENTS,NULL); - noecho(); - cbreak(); - keypad(stdscr,1); - if(has_colors()){ - start_color(); - use_default_colors(); - init_pair(1,COLOR_BLUE,-1); - init_pair(2,COLOR_GREEN,-1); - init_pair(3,COLOR_YELLOW,-1); - init_pair(4,COLOR_RED,-1); - init_pair(5,COLOR_RED,COLOR_YELLOW); - init_pair(6,COLOR_RED,COLOR_MAGENTA); - for(byte b= 0;b<6;b++){ - colors[b]=COLOR_PAIR(b+1); - } + mousemask(ALL_MOUSE_EVENTS,NULL); + noecho(); + cbreak(); + keypad(stdscr,1); + if(has_colors()){ + start_color(); + use_default_colors(); + init_pair(1,COLOR_BLUE,-1); + init_pair(2,COLOR_GREEN,-1); + init_pair(3,COLOR_YELLOW,-1); + init_pair(4,COLOR_RED,-1); + init_pair(5,COLOR_RED,COLOR_YELLOW); + init_pair(6,COLOR_RED,COLOR_MAGENTA); + for(byte b= 0;b<6;b++){ + colors[b]=COLOR_PAIR(b+1); + } - } - byte board[len][wid]; - bool mines[len][wid]; - char result[70]; - int input; + } + byte board[len][wid]; + bool mines[len][wid]; + char result[70]; + int input; int sy,sx; Start: sy=sx=0; py=px=0; - untouched=len*wid; - flags=0; + untouched=len*wid; + flags=0; curs_set(0); memset(board,-1,len*wid); memset(mines,false,len*wid); @@ -290,15 +290,15 @@ int main(int argc, char** argv){ sy=0; } if( input==KEY_NPAGE && LINES< len+3){ - sy-=10; - if(sy< -(len+3) ) - sy=-(len+3); - } + sy-=10; + if(sy< -(len+3) ) + sy=-(len+3); + } if( input=='<' && COLS< wid*2+1){ - sx+=10; - if(sx>0) - sx=0; - } + sx+=10; + if(sx>0) + sx=0; + } if( input=='>' && COLS< wid*2+1){ sx-=10; if(sx< -(wid*2+1)) diff --git a/sources/muncher.c b/sources/muncher.c new file mode 100644 index 0000000..f52d972 --- /dev/null +++ b/sources/muncher.c @@ -0,0 +1,451 @@ +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#define SAVE_TO_NUM 10 +#define MINLEN 10 +#define MAXLEN 24 +#define MINWID 40 +#define MAXWID 80 +enum {UP=1,RIGHT,DOWN,LEFT,FOOD,SUPERFOOD,TRAP}; +/* +|\/| +| |UNCHER + +Authored by Hossein Bakhtiarifar +No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law. + +compile with -lncurses +*/ +typedef signed char byte; +int len,wid,py,px; +int immunity; +byte direction; +long score; +chtype colors[6]={0}; +FILE* scorefile; +char error[150]={0}; +void logo(void){ + mvaddstr(1,0,"|\\/|"); + mvaddstr(2,0,"| |UNCHER"); +} +byte scorewrite(void){// only saves the top 10, returns the place in the chart + bool deforno; + if( !getenv("MNCH_SCORES") && (scorefile= fopen(MNCH_SCORES,"r")) ){ + deforno=1; + } + else{ + deforno=0; + if( !(scorefile = fopen(getenv("MNCH_SCORES"),"r")) ){ + sprintf(error,"No accessible score files found. You can make an empty text file in %s or set MNCH_SCORES to such a file to solve this.",MNCH_SCORES); + return -1; + } + } + + char namebuff[SAVE_TO_NUM][60]; + long scorebuff[SAVE_TO_NUM]; + + memset(namebuff,0,SAVE_TO_NUM*60*sizeof(char) ); + memset(scorebuff,0,SAVE_TO_NUM*sizeof(long) ); + + long fuckingscore =0; + char fuckingname[60]={0}; + byte location=0; + + while( fscanf(scorefile,"%59s : %ld\n",fuckingname,&fuckingscore) == 2 && location=itreached || score>=scorebuff[location]) ){ + fprintf(scorefile,"%s : %ld\n",getenv("USER"),score); + ret=location; + wroteit=1; + } + if(location*>*>Top %d<*<*<\n",SAVE_TO_NUM); + while( rank>>"); + printw("%d) %s : %ld\n",rank+1,pname,pscore); + rank++; + } + addch('\n'); + refresh(); +} +void rectangle(void){ + for(int y=0;y<=len;y++){ + mvaddch(3+y,0,ACS_VLINE); + mvaddch(4+y,1+wid,ACS_VLINE); + } + for(int x=0;x<=wid;x++){ + mvaddch(3,x,ACS_HLINE); + mvaddch(4+len,x,ACS_HLINE); + } + mvaddch(3,0,ACS_ULCORNER); + mvaddch(4+len,0,ACS_LLCORNER); + mvaddch(3,1+wid,ACS_URCORNER); + mvaddch(4+len,1+wid,ACS_LRCORNER); +} +void place_food(byte board[len][wid]){ + int y,x; + do{ + y=rand()%len; + x=rand()%wid; + }while(y==py && x==px); + board[y][x]=FOOD; + + byte num; + if(score<300) + num=rand()%2; + else if(score<500) + num=1+rand()%2; + else if(score<1000) + num=2+rand()%4; + else if(score<2000) + num=5+rand()%6; + else + num=10+rand()%11; + + while(num){ + Again: + y=rand()%len; + x=rand()%wid; + if(abs(y-py)<4 && abs(x-px)<7) + goto Again; + if(board[y][x]==FOOD) + goto Again; + board[y][x]=TRAP; + + num--; + } + if(score>2000 && !(rand()%5)){ + do{ + y=rand()%len; + x=rand()%wid; + }while(y==py && x==px && board[y][x]!=FOOD); + board[y][x]=SUPERFOOD; + } +} +void draw(byte board[len][wid]){ + int y,x; + static byte effect=0; + chtype prnt; + rectangle(); + for(y=0;y3 || (argc==2 && !strcmp("help",argv[1])) ){ + printf("Usage: %s [len wid]\n",argv[0]); + return EXIT_FAILURE; + } + if(argc==2){ + puts("Give both dimensions."); + return EXIT_FAILURE; + } + if(argc==3){ + bool lool = sscanf(argv[1],"%d",&len) && sscanf(argv[2],"%d",&wid); + if(!lool){ + puts("Invalid input."); + return EXIT_FAILURE; + } + if(len500 || wid>500){ + puts("At least one of your given dimensions is either too small or too big."); + return EXIT_FAILURE; + } + + } + else{ + autoset=1; + } + initscr(); + if(autoset){ + len=LINES-7; + if(lenMAXLEN) + len=MAXLEN; + + wid=COLS-5; + if(widMAXWID) + wid=MAXWID; + } + srand(time(NULL)%UINT_MAX); + byte board[len][wid]; + bool halfspeed=0; + int constant=150*(80*24)/(len*wid); + initscr(); + noecho(); + cbreak(); + keypad(stdscr,1); + if(has_colors()){ + start_color(); + use_default_colors(); + init_pair(1,COLOR_BLUE,-1); + init_pair(2,COLOR_GREEN,-1); + init_pair(3,COLOR_YELLOW,-1); + init_pair(4,COLOR_CYAN,-1); + init_pair(5,COLOR_MAGENTA,-1); + init_pair(6,COLOR_RED,-1); + for(byte b= 0;b<6;b++){ + colors[b]=COLOR_PAIR(b+1); + } + + } + Start: + curs_set(0); + halfdelay(1); + score=direction=0; + py=len/2; + px=wid/2; + memset(board,0,len*wid); + place_food(board); + int input; + while(1){ + erase(); + logo(); + mvprintw(1,11,"Score:%ld",score); + if(immunity) + mvprintw(2,11,"Immunity:%d",immunity); + draw(board); + refresh(); + if( board[py][px]==FOOD ){ + score+= constant; + board[py][px]=0; + for(byte b=0;b<6;b++){ + mvaddch(4+py,px+1,'r'|colors[b]|A_STANDOUT); + refresh(); + usleep(100000/5); + } + place_food(board); + } + if( board[py][px]==SUPERFOOD ){ + immunity+=(len+wid)/2; + board[py][px]=0; + } + if(board[py][px]==TRAP){ + if(immunity) + board[py][px]=0; + else + break; + } + if(px<0 || px>=wid) + break; + halfspeed=!halfspeed; + input = getch(); + if( input == KEY_F(1) || input=='?' ) + help(); + if( input==KEY_F(2) ) + gameplay(); + if( (input=='k' || input==KEY_UP) && py>0 ){ + direction=UP; + halfspeed=1; + } + if( (input=='j' || input==KEY_DOWN) && py0 ) + direction=LEFT; + if( (input=='l' || input==KEY_RIGHT) && px=itreached || score>=scorebuff[location]) ){ - fprintf(scorefile,"%s : %ld\n",getenv("USER"),score); - ret=location; - wroteit=1; - } - if(location=itreached || score>=scorebuff[location]) ){ + fprintf(scorefile,"%s : %ld\n",getenv("USER"),score); + ret=location; + wroteit=1; + } + if(location0){ + if(playerrank == 0){ + char formername[60]={0}; + long formerscore=0; + rewind(scorefile); + fscanf(scorefile,"%*s : %*d"); + if ( fscanf(scorefile,"%s : %ld",formername,&formerscore)==2 && formerscore>0){ byte a = (len-9)/2; attron(A_BOLD); - mvprintw(SY,SX, "**** ***"); + mvprintw(SY,SX, "**** ***"); mvprintw(SY+len+1,SX,"***********************"); attroff(A_BOLD); attron(green); - mvprintw(SY,SX+4,"CONGRATULATIONS!"); - attroff(green); + mvprintw(SY,SX+4,"CONGRATULATIONS!"); + attroff(green); - mvprintw(SY+a+1,SX," _____ You bet the"); - mvprintw(SY+a+2,SX," .' | previous"); - mvprintw(SY+a+3,SX," .' | record"); - mvprintw(SY+a+4,SX," | .| | of"); - mvprintw(SY+a+5,SX," |.' | |%11ld",formerscore); - mvprintw(SY+a+6,SX," | | held by"); - mvprintw(SY+a+7,SX," ___| |___%7s!",formername); - mvprintw(SY+a+8,SX," | |"); - mvprintw(SY+a+9,SX," |____________|"); + mvprintw(SY+a+1,SX," _____ You bet the"); + mvprintw(SY+a+2,SX," .' | previous"); + mvprintw(SY+a+3,SX," .' | record"); + mvprintw(SY+a+4,SX," | .| | of"); + mvprintw(SY+a+5,SX," |.' | |%11ld",formerscore); + mvprintw(SY+a+6,SX," | | held by"); + mvprintw(SY+a+7,SX," ___| |___%7s!",formername); + mvprintw(SY+a+8,SX," | |"); + mvprintw(SY+a+9,SX," |____________|"); mvprintw(len+2,0,"Game over! Press a key to proceed:"); refresh(); getch(); erase(); logo(); - } + } - } + } attron(A_BOLD); mvprintw(3,0," HIGH"); mvprintw(4,0,"SCORES"); attroff(A_BOLD); - //scorefile is still open with w+ - char pname[60] = {0}; - long pscore=0; - byte rank=0; - rewind(scorefile); - while( rank>>"); - printw("%d",rank+1); + if(rank == playerrank) + printw(">>>"); + printw("%d",rank+1); attroff(green); printw(") %s : %ld",pname,pscore); - rank++; - } + rank++; + } refresh(); } //move in direction @@ -276,20 +276,20 @@ void draw(bitbox board[len][wid]){ } void mouseinput(void){ - MEVENT minput; + MEVENT minput; #ifdef PDCURSES nc_getmouse(&minput); #else getmouse(&minput); #endif - if( minput.y-4 : Scroll"); - mvprintw(10,0,"Press a key to continue"); + mvprintw(9,0,"Press a key to continue"); - refresh(); - while ( getch()==ERR ); - erase(); + refresh(); + while ( getch()==ERR ); + erase(); } void gameplay(void){ - erase(); - mvprintw(0,0," _ "); - mvprintw(1,0,"|_)"); - mvprintw(2,0,"| \\ABBITHOLE"); - attron(A_BOLD); - mvprintw(3,0," **** THE GAMEPLAY ****"); - attroff(A_BOLD); + erase(); + mvprintw(0,0," _ "); + mvprintw(1,0,"|_)"); + mvprintw(2,0,"| \\ABBITHOLE"); + attron(A_BOLD); + mvprintw(3,0," **** THE GAMEPLAY ****"); + attroff(A_BOLD); move(4,0); printw("Try to gather all the carrots in the maze\n"); printw("in the given time. The determining factors\n"); printw("are your choice of paths and the speed of\n "); printw("your fingers.\n"); - refresh(); - while ( getch()==ERR ); - erase(); + refresh(); + while ( getch()==ERR ); + erase(); } void sigint_handler(int x){ endwin(); @@ -244,13 +243,13 @@ int main(int argc, char** argv){ while(1){ board[py][px] |= VISITED; if( board[py][px] & CARROT ){ - carrots_found++; - board[py][px] &= ~CARROT; - } + carrots_found++; + board[py][px] &= ~CARROT; + } now=time(NULL); erase(); mvprintw(sy+0,sx+0," _ "); - mvprintw(sy+1,sx+0,"|_) Time left :%ld",giventime-(now-tstart)); + mvprintw(sy+1,sx+0,"|_) Time left :%ld",giventime-(now-tstart)); mvprintw(sy+2,sx+0,"| \\ABBITHOLE Carrots left :%d",carrot_count-carrots_found); draw(sy+3,sx+0,board); refresh(); @@ -260,25 +259,27 @@ int main(int argc, char** argv){ } input = getch(); if( input==KEY_PPAGE && LINES< len+3){//the board starts in 3 - sy+=10; - if(sy>0) - sy=0; - } - if( input==KEY_NPAGE && LINES< len+3){ - sy-=10; - if(sy< -(len+3) ) - sy=-(len+3); - } - if( input=='<' && COLS< wid*2+1){ - sx+=10; - if(sx>0) - sx=0; - } - if( input=='>' && COLS< wid*2+1){ - sx-=10; - if(sx< -(wid*2+1)) - sx=-(wid*2+1); - } + sy+=10; + if(sy>0) + sy=0; + } + if( input==KEY_NPAGE && LINES< len+3){ + sy-=10; + if(sy< -(len+3) ) + sy=-(len+3); + } + if( input=='<' && COLS< wid*2+1){ + sx+=10; + if(sx>0) + sx=0; + } + if( input=='>' && COLS< wid*2+1){ + sx-=10; + if(sx< -(wid*2+1)) + sx=-(wid*2+1); + } + if( input == KEY_F(2) ) + gameplay(); if( input == KEY_F(1) || input=='?' ) help(); if( (input=='k' || input==KEY_UP) && py>0 && (board[py][px]&UP) ) diff --git a/sources/redsquare.c b/sources/redsquare.c new file mode 100644 index 0000000..4f02856 --- /dev/null +++ b/sources/redsquare.c @@ -0,0 +1,650 @@ +#include +#include +#include +#include +#include +#include +#define LEN 35 +#define WID 50 +#define RLEN LEN //real +#define RWID WID +#define DEAD 0 +#define ALIVE 1 +#define RED 2 +/* + _ _ +|_) (_ +| \ED_)QUARE + +Authored by Hossein Bakhtiarifar +No rights are reserved and this software comes with no warranties of any kind to the extent permitted by law. + +compile with -lncurses +*/ +typedef signed char byte; +int level; +byte py,px; +byte cy,cx;//cross +bool coherent;//square's coherence +int anum,rnum;//reds and otherwise alive cell counts +chtype colors[6]={0}; +void cp(byte a[RLEN][RWID],byte b[RLEN][RWID]){ + byte y,x; + for(y=0;yalives) + board[y][x]=RED; + else if(alives>reds) + board[y][x]=ALIVE; + } + else{ + if(coherent && board[y][x]==RED) + coherent=0; + board[y][x]=DEAD; + } + } + else if(alives+reds==3){ + if(alives>reds) + board[y][x]=ALIVE; + else + board[y][x]=RED; + } + } + } +} +void add_line(byte board[LEN][WID],byte line,const char* str){ + for(byte x=0;str[x]!='\0';x++){ + if(str[x]=='#') + board[line][x]=ALIVE; + /*else + board[line][x]=0;*/ + } +} +void new_level(byte board[LEN][WID]){ + level++; + memset(board,0,RLEN*RWID); + switch(level){ + case 0: + cy=12; + cx=RWID/2; + add_line(board,5, " #### #"); + add_line(board,6, " #### #"); + add_line(board,7, " # # "); + add_line(board,8, " # ## # ## # ##"); + add_line(board,9, " # # # ## # ## #"); + add_line(board,10," # # # # # # # #"); + add_line(board,11," ### ## # # # #"); + + add_line(board,15," #### "); + add_line(board,16," # # "); + add_line(board,17," # ## # ## # # ## # #"); + add_line(board,18," # # # ## # # # # # # # #"); + add_line(board,19," # # # # # # # # # # # # #"); + add_line(board,20," #### ## # # # # ## # ###"); + add_line(board,21," #"); + add_line(board,22," # #"); + add_line(board,23," ##"); + break; + case 1: + cy=12; + cx=RWID/2; + add_line(board,5, " # # # #"); + add_line(board,6, " # # ## # "); + add_line(board,7, " # # # ## ### # # ## ## # # ##"); + add_line(board,8, " # # # # # # # # ## # # # ##"); + add_line(board,9, " # # # # # # # # # # # # #"); + add_line(board,10," # # ## # ## # # # # # # #"); + + add_line(board,15," #### # "); + add_line(board,16," # # # "); + add_line(board,17," # # # ## # # # ## # ## # #"); + add_line(board,18," ##### ## # # # # # # # # # #"); + add_line(board,19," # # # # # # # # # # # #"); + add_line(board,20," # # # # ## # # ## #"); + break; + case 2: + cy= 12; + cx= 10; + add_line(board,3, " ## # #"); + add_line(board,4, " ## # # "); + add_line(board,5, " # # "); + add_line(board,6, " # # # # "); + add_line(board,7, " ### ### "); + add_line(board,17," ## ## "); + add_line(board,18," # # # #"); + add_line(board,19," # # # # "); + add_line(board,20," # # "); + add_line(board,21," ### ### "); + add_line(board,22," ### ### "); + add_line(board,23," ## ## "); + add_line(board,24," ## ## "); + add_line(board,25," # ## ## # "); + add_line(board,26," ### ###"); + add_line(board,27," # #"); + + add_line(board,30," ##"); + add_line(board,31," ##"); + break; + case 3: + cy=RLEN/2; + cx=RWID/2; + add_line(board,0, " "); + add_line(board,1, " # # "); + add_line(board,2, " # # "); + add_line(board,3, " ### ### "); + add_line(board,4, " # # "); + add_line(board,5, " # # "); + add_line(board,6, " ### ### "); + add_line(board,7, " # # "); + add_line(board,8, " # # "); + add_line(board,9, " ### ### "); + add_line(board,10," # # "); + add_line(board,11," # # "); + add_line(board,12," ### ### "); + add_line(board,13," # # "); + add_line(board,14," # #"); + add_line(board,15," ### ###"); + add_line(board,17," "); + add_line(board,18," # "); + add_line(board,19," # "); + add_line(board,20," ### "); + add_line(board,21," # "); + add_line(board,22," # "); + add_line(board,23," ### "); + add_line(board,24," # "); + add_line(board,25," # "); + add_line(board,26," ### "); + add_line(board,27," # "); + add_line(board,28," # "); + add_line(board,29," ### "); + add_line(board,30," # "); + add_line(board,31," # "); + add_line(board,32," ### "); + break; + case 4: + cy=rand()%(RLEN/2); + cx=rand()%(RWID/2); + add_line(board,0, " "); + add_line(board,1, " "); + add_line(board,2, " "); + add_line(board,3, " "); + add_line(board,4, " "); + add_line(board,5, " "); + add_line(board,6, " "); + add_line(board,0, " # # # # "); + add_line(board,1, " # | | # # # "); + add_line(board,2, " # # | | # # # # # # "); + add_line(board,3 ," #### | | #### #### #### "); + add_line(board,11," "); + add_line(board,12," "); + add_line(board,13," "); + add_line(board,8 ," # # # # "); + add_line(board,9 ," # # # # "); + add_line(board,10," # # # # # # # # "); + add_line(board,11," #### #### #### #### "); + add_line(board,19," "); + add_line(board,20," "); + add_line(board,16," # # # # "); + add_line(board,17," #| | # # # "); + add_line(board,18," # #| | # # # # # # "); + add_line(board,19," ####| | #### #### #### "); + add_line(board,25," "); + add_line(board,26," "); + add_line(board,27," "); + add_line(board,28," "); + add_line(board,25," # # "); + add_line(board,26," # # "); + add_line(board,27," # # # # "); + add_line(board,28," #### #### "); + //add_line(board,5," #"); + //add_line(board,6," ##"); + //add_line(board,7," ##"); + break; + default: + srand(level); + rand_level(board); + } +} +void rm_square(byte board[LEN][WID],byte prey,byte prex){ + byte dy,dx,ry,rx; + for(dy=0;dy<2;dy++){ + for(dx=0;dx<2;dx++){ + ry=prey+dy; + if(ry==-1) + ry=LEN-1; + else if(ry==LEN) + ry=0; + rx=prex+dx; + if(rx==-1) + rx=WID-1; + else if(rx==WID) + rx=0; + board[ry][rx]=DEAD; + } + } +} +void mk_square(byte board[LEN][WID]){ + byte dy,dx,ry,rx; + for(dy=0;dy<2;dy++){ + for(dx=0;dx<2;dx++){ + ry=py+dy; + if(ry==-1) + ry=LEN-1; + else if(ry==LEN) + ry=0; + rx=px+dx; + if(rx==-1) + rx=WID-1; + else if(rx==WID) + rx=0; + board[ry][rx]=RED; + } + } +} +//detect if there is a square and enable the player to move +void reemerge(byte board[LEN][WID]){ + byte y,x,dy,dx,ry,rx; + for(y=0;y : Scroll"); + mvprintw(12,0,"Press a key to continue"); + refresh(); + getch(); + erase(); +} +void gameplay(void){ + erase(); + logo(); + attron(A_BOLD); + mvprintw(3,0," **** THE GAMEPLAY ****"); + attroff(A_BOLD); + mvprintw(4,0,"Try to find the landmines in the field\n"); + printw("with logical reasoning: When you click\n"); + printw("on a tile ( a '.' here), numbers may show\n"); + printw("up that indicate the number of landmines\n"); + printw("in adjacent tiles; you should find and \n"); + printw("avoid the landmines based on them; and\n"); + printw("clicking on a landmine would make you\n"); + printw("lose the game."); + refresh(); + getch(); + erase(); +} +int main(void){ + signal(SIGINT,sigint_handler); + srand(time(NULL)%UINT_MAX); + initscr(); + mousemask(ALL_MOUSE_EVENTS,NULL); + noecho(); + cbreak(); + keypad(stdscr,1); + if(has_colors()){ + start_color(); + use_default_colors(); + init_pair(1,COLOR_BLUE,-1); + init_pair(2,COLOR_GREEN,-1); + init_pair(3,COLOR_YELLOW,-1); + init_pair(4,COLOR_RED,-1); + init_pair(5,COLOR_RED,COLOR_YELLOW); + init_pair(6,COLOR_RED,COLOR_MAGENTA); + for(byte b= 0;b<6;b++){ + colors[b]=COLOR_PAIR(b+1); + } + + } + byte board[RLEN][RWID]; + memset(board,0,RLEN*RWID); + char result[70]; + int input; + int prey,prex; + int cinred; + Start: + cinred=0; + py=LEN*3/4; + px=WID/2; + curs_set(0); + level=-1; + new_level(board); + mk_square(board); + while(1){ + switch(rand()%5){//move the cross + case 0: + cx++; + if(cx==WID) + cx=0; + break; + case 1: + cy--; + if(cy==-1) + cy=LEN-1; + break; + case 2: + cx--; + if(cx==-1) + cx=WID-1; + break; + case 3: + cy++; + if(cy==LEN) + cy=0; + break; + case 4: + ;//stay there + } + if(board[cy][cx]==RED) + cinred++; + else + cinred=0; + /*if(rnum>anum||cinred==2){ + mvprintw(LEN+5,0,"Well done! Press a key to continue:"); + curs_set(1); + getch(); + curs_set(0); + new_level(board); + py=LEN*3/4; + px=WID/2; + mk_square(board); + }*/ + count(board); + if(rnum!=4) + coherent=0; + if(!coherent && rnum==4) + reemerge(board); + erase(); + logo(); + draw(board); + refresh(); + if(rnum>anum||cinred==2){ + mvprintw(LEN+5,0,"Well done! Press a key to continue:"); + curs_set(1); + getch(); + curs_set(0); + new_level(board); + py=LEN*3/4; + px=WID/2; + mk_square(board); + continue; + } + input = getch(); + live(board); + count(board);//apparently this should come at both sides of live+draw. resulting from trial and error. + if(rnum!=4)//the square has participated in life reactions if so + coherent=0; + if(!coherent && rnum==4)//there can be a square + reemerge(board); + + /*if(board[cy][cx]==RED) + cinred++; + else + cinred=0;*/ + + /*if(rnum>anum||cinred==2){ + mvprintw(LEN+5,0,"Well done! Press a key to continue:"); + curs_set(1); + getch(); + curs_set(0); + new_level(board); + py=LEN*3/4; + px=WID/2; + mk_square(board); + }*/ + if( input==KEY_F(1) || input=='?' ) + help(); + if( input==KEY_F(2) ) + gameplay(); + prey=py; + prex=px; + if(input=='k' || input==KEY_UP){ + py--; + if(py==-1) + py=LEN-1; + } + else if(input=='j' || input==KEY_DOWN){ + py++; + if(py==LEN) + py=0; + } + else if(input=='h' || input==KEY_LEFT){ + px--; + if(px==-1) + px=WID-1; + } + else if(input=='l' || input==KEY_RIGHT){ + px++; + if(px==WID) + px=0; + } + else + goto DidntMove; + if(coherent){ + rm_square(board,prey,prex); + mk_square(board); + } + DidntMove: + /*switch(rand()%5){//move the cross + case 0: + cx++; + if(cx==WID) + cx=0; + break; + case 1: + cy--; + if(cy==-1) + cy=LEN-1; + break; + case 2: + cx--; + if(cx==-1) + cx=WID-1; + break; + case 3: + cy++; + if(cy==LEN) + cy=0; + break; + case 4: + ;//stay there + }*/ + /*if(board[cy][cx]==RED) + cinred++; + else + cinred=0; + if(rnum>anum||cinred==2){ + mvprintw(LEN+5,0,"Well done! Press a key to continue:"); + curs_set(1); + getch(); + curs_set(0); + new_level(board); + py=LEN*3/4; + px=WID/2; + mk_square(board); + }*/ + if( input=='q') + sigint_handler(0); + } + mvprintw(LEN+5,0,"Wanna play again?(y/n)"); + curs_set(1); + input=getch(); + if(input != 'N' && input != 'n' && input != 'q') + goto Start; + endwin(); + return EXIT_SUCCESS; +} diff --git a/sources/reversi.c b/sources/reversi.c index f25cf76..75afd02 100644 --- a/sources/reversi.c +++ b/sources/reversi.c @@ -14,7 +14,7 @@ compile with -lncurses */ typedef signed char byte; byte py,px;//cursor -const char piece[2] = "OX"; +const char piece[2] = {'O','X'}; char game[8][8];//main board byte computer[2] = {0,0}; byte score[2];//set by header() @@ -61,7 +61,7 @@ void draw(byte sy,byte sx){//the game's board attr |= A_STANDOUT; if(game[y][x]) mvaddch(sy+1+y,sx+x*2+1,attr|game[y][x]); - else + else mvaddch(sy+1+y,sx+x*2+1,attr|'.'); } } @@ -214,42 +214,42 @@ void sigint_handler(int x){ exit(x); } void mouseinput(void){ - MEVENT minput; + MEVENT minput; #ifdef PDCURSES nc_getmouse(&minput); #else getmouse(&minput); #endif - if( minput.y-4 <8 && minput.x-1<16){ - py=minput.y-4; - px=(minput.x-1)/2; - } - else - return; - if(minput.bstate & BUTTON1_CLICKED) - ungetch('\n'); + if( minput.y-4 <8 && minput.x-1<16){ + py=minput.y-4; + px=(minput.x-1)/2; + } + else + return; + if(minput.bstate & BUTTON1_CLICKED) + ungetch('\n'); } void help(void){ - erase(); + erase(); header(); - attron(A_BOLD); - mvprintw(3,0," **** THE CONTROLS ****"); - mvprintw(8,0,"YOU CAN ALSO USE THE MOUSE!"); - attroff(A_BOLD); - mvprintw(4,0,"RETURN/ENTER : Put the piece"); - mvprintw(5,0,"hjkl/ARROW KEYS : Move cursor"); - mvprintw(6,0,"q : Quit"); + attron(A_BOLD); + mvprintw(3,0," **** THE CONTROLS ****"); + mvprintw(8,0,"YOU CAN ALSO USE THE MOUSE!"); + attroff(A_BOLD); + mvprintw(4,0,"RETURN/ENTER : Put the piece"); + mvprintw(5,0,"hjkl/ARROW KEYS : Move cursor"); + mvprintw(6,0,"q : Quit"); mvprintw(7,0,"F1 & F2 : Help on controls & gameplay"); - mvprintw(10,0,"Press a key to continue"); + mvprintw(10,0,"Press a key to continue"); curs_set(1); - getch(); + getch(); } void gameplay(void){ - erase(); - header(); - attron(A_BOLD); - mvprintw(3,0," **** THE GAMEPLAY ****"); - attroff(A_BOLD); + erase(); + header(); + attron(A_BOLD); + mvprintw(3,0," **** THE GAMEPLAY ****"); + attroff(A_BOLD); move(4,0); printw("Players take turns placing disks on the board:\n\n"); printw("1) Any pieces of the opponet's color that is bounded\n"); @@ -260,7 +260,7 @@ void gameplay(void){ printw(" opponet's pieces turns into your color.\n\n"); printw("3) The game ends when neither side can do a move and\n"); printw(" the player with more pieces wins.\n"); - getch(); + getch(); } int main(int argc , char** argv){ int depth=2; @@ -322,8 +322,8 @@ int main(int argc , char** argv){ Turn: erase(); flushinp(); - header(); draw(3,0); + header(); refresh(); if(cantmove >=2)//both sides cant move, the game ends goto End; @@ -350,8 +350,11 @@ int main(int argc , char** argv){ cantmove=0; while(1){ //human control erase(); - header(); draw(3,0); + header(); + if(!(computer[0]||computer[1])) + mvprintw(0,5,"%c's turn",piece[turn]); + refresh(); input=getch(); if( input==KEY_F(1) || input=='?' ) help(); diff --git a/sources/sos.c b/sources/sos.c index d396156..052992d 100644 --- a/sources/sos.c +++ b/sources/sos.c @@ -95,28 +95,28 @@ byte did_sos(char board[len][wid], int y , int x ){ } void color_sos(char board[len][wid],byte colored[len][wid], int y , int x ,bool side){ byte dy,dx; - if(board[y][x]== 'S'){ - for(dy=-1;dy<2;dy++){ - for(dx=-1;dx<2;dx++){ - if(rd(board,y+dy,x+dx)=='O' && rd(board,y+2*dy,x+2*dx) == 'S' ){ + if(board[y][x]== 'S'){ + for(dy=-1;dy<2;dy++){ + for(dx=-1;dx<2;dx++){ + if(rd(board,y+dy,x+dx)=='O' && rd(board,y+2*dy,x+2*dx) == 'S' ){ color(colored,y,x,side); - color(colored,y+dy,x+dx,side); - color(colored,y+2*dy,x+2*dx,side); + color(colored,y+dy,x+dx,side); + color(colored,y+2*dy,x+2*dx,side); } - } - } - } - else if(board[y][x]== 'O'){ - for(dy=-1;dy<2;dy++){ - for(dx=-1;dx<2;dx++){ - if(rd(board,y+dy,x+dx)=='S' && rd(board,y-dy,x-dx) =='S'){ + } + } + } + else if(board[y][x]== 'O'){ + for(dy=-1;dy<2;dy++){ + for(dx=-1;dx<2;dx++){ + if(rd(board,y+dy,x+dx)=='S' && rd(board,y-dy,x-dx) =='S'){ color(colored,y,x,side); - color(colored,y+dy,x+dx,side); - color(colored,y-dy,x-dx,side); + color(colored,y+dy,x+dx,side); + color(colored,y-dy,x-dx,side); } - } - } - } + } + } + } } void randmove(int* y,int* x,byte* c){ *y=rand()%len; @@ -178,59 +178,59 @@ void sigint_handler(int x){ exit(x); } void mouseinput(int sy,int sx){ - MEVENT minput; + MEVENT minput; #ifdef PDCURSES nc_getmouse(&minput); #else getmouse(&minput); #endif - if( minput.y-4-sy : Scroll"); - mvprintw(11,0,"Press a key to continue"); - refresh(); - getch(); - erase(); + mvprintw(11,0,"Press a key to continue"); + refresh(); + getch(); + erase(); } void gameplay(void){ - erase(); - mvprintw(0,0," _ _ _"); - mvprintw(1,0,"(_'| |(_' "); - mvprintw(2,0,"._):_:._) "); - attron(A_BOLD); - mvprintw(3,0," **** THE GAMEPLAY ****"); - attroff(A_BOLD); + erase(); + mvprintw(0,0," _ _ _"); + mvprintw(1,0,"(_'| |(_' "); + mvprintw(2,0,"._):_:._) "); + attron(A_BOLD); + mvprintw(3,0," **** THE GAMEPLAY ****"); + attroff(A_BOLD); move(4,0); printw("The game is similiar to Tic Tac Toe:\n"); printw("The players write S and O in the squares\n"); printw("and making the straight connected sequence\n"); printw("S-O-S makes you a score; obviously, the\n"); printw("player with a higher score wins."); - refresh(); - getch(); - erase(); + refresh(); + getch(); + erase(); } int main(int argc, char** argv){ int dpt=1; @@ -279,27 +279,27 @@ int main(int argc, char** argv){ keypad(stdscr,1); printw("Black plays first.\n Choose the type of the blue player(H/c)\n" ); refresh(); - input=getch(); - if(input=='c'){ - computer[0]=dpt; - printw("Computer.\n"); - } - else{ - computer[0]=0; - printw("Human.\n"); - } + input=getch(); + if(input=='c'){ + computer[0]=dpt; + printw("Computer.\n"); + } + else{ + computer[0]=0; + printw("Human.\n"); + } refresh(); - printw("Choose the type of the yellow player(h/C)\n"); + printw("Choose the type of the yellow player(h/C)\n"); refresh(); - input=getch(); - if(input=='h'){ - computer[1]=0; - printw("Human.\n"); - } - else{ - computer[1]=dpt; - printw("Computer.\n"); - } + input=getch(); + if(input=='h'){ + computer[1]=0; + printw("Human.\n"); + } + else{ + computer[1]=dpt; + printw("Computer.\n"); + } if(has_colors()){ start_color(); use_default_colors(); @@ -340,32 +340,32 @@ int main(int argc, char** argv){ //else while(1){ erase(); - mvprintw(sy+0,sx+0," _ _ _"); - mvprintw(sy+1,sx+0,"(_'| |(_' %d vs %d \n",score[0],score[1]); - mvprintw(sy+2,sx+0,"._):_:._) \n"); + mvprintw(sy+0,sx+0," _ _ _"); + mvprintw(sy+1,sx+0,"(_'| |(_' %d vs %d \n",score[0],score[1]); + mvprintw(sy+2,sx+0,"._):_:._) \n"); draw(sy+3,sx+0,board,colored); refresh(); input = getch(); if( input==KEY_PPAGE && LINES< len+3){//the board starts in 3 - sy+=10; - if(sy>0) - sy=0; - } - if( input==KEY_NPAGE && LINES< len+3){ - sy-=10; - if(sy< -(len+3) ) - sy=-(len+3); - } - if( input=='<' && COLS< wid*2+1){ - sx+=10; - if(sx>0) - sx=0; - } - if( input=='>' && COLS< wid*2+1){ - sx-=10; - if(sx< -(wid*2+1)) - sx=-(wid*2+1); - } + sy+=10; + if(sy>0) + sy=0; + } + if( input==KEY_NPAGE && LINES< len+3){ + sy-=10; + if(sy< -(len+3) ) + sy=-(len+3); + } + if( input=='<' && COLS< wid*2+1){ + sx+=10; + if(sx>0) + sx=0; + } + if( input=='>' && COLS< wid*2+1){ + sx-=10; + if(sx< -(wid*2+1)) + sx=-(wid*2+1); + } if( input==KEY_F(1) || input=='?') help(); if( input==KEY_F(2) ) diff --git a/sources/sudoku.c b/sources/sudoku.c index 750e786..f2d1794 100644 --- a/sources/sudoku.c +++ b/sources/sudoku.c @@ -55,7 +55,7 @@ byte sgn2int(char sgn){ return sgn-'a'+10; if('A'<=sgn && sgn <= 'Z') return sgn-'A'+36; - return 0; + return 0; } char int2sgn(byte num){// convert integer to representing sign @@ -142,7 +142,7 @@ void fill(char board[s][s]){ if ( fill_with(board,int2sgn(num) ) ){ memset(board,0,s*s); num=0; - mvaddstr(0,0,"My algorithm sucks, so you need to wait a bit ");//with animated dots to entertain the waiter + mvaddstr(0,0,"My algorithm sucks, so you need to wait a bit ");//with animated dots to entertain the waiter if(waitcycles==3) mvaddstr(2,0,"(You can set SUDOKU_FASTGEN if you just want to see if it works)"); move(0,45); @@ -231,22 +231,22 @@ void sigint_handler(int x){ exit(x); } void mouseinput(int sy, int sx){ - MEVENT m; + MEVENT m; #ifdef PDCURSES - nc_getmouse(&m); + nc_getmouse(&m); #else getmouse(&m); #endif - if( m.y < (3+1+size+s)-sy && m.x<(2*s+1)-sx ){//it's a shame to include math.h only for round() but it was the only moral way to make gcc shut up - py= round( (float)(size*(m.y-4-sy))/(size+1) );//these are derived from the formulas in draw() by simple algebra - px=(m.x-1-sx)/2; - } - else - return; - if(m.bstate & BUTTON1_CLICKED) - ungetch('\n'); - if(m.bstate & (BUTTON2_CLICKED|BUTTON3_CLICKED) ) - ungetch(' '); + if( m.y < (3+1+size+s)-sy && m.x<(2*s+1)-sx ){//it's a shame to include math.h only for round() but it was the only moral way to make gcc shut up + py= round( (float)(size*(m.y-4-sy))/(size+1) );//these are derived from the formulas in draw() by simple algebra + px=(m.x-1-sx)/2; + } + else + return; + if(m.bstate & BUTTON1_CLICKED) + ungetch('\n'); + if(m.bstate & (BUTTON2_CLICKED|BUTTON3_CLICKED) ) + ungetch(' '); } void help(void){ erase(); @@ -272,10 +272,10 @@ void help(void){ erase(); } void gameplay(void){ - erase(); - header(0,0); - attron(A_BOLD); - mvprintw(3,0," **** THE GAMEPLAY ****"); + erase(); + header(0,0); + attron(A_BOLD); + mvprintw(3,0," **** THE GAMEPLAY ****"); attroff(A_BOLD); move(4,0); printw("Fill the table with digits"); @@ -295,9 +295,9 @@ void gameplay(void){ printw(" and all\nthe alphabet letters from 'a' to '%c'.",int2sgn(s)); } printw("\n\nPress a key to continue."); - refresh(); - getch(); - erase(); + refresh(); + getch(); + erase(); } int main(int argc,char** argv){ signal(SIGINT,sigint_handler); @@ -327,28 +327,28 @@ int main(int argc,char** argv){ diff=2; bool fastgen= !(!getenv("SUDOKU_FASTGEN")); initscr(); - mousemask(ALL_MOUSE_EVENTS,NULL); - noecho(); - cbreak(); - keypad(stdscr,1); - srand(time(NULL)%UINT_MAX); + mousemask(ALL_MOUSE_EVENTS,NULL); + noecho(); + cbreak(); + keypad(stdscr,1); + srand(time(NULL)%UINT_MAX); if( has_colors() ){ - start_color(); - use_default_colors(); - init_pair(1,COLOR_YELLOW,-1); - init_pair(2,COLOR_GREEN,-1); - init_pair(3,COLOR_BLUE,-1); - init_pair(4,COLOR_CYAN,-1); - init_pair(5,COLOR_MAGENTA,-1); - init_pair(6,COLOR_RED,-1); - for(byte b=0;b<6;b++){ - colors[b]=COLOR_PAIR(b+1); - } - } + start_color(); + use_default_colors(); + init_pair(1,COLOR_YELLOW,-1); + init_pair(2,COLOR_GREEN,-1); + init_pair(3,COLOR_BLUE,-1); + init_pair(4,COLOR_CYAN,-1); + init_pair(5,COLOR_MAGENTA,-1); + init_pair(6,COLOR_RED,-1); + for(byte b=0;b<6;b++){ + colors[b]=COLOR_PAIR(b+1); + } + } s= size*size; char board[s][s]; - char empty[s][s]; - char game[s][s]; + char empty[s][s]; + char game[s][s]; int input=0; int sy,sx; Start: @@ -375,25 +375,25 @@ int main(int argc,char** argv){ break; input = getch(); if( input==KEY_PPAGE && LINES< s+size+3){//the board starts in 3 - sy+=10; - if(sy>0) - sy=0; - } - if( input==KEY_NPAGE && LINES< s+size+3){ - sy-=10; - if(sy< -(s+size+3) ) - sy=-(s+size+3); - } - if( input=='<' && COLS< s*2){ - sx+=10; - if(sx>0) - sx=0; - } - if( input=='>' && COLS< s*2){ - sx-=10; - if(sx< -(s*2)) - sx=-(s*2); - } + sy+=10; + if(sy>0) + sy=0; + } + if( input==KEY_NPAGE && LINES< s+size+3){ + sy-=10; + if(sy< -(s+size+3) ) + sy=-(s+size+3); + } + if( input=='<' && COLS< s*2){ + sx+=10; + if(sx>0) + sx=0; + } + if( input=='>' && COLS< s*2){ + sx-=10; + if(sx< -(s*2)) + sx=-(s*2); + } if(input == KEY_F(1)) help(); if(input == KEY_F(2))