From 73d499688156f2c8269ed7b3591396cb1639d7fe Mon Sep 17 00:00:00 2001 From: me Date: Fri, 28 Jan 2022 09:08:32 +0330 Subject: [PATCH] vertical scroll added --- mines.c | 81 +++++++++++++++++++++++++++++++++++------------------ redsquare.c | 44 +++++++++++++++++++++-------- 2 files changed, 86 insertions(+), 39 deletions(-) diff --git a/mines.c b/mines.c index 8eeadd5..02c20d7 100644 --- a/mines.c +++ b/mines.c @@ -24,6 +24,7 @@ compile with -lncurses #define MINWID 8 #define MAXLEN 1000 #define MAXWID 1000 +#define EMPTY_LINES 7 #ifdef NO_VLA //The Plan9 compiler can not handle VLAs #define len 8 #define wid 8 @@ -34,20 +35,38 @@ int py,px,flags; int untouched; int mscount; chtype colors[6]={0}; +int beginy,view_len; +byte setup_scroll(){ + beginy=0; + if(0len){ + beginy-=beginy+view_len-len; + } +} void rectangle(int sy,int sx){ - for(int y=0;y<=len+1;++y){ + setup_scroll(); + for(int y=0;y<=view_len;++y){ mvaddch(sy+y,sx,ACS_VLINE); mvaddch(sy+y,sx+wid*2,ACS_VLINE); } for(int x=0;x<=wid*2;++x){ mvaddch(sy,sx+x,ACS_HLINE); - mvaddch(sy+len+1,sx+x,ACS_HLINE); + mvaddch(sy+view_len+1,sx+x,ACS_HLINE); } mvaddch(sy,sx,ACS_ULCORNER); - mvaddch(sy+len+1,sx,ACS_LLCORNER); + mvaddch(sy+view_len+1,sx,ACS_LLCORNER); mvaddch(sy,sx+wid*2,ACS_URCORNER); - mvaddch(sy+len+1,sx+wid*2,ACS_LRCORNER); + mvaddch(sy+view_len+1,sx+wid*2,ACS_LRCORNER); +} +byte get_cell(byte board[len][wid],int y,int x){ + return board[(y+len)%len][(x+wid)%wid]; } //display void draw(int sy,int sx,byte board[len][wid]){ @@ -55,49 +74,53 @@ void draw(int sy,int sx,byte board[len][wid]){ chtype attr ; char prnt; int y,x; - for(y=0;y9) + else if(get_cell(board,y,x)>9){ prnt='?'; - - mvaddch(sy+1+y,sx+x*2+1,attr|prnt); + } + mvaddch(sy+1+(y-beginy),sx+x*2+1,attr|prnt); } } } //show the mines -void drawmines(int sy,int sx,byte board[len][wid],bool mines[len][wid]){ +void drawmines(int sy,int sx,byte board[len][wid],byte mines[len][wid]){ int y,x; - for(y=0;y=0 && board[ty][tx] <9)//it has been click()ed before return 0; else{//untouched @@ -281,7 +304,7 @@ int main(int argc, char** argv){ } byte board[len][wid]; - bool mines[len][wid]; + byte mines[len][wid]; char result[70]; int input; int sy,sx; @@ -397,7 +420,9 @@ int main(int argc, char** argv){ } } drawmines(sy+3,sx+0,board,mines); - mvprintw(sy+len+5,sx+0,"%s Wanna play again?(y/n)",result); + move(sy+view_len+5,sx+0); + printw("%s Wanna play again?(y/n)",result); + curs_set(1); input=getch(); if(input != 'N' && input != 'n' && input != 'q') diff --git a/redsquare.c b/redsquare.c index 6b5233e..0bff958 100644 --- a/redsquare.c +++ b/redsquare.c @@ -24,7 +24,7 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #define DEAD 0 #define ALIVE 1 #define RED 2 - +#define EMPTY_LINES 7 int level; byte py,px; byte cy,cx;//cross @@ -43,19 +43,36 @@ void logo(void){ addstr("|_) (_\n"); addstr("| \\ED_)QUARE"); } + +int beginy,view_len; +byte setup_scroll(){ + beginy=0; + if(0LEN){ + beginy-=beginy+view_len-LEN; + } +} + void rectangle(int sy,int sx){ - for(int y=0;y<=LEN;++y){ + setup_scroll(); + for(int y=0;y<=view_len;++y){ mvaddch(sy+y,sx,ACS_VLINE); mvaddch(sy+y,sx+WID+1,ACS_VLINE); } for(int x=0;x<=WID;++x){ mvaddch(sy,sx+x,ACS_HLINE); - mvaddch(sy+LEN+1,sx+x,ACS_HLINE); + mvaddch(sy+view_len+1,sx+x,ACS_HLINE); } mvaddch(sy,sx,ACS_ULCORNER); - mvaddch(sy+LEN+1,sx,ACS_LLCORNER); + mvaddch(sy+view_len+1,sx,ACS_LLCORNER); mvaddch(sy,sx+WID+1,ACS_URCORNER); - mvaddch(sy+LEN+1,sx+WID+1,ACS_LRCORNER); + mvaddch(sy+view_len+1,sx+WID+1,ACS_LRCORNER); } void count(byte board[LEN][WID]){ byte y,x; @@ -69,24 +86,29 @@ void count(byte board[LEN][WID]){ } } } +byte get_cell(byte board[LEN][WID],int y,int x){ + return board[(y+LEN)%LEN][(x+WID)%WID]; +} + //display void draw(byte board[RLEN][RWID]){ rectangle(3,0); chtype prnt; byte y,x; - for(y=0;y