QT+C++实现连连看 (二)
nter1,const Point& second);
void AddPoint(const Point& first,const Point& center1,const Point& center2,const Point& second);
~PathRecord();
Point* operator[](int index);
int Size();
private:
vector pointVector;
};
PathFind主要是测试两个点是否能成功连接,练练的核心实现就是他了。
#pragma once
extern DType A[row][column];
//寻路,主要的逻辑实现
class PathFind
{
public:
PathFind();
~PathFind();
bool Left(const Point& first,const Point& second);
bool Right(const Point& first,const Point& second);
bool Top(const Point& first,const Point& second);
bool Bottom(const Point& first,const Point& second);
bool Center(const Point& first,const Point& second);
bool OneLine(TwoPoint& endPoint);
bool OneLine(const Point& first,const Point& second);
bool MoreLine(TwoPoint& endPoint);
bool MoreLine(const Point& first,const Point& second);
bool Near(TwoPoint& endPoint);
bool Near(const Point& first,const Point& second);
bool Search(TwoPoint& endPoint);
bool Search(const Point& first,const Point& second);
private:
//判断两个点是否在一条竖线上即同Y
bool SameY(const Point& first,const Point& second);
//判断两次点击是否在一条横线上即同X
bool SameX(const Point& first,const Point& second);
};
CheckResult判断是否成功或是无解。
#pragma once
//结果判定-判定是死局或是已通关
class CheckResult
{
public:
CheckResult(int _leftPoint);
int LeftPoint() const;//返回剩下的点
int LeftLinkLine();//可连接的点对数
void SearchLeftLinkLine();//查询可连接的点对数
void SearchLeftPoint();//查询剩下的点个数
bool Reduce2Point();//减少两个剩余的点
bool IsSuccess();//判断是否成功
bool IsNoSolution();//是否是无解
private:
int leftPoint;//剩下的点用于判断是否结束
volatile int leftLinkLine;//可连接的点对数 用于判断是否死局
};
IntelligentTest智能测试,就是让电脑来玩连连看,事实证明电脑玩得很快啊,主要是用来测试的,经过他的测试就知道程序实现是否有问题了。这也是很关键的一个环节,测试发现了一些问题,这也是我少有的写测试相关的代码,个人认为自己写测试代码比手动测试效果好很多啊。
#pragma once
//智能测试
class IntelligentTest
{
public:
IntelligentTest();
void Remove(const Point& p);//删除已经连接成功的点
Point GetFirstPoint();//获取第一个点
Point GetSecondPoint();//获取第二个点
void AddHasReadPoint(const Point& p);//将已经检索过得点(暂时没有找到跟他匹配的点)加入hasReadList中
private:
void InitDataBind();//将所有非空的点的坐标(某个值)加入集合noReadList中
int firstIndex;//第一个点在集合中的索引
int secondIndex;//第二个点在集合中的索引
vector hasReadList;//存放已经读了的点信息
vector noReadList;//存放剩下的点信息
};
开始图形及运行时间如下:

智能测试,程序自动玩连连看步骤如下:
