1
0
Fork 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:
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;

Binary file not shown.