From 1217d585a845eeca673a941ed8a2a9c9638c1fd9 Mon Sep 17 00:00:00 2001 From: acn Date: Wed, 22 Apr 2020 12:11:02 +0200 Subject: [PATCH] After eacht turn, only the inside of the board will be redrawn. --- FindThatMine/ftm.c | 205 ++++++++++++++++++++++++++----------------- FindThatMine/ftm.com | Bin 10112 -> 10496 bytes 2 files changed, 124 insertions(+), 81 deletions(-) diff --git a/FindThatMine/ftm.c b/FindThatMine/ftm.c index 856a0b8..7d8f356 100644 --- a/FindThatMine/ftm.c +++ b/FindThatMine/ftm.c @@ -37,7 +37,7 @@ Usage: ftm [tty_name] - If no tty_name is given, VT100COL is + If no tty_name is given, VT100COL is used Revisions: @@ -88,6 +88,26 @@ #define SPR_ERR 'X' /* Flag error */ #define SPR_BLANK ' ' /* Blank */ +/* DEFs for border elements (corners, top+bottom line, right+left line) + * either the normal ones (7-bit compatible) are used or codepage 437 + */ +#define CP437 +#ifdef CP437 + #define B_TOP_LEFT 201 + #define B_TOP_RIGHT 187 + #define B_BOTTOM_LEFT 200 + #define B_BOTTOM_RIGHT 188 + #define B_TOP_BOTTOM 205 + #define B_LEFT_RIGHT 186 +#else + #define B_TOP_LEFT '+' + #define B_TOP_RIGHT '+' + #define B_BOTTOM_LEFT '+' + #define B_BOTTOM_RIGHT '+' + #define B_TOP_BOTTOM '-' + #define B_LEFT_RIGHT '|' +#endif + /* Global variables */ int brd_rows, /* Board size in rows */ @@ -240,7 +260,7 @@ Play() PrStr("\t3 > Level 3 : 08 x 16 squares, 16 mines\n"); PrStr("\tQ > Quit game\n\n"); - PrStr("\t? "); + PrStr("\tYour Choice? "); ReadLine(buf, 1); @@ -296,20 +316,34 @@ RunLevel() { int row, col; char buf[4]; + DrawBoard(); + for(;;) { - ShowBoard(); + ShowPlayfield(); if(gameover) { - PrStr("\tRETURN > Quit level\n\n\t? "); + KsPosCursor(16,0); + PrStr("\tRETURN > Quit level"); + PrChTimes(' ', 15); + PrStr("\n\t"); + PrChTimes(' ', 45); + PrStr("\n\t"); + PrChTimes(' ', 25); + PrStr("\n\n\t"); + PrChTimes(' ', 15); + KsPosCursor(18,0); + PrStr("\t? "); ReadLine(buf, 0); break; } - PrStr("\trc > Select (ie 0B)\n"); - PrStr("\trcF > Set/remove flag (ie: 3DF)\n"); - PrStr("\tQ > Quit level\n\n"); - PrStr("\t? "); + KsPosCursor(16,0); + PrStr("\trc / cr > Select (ie 0B or B0)\n"); + PrStr("\trcF / crF > Set/remove flag (ie: 3DF or D3F)\n"); + PrStr("\tQ > Quit level\n\n"); + PrStr("\tYour Move? "); + KsPosCursor(20, 19); ReadLine(buf, 3); @@ -327,6 +361,21 @@ RunLevel() ChoiceFlag(row, col); } } + if(buf[1] >= '0' && buf[1] < '0' + brd_cols) + { + row = buf[1] - '0'; + + if(buf[0] >= 'A' && buf[0] < 'A' + brd_cols) + { + col = buf[0] - 'A'; + + if(!buf[2]) + Choice(row, col); + else if(buf[2] == 'F' && !buf[3]) + ChoiceFlag(row, col); + } + } + else if(buf[0] == 'Q' && !buf[1]) gameover = 1; } @@ -527,14 +576,12 @@ int row, col; } } -/* Display board -*/ -ShowBoard() +/* Draw the board (all around the playfield) + */ +DrawBoard() { int r, c; - int col; - col = KsCan(KS_CAN_COLOR); - + KsClear(); PrStr("\n\n"); @@ -544,29 +591,51 @@ ShowBoard() } PrCh('\n'); - if(col) KsFgCol(BBLK); - PrStr("\t +"); - PrChTimes('-', brd_cols + brd_cols + 1); - PrCh('+'); PrCh('\n'); - if(col) KsResetAttr(); - + KsFgCol(BBLK); + PrStr("\t "); PrCh(B_TOP_LEFT); + PrChTimes(B_TOP_BOTTOM, brd_cols + brd_cols + 1); + PrCh(B_TOP_RIGHT); PrCh('\n'); + KsResetAttr(); + for(r = 0; r < brd_rows; ++r) { PrCh('\t'); PrCh('0' + r); - if(col) { - KsFgCol(BBLK); PrCh('|'); KsResetAttr(); - } - else - PrCh('|'); + KsFgCol(BBLK); PrCh(B_LEFT_RIGHT); KsResetAttr(); + PrChTimes(' ', brd_cols*2); + PrCh(' '); KsFgCol(BBLK); PrCh(B_LEFT_RIGHT); KsResetAttr(); PrCh('0' + r); + PrCh('\n'); + } + + KsFgCol(BBLK); + PrStr("\t "); PrCh(B_BOTTOM_LEFT); + PrChTimes(B_TOP_BOTTOM, brd_cols + brd_cols + 1); + PrCh(B_BOTTOM_RIGHT); PrCh('\n'); + KsResetAttr(); + + PrStr("\t "); + for(c = 0; c < brd_cols; ++c) { + PrCh(' '); PrCh('A' + c); + } + +} + +/* Draw the playfield +*/ +ShowPlayfield() +{ + int r, c; + + for(r = 0; r < brd_rows; ++r) + { + KsPosCursor(4 + r, 10); for(c = 0; c < brd_cols; ++c) { PrCh(' '); - if(TstVis(r, c)) { if(GetCount(r, c)) { - if(col) { + if(KsCan(KS_CAN_COLOR)) { switch(GetCount(r, c)) { case 1: KsFgCol(BBLU); break; @@ -590,31 +659,22 @@ ShowBoard() if(TstMine(r, c)) { if(TstFlag(r, c)) { - if(col) { - KsFgCol(RED); - PrCh(SPR_FLAG); - KsResetAttr(); - } else - PrCh(SPR_FLAG); + KsFgCol(RED); + PrCh(SPR_FLAG); + KsResetAttr(); } else { - if(col) { - KsFgCol(RED); - PrCh(SPR_MINE); - KsResetAttr(); - } else - PrCh(SPR_MINE); + KsFgCol(RED); + PrCh(SPR_MINE); + KsResetAttr(); } } else if(TstFlag(r, c)) PrCh(SPR_ERR); else { - if(col) { - KsFgCol(BBLK); - PrCh(SPR_UNK); - KsResetAttr(); - } else - PrCh(SPR_UNK); + KsFgCol(BBLK); + PrCh(SPR_UNK); + KsResetAttr(); } } else @@ -628,78 +688,62 @@ ShowBoard() PrCh(SPR_UNK); #else if(TstFlag(r, c)) { - if(col) KsFgCol(RED); + KsFgCol(RED); PrCh(SPR_FLAG); - if(col) KsResetAttr(); + KsResetAttr(); } else { - if(col) KsFgCol(BBLK); + KsFgCol(BBLK); PrCh(SPR_UNK); - if(col) KsResetAttr(); + KsResetAttr(); } #endif } } - if(col) { - PrCh(' '); KsFgCol(BBLK); PrCh('|'); KsResetAttr(); PrCh('0' + r); - } - else { - PrCh(' '); PrCh('|'); PrCh('0' + r); - } - switch(r) { case 0 : - PrStr(" FIND THAT MINE!"); + KsPosCursor(5, (brd_cols*2)+16); + PrStr("Find That Mine!"); break; case 2 : + KsPosCursor(7, (brd_cols*2)+16); if(gameover) { - PrStr(" GAME OVER"); + PrStr(" GAME OVER "); } else { - PrStr(" Level: "); PrNumber(level); + PrStr("Level: "); PrNumber(level); } break; case 4 : + KsPosCursor(9, (brd_cols*2)+16); if(gameover) { if(dead) { - PrStr(" YOU'RE DEAD"); + PrStr(" YOU'RE DEAD "); } else if(flgcnt + viscnt == squares) { - PrStr(" YOU WIN"); + PrStr(" YOU WIN "); } else { - PrStr(" SEE YOU LATER"); + PrStr(" SEE YOU LATER"); } } else { - PrStr(" Mines: "); PrNumber(mines); + PrStr("Mines: "); PrNumber(mines); } break; case 6 : + KsPosCursor(11, (brd_cols*2)+16); if(!gameover) { - PrStr(" Flags: "); PrNumber(flgcnt); + PrStr("Flags: "); PrNumber(flgcnt); + } + else { + PrChTimes(' ', 9); } break; } - - PrCh('\n'); } - - if(col) KsFgCol(BBLK); - PrStr("\t +"); - PrChTimes('-', brd_cols + brd_cols + 1); - PrCh('+'); PrCh('\n'); - if(col) KsResetAttr(); - - PrStr("\t "); - for(c = 0; c < brd_cols; ++c) { - PrCh(' '); PrCh('A' + c); - } - PrCh('\n'); - - PrCh('\n'); } @@ -708,7 +752,6 @@ ShowBoard() Set the mines randomly. */ extern char RandStr[]; - ClrBoard() { int r, c; char *p; diff --git a/FindThatMine/ftm.com b/FindThatMine/ftm.com index 0e968ef9dd1882bc1e96932a14eb535230e17731..217439e377cc8bc26e596e0ff8f2309548139950 100644 GIT binary patch delta 4656 zcmai1du$ZP8DH=Dj`R6>KI7XnzPp`Wb9=i6<3iE|hypg41PPPGkWh%4hKJi&aX@hi zLKJ!~f+(*>fk`Nk)TK$&DpJx%2ql85?P}{PhqP_2Hc_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