1
0

After eacht turn, only the inside of the board will be redrawn.

This commit is contained in:
acn 2020-04-22 12:11:02 +02:00
parent 2266b9497c
commit 1217d585a8
2 changed files with 124 additions and 81 deletions

View File

@ -37,7 +37,7 @@
Usage: Usage:
ftm [tty_name] ftm [tty_name]
If no tty_name is given, VT100COL is If no tty_name is given, VT100COL is used
Revisions: Revisions:
@ -88,6 +88,26 @@
#define SPR_ERR 'X' /* Flag error */ #define SPR_ERR 'X' /* Flag error */
#define SPR_BLANK ' ' /* Blank */ #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 /* Global variables
*/ */
int brd_rows, /* Board size in rows */ int brd_rows, /* Board size in rows */
@ -240,7 +260,7 @@ Play()
PrStr("\t3 > Level 3 : 08 x 16 squares, 16 mines\n"); PrStr("\t3 > Level 3 : 08 x 16 squares, 16 mines\n");
PrStr("\tQ > Quit game\n\n"); PrStr("\tQ > Quit game\n\n");
PrStr("\t? "); PrStr("\tYour Choice? ");
ReadLine(buf, 1); ReadLine(buf, 1);
@ -296,20 +316,34 @@ RunLevel()
{ {
int row, col; char buf[4]; int row, col; char buf[4];
DrawBoard();
for(;;) for(;;)
{ {
ShowBoard(); ShowPlayfield();
if(gameover) { 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); ReadLine(buf, 0);
break; break;
} }
PrStr("\trc > Select (ie 0B)\n"); KsPosCursor(16,0);
PrStr("\trcF > Set/remove flag (ie: 3DF)\n"); 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("\tQ > Quit level\n\n");
PrStr("\t? "); PrStr("\tYour Move? ");
KsPosCursor(20, 19);
ReadLine(buf, 3); ReadLine(buf, 3);
@ -327,6 +361,21 @@ RunLevel()
ChoiceFlag(row, col); 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]) else if(buf[0] == 'Q' && !buf[1])
gameover = 1; gameover = 1;
} }
@ -527,13 +576,11 @@ int row, col;
} }
} }
/* Display board /* Draw the board (all around the playfield)
*/ */
ShowBoard() DrawBoard()
{ {
int r, c; int r, c;
int col;
col = KsCan(KS_CAN_COLOR);
KsClear(); KsClear();
PrStr("\n\n"); PrStr("\n\n");
@ -544,29 +591,51 @@ ShowBoard()
} }
PrCh('\n'); PrCh('\n');
if(col) KsFgCol(BBLK); KsFgCol(BBLK);
PrStr("\t +"); PrStr("\t "); PrCh(B_TOP_LEFT);
PrChTimes('-', brd_cols + brd_cols + 1); PrChTimes(B_TOP_BOTTOM, brd_cols + brd_cols + 1);
PrCh('+'); PrCh('\n'); PrCh(B_TOP_RIGHT); PrCh('\n');
if(col) KsResetAttr(); KsResetAttr();
for(r = 0; r < brd_rows; ++r) for(r = 0; r < brd_rows; ++r)
{ {
PrCh('\t'); PrCh('0' + r); PrCh('\t'); PrCh('0' + r);
if(col) { KsFgCol(BBLK); PrCh(B_LEFT_RIGHT); KsResetAttr();
KsFgCol(BBLK); PrCh('|'); KsResetAttr(); PrChTimes(' ', brd_cols*2);
PrCh(' '); KsFgCol(BBLK); PrCh(B_LEFT_RIGHT); KsResetAttr(); PrCh('0' + r);
PrCh('\n');
} }
else
PrCh('|'); 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) for(c = 0; c < brd_cols; ++c)
{ {
PrCh(' '); PrCh(' ');
if(TstVis(r, c)) if(TstVis(r, c))
{ {
if(GetCount(r, c)) { if(GetCount(r, c)) {
if(col) { if(KsCan(KS_CAN_COLOR)) {
switch(GetCount(r, c)) switch(GetCount(r, c))
{ {
case 1: KsFgCol(BBLU); break; case 1: KsFgCol(BBLU); break;
@ -590,31 +659,22 @@ ShowBoard()
if(TstMine(r, c)) if(TstMine(r, c))
{ {
if(TstFlag(r, c)) { if(TstFlag(r, c)) {
if(col) {
KsFgCol(RED); KsFgCol(RED);
PrCh(SPR_FLAG); PrCh(SPR_FLAG);
KsResetAttr(); KsResetAttr();
} else
PrCh(SPR_FLAG);
} }
else { else {
if(col) {
KsFgCol(RED); KsFgCol(RED);
PrCh(SPR_MINE); PrCh(SPR_MINE);
KsResetAttr(); KsResetAttr();
} else
PrCh(SPR_MINE);
} }
} }
else if(TstFlag(r, c)) else if(TstFlag(r, c))
PrCh(SPR_ERR); PrCh(SPR_ERR);
else { else {
if(col) {
KsFgCol(BBLK); KsFgCol(BBLK);
PrCh(SPR_UNK); PrCh(SPR_UNK);
KsResetAttr(); KsResetAttr();
} else
PrCh(SPR_UNK);
} }
} }
else else
@ -628,78 +688,62 @@ ShowBoard()
PrCh(SPR_UNK); PrCh(SPR_UNK);
#else #else
if(TstFlag(r, c)) { if(TstFlag(r, c)) {
if(col) KsFgCol(RED); KsFgCol(RED);
PrCh(SPR_FLAG); PrCh(SPR_FLAG);
if(col) KsResetAttr(); KsResetAttr();
} }
else { else {
if(col) KsFgCol(BBLK); KsFgCol(BBLK);
PrCh(SPR_UNK); PrCh(SPR_UNK);
if(col) KsResetAttr(); KsResetAttr();
} }
#endif #endif
} }
} }
if(col) {
PrCh(' '); KsFgCol(BBLK); PrCh('|'); KsResetAttr(); PrCh('0' + r);
}
else {
PrCh(' '); PrCh('|'); PrCh('0' + r);
}
switch(r) switch(r)
{ {
case 0 : case 0 :
PrStr(" FIND THAT MINE!"); KsPosCursor(5, (brd_cols*2)+16);
PrStr("Find That Mine!");
break; break;
case 2 : case 2 :
KsPosCursor(7, (brd_cols*2)+16);
if(gameover) { if(gameover) {
PrStr(" GAME OVER"); PrStr(" GAME OVER ");
} }
else { else {
PrStr(" Level: "); PrNumber(level); PrStr("Level: "); PrNumber(level);
} }
break; break;
case 4 : case 4 :
KsPosCursor(9, (brd_cols*2)+16);
if(gameover) { if(gameover) {
if(dead) { if(dead) {
PrStr(" YOU'RE DEAD"); PrStr(" YOU'RE DEAD ");
} }
else if(flgcnt + viscnt == squares) { else if(flgcnt + viscnt == squares) {
PrStr(" YOU WIN"); PrStr(" YOU WIN ");
} }
else { else {
PrStr(" SEE YOU LATER"); PrStr(" SEE YOU LATER");
} }
} }
else { else {
PrStr(" Mines: "); PrNumber(mines); PrStr("Mines: "); PrNumber(mines);
} }
break; break;
case 6 : case 6 :
KsPosCursor(11, (brd_cols*2)+16);
if(!gameover) { if(!gameover) {
PrStr(" Flags: "); PrNumber(flgcnt); PrStr("Flags: "); PrNumber(flgcnt);
}
else {
PrChTimes(' ', 9);
} }
break; 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. Set the mines randomly.
*/ */
extern char RandStr[]; extern char RandStr[];
ClrBoard() ClrBoard()
{ {
int r, c; char *p; int r, c; char *p;

Binary file not shown.