资源简介
请参看我的博客,这里有对其的详细介绍,http://blog.csdn.net/satanzw/article/details/9531645
代码片段和文件信息
#include “block.h“
#include “minehuntgame.h“
#include
#include
using namespace std;
Block::Block(MineHuntGame *parent int row int col bool isMine/* = false*/)
{
m_isRightPressed = false;
m_isLeftPressed = false;
m_isMine = isMine;
m_mines = -1;
m_row = row;
m_col = col;
m_parent = parent;
}
void Block::show2()
{
cout.width(3);
if (m_isMine)
cout << “*“;
else
cout << mines();
}
void Block::show()
{
cout.width(3);
if (m_isRightPressed)
{
cout << “F“;
}
else if (m_isLeftPressed)
{
if (m_mines <= 0)
cout << “ “;
else
cout << m_mines;
}
else
cout << “*“;
}
int Block::mines()
{
if (m_isMine)
return -1;
if (m_mines != -1)
return m_mines;
// 这里赋0,假设无雷,不管怎样,也只计算一次
m_mines = 0;
for (int aroundRow = m_row - 1; aroundRow <= m_row + 1; ++aroundRow)
{
for (int aroundCol = m_col - 1; aroundCol <= m_col + 1; ++aroundCol)
{
Block *block = m_parent->block(aroundRow aroundCol);
if (block && block != this)
{
if (block->isMine())
++m_mines;
}
}
}
return m_mines;
}
// 仅在生成地图时使用
void Block::swap(Block *block)
{
std::swap(m_isMine block->m_isMine);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-07-27 19:25 MineHunt-Console\
文件 1217 2013-07-27 18:10 MineHunt-Console\block.cpp
文件 909 2013-07-27 18:10 MineHunt-Console\block.h
文件 216 2013-07-27 18:09 MineHunt-Console\main.cpp
文件 377 2013-07-27 17:15 MineHunt-Console\MineHunt-Console.pro
文件 3337 2013-07-27 19:25 MineHunt-Console\minehuntgame.cpp
文件 575 2013-07-27 17:15 MineHunt-Console\minehuntgame.h
评论
共有 条评论