diff --git a/.gitignore b/.gitignore index 80e11c7..b244177 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,10 @@ +# Qt-version-dependent debugging output +build-PictureMatching3-Desktop_Qt_5_11_1_MinGW_32bit-Debug/ + +# Qt Creator config +*.pro.user +## E.g. PictureMatching\PictureMatching3\PictureMatching3.pro.user + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/LICENSE b/LICENSE index 95a764f..a996745 100644 --- a/LICENSE +++ b/LICENSE @@ -5,12 +5,12 @@ Copyright (c) 2017 ThreeDog ->https://www.github.com/TheThreeDog wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a super bottles of Sprite in return. -fork from:https://en.wikipedia.org/wiki/Beerware & https://github.com/bitdust/WamaCry/blob/master/LICENSE.txt -of course, you can copy this and modify it again. +Forked from: https://en.wikipedia.org/wiki/Beerware & https://github.com/bitdust/WamaCry/blob/master/LICENSE.txt +Of course, you can copy this and modify it again. “雪碧软件协议”(第一版): ->https://www.github.com/TheThreeDog 编写了此文件。 -只要你还保留本协议文本,你可以以使用此软件做任何事。 +只要你还保留本协议文本,你可以使用此软件做任何事。 如果我们在某一天相遇了,而且你认为此软件很有价值,你可以为我买一大瓶雪碧来答谢。 -此协议抄袭自:https://en.wikipedia.org/wiki/Beerware 和 https://github.com/bitdust/WamaCry/blob/master/LICENSE.txt -当然,你可以按照你的喜好来修改此协议. +此协议抄袭自 https://en.wikipedia.org/wiki/Beerware 和 https://github.com/bitdust/WamaCry/blob/master/LICENSE.txt +当然,你可以按照你的喜好来修改此协议。 diff --git a/PictureMatching3/gamemain.cpp b/PictureMatching3/gamemain.cpp index adce131..9ad3ae7 100644 --- a/PictureMatching3/gamemain.cpp +++ b/PictureMatching3/gamemain.cpp @@ -3,7 +3,15 @@ #include #include -using namespace std; +using std::cout; +using std::endl; +using std::min; +using std::max; + +#include +using std::tuple; +using std::make_tuple; // variables -> tuple +using std::tie; // tuple -> variables GameMain::GameMain(QWidget *parent) :TDWidget(":/img/game_main_with_logo.png",parent) @@ -73,6 +81,16 @@ void GameMain::createItems() } //方块的图片是随机的。 } + +// 坐标转位置 +tuple coordicateToIndex(MyItem *item1, MyItem *item2){ + int x1 = (item1->x()-100)/65; // Gee, magic number 100, 65 + int y1 = (item1->y()-100)/65; + int x2 = (item2->x()-100)/65; + int y2 = (item2->y()-100)/65; + return make_tuple(x1,y1,x2,y2); +} + //判断可以连通的函数 bool GameMain::canConnect(MyItem *item1, MyItem *item2) { @@ -80,16 +98,14 @@ bool GameMain::canConnect(MyItem *item1, MyItem *item2) if(item1 == NULL || item2 == NULL) return false; //提取两个方块数组中所处的位置 - int x1 = (item1->x()-100)/65; - int y1 = (item1->y()-100)/65; - int x2 = (item2->x()-100)/65; - int y2 = (item2->y()-100)/65; + int x1,y1,x2,y2; + tie(x1,y1,x2,y2) = coordicateToIndex(item1,item2); // bool ret = false; // ret = canConnect(x1,x2,y2,y2); // return ret; return canConnect(x1,y1,x2,y2); - } + //重载一个连通函数接口 bool GameMain::canConnect(int x1, int y1, int x2, int y2) { diff --git a/README.md b/README.md index 0b7a06b..5b9555d 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@ - 一个王者荣耀风格的连连看游戏,实现了连连看的基本算法和功能。超过十秒没有消除就会游戏失败。全部消除游戏成功。提供重新开始、重新排列、提示(会直接消除两个方块)退出游戏的功能。 ## 说明: -- 开发平台: Windows 7 X64. +- 开发平台: Windows 7 x64. - 开发环境: Qt 5.7 - 游戏中所有的代码以及资源文件均已开源,可自行下载,欢迎更多的学习交流。 ## 用法: -- 使用Qt打开项目.pro文件,编译运行。 +- 使用 Qt Creator 打开项目 `.pro` 文件,编译运行。 ## 项目截图: ![项目截图1](show/show_1.jpg) @@ -20,4 +20,4 @@ ![项目截图4](show/show_4.jpg) ## 开源协议: -- 雪碧软件协议 +- [雪碧软件协议](./LICENSE)