From 048cc3f9df8bc95ed8ac4e69f7a6155415d22149 Mon Sep 17 00:00:00 2001 From: SnowOnion Date: Mon, 20 Aug 2018 16:14:24 +0800 Subject: [PATCH 1/3] Maybe a little more elegant --- LICENSE | 10 +++++----- README.md | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) 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/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) From 9f94bb8deef23063014e062494d2578c38f1d7b7 Mon Sep 17 00:00:00 2001 From: SnowOnion Date: Mon, 20 Aug 2018 17:15:36 +0800 Subject: [PATCH 2/3] Gitignoring more files: debug output & .pro.user config, after importing into Windows Qt Creator 4.7.0 and Qt 5.11.1 --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) 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] From 19ee5625aced8fd221c2614b3c83c97bc8dfb5b2 Mon Sep 17 00:00:00 2001 From: SnowOnion Date: Mon, 20 Aug 2018 17:52:43 +0800 Subject: [PATCH 3/3] Outlining funtions to debug, using std::tuple, std::make_tuple and std::tie in . Haven't located root cause yet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现在的行为:如果开局试图消除 左上角的卡片 和 第一行或第一列的相同卡片,会不能消除。单步跟踪发现 item1 -> x() 与 item2 -> x() 相等,item1 -> y() 与 item2 -> y() 相等,这显然不符合预期。但我不熟悉 Qt,没有继续跟下去。 --- PictureMatching3/gamemain.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) 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) {