Skip to content

Commit

Permalink
初步实现方块移动后的还原
Browse files Browse the repository at this point in the history
  • Loading branch information
Leslie-Ke committed Jul 29, 2024
1 parent 038c7a3 commit 7324537
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 7 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/我的消消乐/v17/.suo
Binary file not shown.
Binary file modified .vs/我的消消乐/v17/Browse.VC.db
Binary file not shown.
Binary file modified .vs/我的消消乐/v17/ipch/AutoPCH/b63fb6d5f4d0e8f3/TOOLS.ipch
Binary file not shown.
Binary file modified x64/Release/我的消消乐.exe
Binary file not shown.
Binary file modified x64/Release/我的消消乐.pdb
Binary file not shown.
23 changes: 21 additions & 2 deletions 我的消消乐/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ struct block{
int posX1, posY1;//第一次单击的行和列
int posX2, posY2;//第二次单击的行和列

bool isMoving;//表示当前是否在移动
bool isSwap; //当单击两个相邻的方块后设置为true

void init() {
//创建游戏窗口
initgraph(WIN_WIDHT, WIN_HEIGHT, 1);
Expand Down Expand Up @@ -67,6 +70,8 @@ void init() {
}

click = 0;
isMoving = false;
isSwap = false;
}

void updateWindow() {
Expand Down Expand Up @@ -121,6 +126,7 @@ void userClick() {
if (abs(posX2 - posX1) + abs(posY2 - posY1) == 1) {
exchange(posY1, posX1, posY2, posX2);
click = 0;
isSwap = true;
//后续音效
}
else {
Expand All @@ -134,26 +140,39 @@ void userClick() {
}

void move() {
isMoving = false;
for (int i = ROWS; i > 0; i--) {
for (int j = 1; j <= COLS; j++) {
struct block* p = &map[i][j];

int dx, dy;
for (int k = 0; k < 4; k++) {

int x = off_x + (p->col - 1) * (block_size + 5);
int y = off_y + (p->row - 1) * (block_size + 5);

int dx = p->x - x;
int dy = p->y - y;
dx = p->x - x;
dy = p->y - y;

if (dx) p->x -= dx / abs(dx);
if (dy) p->y -= dy / abs(dy);
}

if (dx || dy) isMoving = true;
}
}
}

void huanYuan() {
//发生移动后,而且这个单向移动已经结束
if (isSwap && !isMoving) {
//如果没有匹配到三个或者三个以上的方块,就设置还原
if (1) {//后续优化,先完成还原的基础逻辑代码
exchange(posY1, posX1, posY2, posX2);
}

isSwap = false;
}
}
int main() {
init();//初始化
Expand Down
Binary file modified 我的消消乐/x64/Release/main.obj
Binary file not shown.
Binary file modified 我的消消乐/x64/Release/vc143.pdb
Binary file not shown.
Binary file modified 我的消消乐/x64/Release/我的消消乐.iobj
Binary file not shown.
Binary file modified 我的消消乐/x64/Release/我的消消乐.ipdb
Binary file not shown.
6 changes: 3 additions & 3 deletions 我的消消乐/x64/Release/我的消消乐.log
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
 main.cpp
D:\vscode\我的消消乐\我的消消乐\main.cpp(54,12): warning C4244: “参数”: 从“time_t”转换到“unsigned int”,可能丢失数据
D:\vscode\我的消消乐\我的消消乐\main.cpp(58,12): warning C4244: “参数”: 从“time_t”转换到“unsigned int”,可能丢失数据
正在生成代码
1 of 18 functions ( 5.6%) were compiled, the rest were copied from previous compilation.
2 of 18 functions (11.1%) were compiled, the rest were copied from previous compilation.
0 functions were new in current compilation
1 functions had inline decision re-evaluated but remain unchanged
0 functions had inline decision re-evaluated but remain unchanged
已完成代码的生成
我的消消乐.vcxproj -> D:\vscode\我的消消乐\x64\Release\我的消消乐.exe
4 changes: 2 additions & 2 deletions 我的消消乐/我的消消乐.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<ClCompile Include="tools.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="tools.cpp">
<ClCompile Include="main.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
Expand Down

0 comments on commit 7324537

Please sign in to comment.