📄 tsixmineplayer.cpp
字号:
#ifndef __BenBear_TSixMinePlayer_cpp
#define __BenBear_TSixMinePlayer_cpp
#include <iostream>
#include <cstdlib>
#include <cctype>
using namespace std;
#include <conio.h>
#include "screen.h"
#include "TSixMine.cpp"
class TSixMinePlayer: public TSixMine
{
static const int dMaxFloor = 10;
TReturn re;
bool playing;
protected:
int bye();
int command();
int hello();
int help();
int play();
int reset();
int set_mine();
int show();
public:
int run();
};
int TSixMinePlayer::bye()
{
scr_clrscr();
scr_goto( 1, 9 );
cout << "\
感谢使用! BenBear\n\
\n\
BBBB Y Y EEEEE\n\
B B Y Y E\n\
BBBB Y Y EEEE\n\
B B Y E\n\
BBBB Y EEEEE";
command();
}
int TSixMinePlayer::command()
{
return toupper( getch() );
}
int TSixMinePlayer::hello()
{
scr_clrscr();
scr_goto( 1, 8 );
cout << "\
BenBear's 六边扫雷\n\
1.3 控制台\n\
玩得开心\n\
H H EEEEE L L OOO\n\
H H E L L O O\n\
HHHHH EEEE L L O O\n\
H H E L L O O\n\
H H EEEEE LLLLL LLLLL OOO\n\
\n\
2003年 3月";
command();
}
int TSixMinePlayer::help()
{
scr_clrscr();
cout << "每一个孔周围都有六个或三个、四个孔;"
"挖开的孔中的数字为周围有几个雷。" << endl;
cout << "J用来挖开一个孔,L用来标记一个孔或去掉一个标记。" << endl;
cout << "K用来把周围的剩下的孔都挖开或都标记。" << endl;
cout << "D、E、W、A、Z、X六个键用来移动。"
"(看到了吗?这六个键成六边形)" << endl;
cout << endl;
cout << "主菜单:" << endl;
cout << "-P:玩游戏" << endl;
cout << "+S:设置雷区的层数和雷的数量" << endl;
cout << " -F:设置雷区的层数" << endl;
cout << " -M:设置雷的数量" << endl;
cout << " -X:退出设置雷区" << endl;
cout << "-H:帮助信息" << endl;
cout << "-X:退出游戏" << endl;
command();
}
int TSixMinePlayer::play()
{
int cmd;
TReturn re;
scr_clrscr();
reset();
show();
do
{
re = hrOK;
show();
scr_goto( 1, 24 );
cout << " F R E S X C : 移动 "
"J : 挖雷 "
"K : 全挖/全标 "
"L : 标记 "
"0 : 退出";
cmd = command();
int dir=0;
switch( cmd )
{
case '0' : return hrOK;
case 'J' : if( !playing )
{
playing = true;
lay( pos );
}
re = dig();
break;
case 'K' : re = wide_dig(); break;
case 'L' : re = mark(); break;
case 'C' : dir++;
case 'X' : dir++;
case 'S' : dir++;
case 'E' : dir++;
case 'R' : dir++;
case 'F' : re = move( dir ); break;
}
if( re == hrWin || re == hrDie )
{
playing = false;
if( re == hrWin )
{
show();
scr_goto( 1, 24 );
cout << "OK! press ENTER to continue... "
" ";
command();
}
else
{
show();
scr_goto( 1, 24 );
cout << "Sorry! press ENTER to continue... "
" ";
command();
}
return re;
}
}
while( re != hrWin && re != hrDie );
scr_clrscr();
return hrOK;
}
int TSixMinePlayer::reset()
{
playing = false;
left_mine = mine;
open_hole = 0;
pos = 0;
lay();
}
int TSixMinePlayer::run()
{
bool gameover = false;
int cmd;
scr_window( 80, 25 );
hello();
do
{
scr_clrscr();
scr_goto( 10, 10 ); cout << "P : 玩游戏" << endl;
scr_goto( 10, 11 ); cout << "S : 设置雷区" << endl;
scr_goto( 10, 12 ); cout << "H : 帮助信息" << endl;
scr_goto( 10, 13 ); cout << "X : 退出游戏" << endl;
scr_goto( 10, 14 ); cout << " 请选择:";
cmd = command(); // get command
switch( cmd )
{
case 'P': play(); break; // play game
case 'S': set_mine(); break; // set game
case 'X': gameover = true; break; // exit game
case 'H': help(); break; // help
}
}
while( !gameover );
bye();
scr_clrscr();
return 1;
}
int TSixMinePlayer::set_mine()
{
int cmd;
int num;
do
{
scr_clrscr();
scr_goto( 1, 10 );
cout << "F : 设置层数;(1 到 " << dMaxFloor
<< ") @ " << floor << endl
<< "M : 设置雷数;(1 到 " << hole
<< ") @ " << mine << endl
<< "X : 返回主菜单" << endl
<< " 请选择:";
cmd = command();
cout << endl;
switch( cmd )
{
case 'F': cout << "请输入层数:"; cin >> num;
if(( num < 1 ) || ( num > dMaxFloor ))
continue;
set( num );
break;
case 'M': cout << "请输入雷数:";
cin >> num;
if(( num < 1 ) || ( num > hole ))
continue;
mine = num;
break;
case 'X': return hrOK;
}
}
while( 1 );
return hrOK;
}
int TSixMinePlayer::show()
{
char hvStr[7][4] = { "0", "1", "2", "3", "4", "5", "6" };
char hsStr[4][4] = { "■", "", "※", "X" };
int i, x, y;
CHoneyHole h;
scr_clrscr();
scr_front( YELLOW );
for( i = 0; i < hole; i++ )
{
h.set( i );
h.get( x, y );
if( holes[ h ].s == hsOpen )
scr_front( WHITE );
else if( holes[ h ].s == hsMark )
scr_front( YELLOW );
else if( holes[ h ].s == hsError )
scr_front( LIGHTRED );
else
switch( ( x + y + 40 ) % 2 )
{
case 0: scr_front( LIGHTBLUE ); break;
case 1: scr_front( LIGHTGREEN ); break;
case 2: scr_front( YELLOW ); break;
}
scr_goto( ( floor + x ) * 2 + 1 - y, floor - y + 1 );
if( holes[ i ].s == hsOpen )
cout << hvStr[ holes[ i ].v ];
else
cout << hsStr[ holes[ i ].s ];
}
if( pos < hole )
{
scr_front( MAGENTA );
pos.get( x, y );
scr_goto( ( floor + x ) * 2 + 1 - y, floor - y + 1 );
if( holes[ pos ].s == hsOpen )
cout << hvStr[ holes[ pos ].v ];
else
cout << hsStr[ holes[ pos ].s ];
}
scr_front( YELLOW );
scr_goto( 1, floor * 2 + 2 );
cout << "还剩下雷数: " << left_mine ;
return hrOK;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -