Skip to content

Commit 56cf6f5

Browse files
committed
推箱子v0.0.3
修复了在某些情况下撤回出错的问题 修复了一些bug
1 parent 363ca1d commit 56cf6f5

7 files changed

Lines changed: 159 additions & 18 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
目前实现的功能有:
1818

19-
1. 已实现在无限步数下的撤回操作~~基于链表的有限步数下的单次回滚(撤回)等操作 (通俗点说,就是不支持多次撤回,撤回的前一步不能是撤回步骤)~~
19+
1. 已实现在无限步数下的撤回操作
20+
~~基于链表的有限步数下的单次回滚(撤回)等操作 (通俗点说,就是不支持多次撤回,撤回的前一步不能是撤回步骤)~~
2021
2. 基于ncurses.h库而实现的窗口和方向键等功能 (本程序多次使用这个库里面的函数,建议了解并学习后使用它)
2122
3. 在玩过的关卡中可自由选择关卡
2223
4. 通过文件读写方式存数据和地图
@@ -45,7 +46,7 @@ gcc main.c -o PushBox -lncurses
4546

4647
游戏🎮游玩示例GIF图:
4748

48-
![2022-05-05 12.48.32](README/2022-05-05%2012.48.32.gif)
49+
![v0.0.3-2022-05-07 00.10.53](README/v0.0.3-2022-05-07%2000.10.53.gif)
4950

5051
## Todo
5152

1.69 MB
Loading
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Start testing: May 06 23:13 CST
1+
Start testing: May 07 00:09 CST
22
----------------------------------------------------------
3-
End testing: May 06 23:13 CST
3+
End testing: May 07 00:09 CST

data.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Top_Level:14
2+
Latest_Level:14

main

51.5 KB
Binary file not shown.

main.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,9 @@ void moveUp(Position *p) {
475475

476476
//人上面是目的地
477477
if (map[uy][ux] == 4) {
478-
map[y][x] = 0;
478+
if (map[y][x] == 6) {
479+
map[y][x] = 4;
480+
} else map[y][x] = 0;
479481
map[uy][ux] = 6;
480482
//更新人的坐标
481483
y = uy;
@@ -547,7 +549,9 @@ void moveDown(Position *p) {
547549

548550
//人下面是目的地
549551
if (map[uy][ux] == 4) {
550-
map[y][x] = 0;
552+
if (map[y][x] == 6) {
553+
map[y][x] = 4;
554+
} else map[y][x] = 0;
551555
map[uy][ux] = 6;
552556
//更新人的坐标
553557
y = uy;
@@ -620,7 +624,9 @@ void moveLeft(Position *p) {
620624

621625
//人左面是目的地
622626
if (map[uy][ux] == 4) {
623-
map[y][x] = 0;
627+
if (map[y][x] == 6) {
628+
map[y][x] = 4;
629+
} else map[y][x] = 0;
624630
map[uy][ux] = 6;
625631
//更新人的坐标
626632
x = ux;
@@ -693,7 +699,9 @@ void moveRight(Position *p) {
693699

694700
//人右面是目的地
695701
if (map[uy][ux] == 4) {
696-
map[y][x] = 0;
702+
if (map[y][x] == 6) {
703+
map[y][x] = 4;
704+
} else map[y][x] = 0;
697705
map[uy][ux] = 6;
698706
//更新人的坐标
699707
x = ux;
@@ -750,28 +758,33 @@ Position *moveBack(Position *head, Position *p) {
750758
int n = 0;//记录📝指针循环♻️次数
751759

752760
while (tmp->next->next != NULL) {//移动指针到倒数第二个
753-
tmp = tmp->next;
754-
n++;
761+
tmp = tmp->next;//链表tmp指向下一个节点
762+
n++;//计数n增加一
755763
}
756764

757765
//判断步数是否有两步以上,如果有就不进行撤回
758766
if (!n) {
759-
free(del);
767+
free(del);//释放指针del的内存
760768

761769
check = 3;//不可再进行撤回标识
762770

763771
return p;
764772
}
765773

766774
del = tmp->next; //要删除的位置,即当前位置
767-
tmp->next = NULL;
775+
tmp->next = NULL;//删除tmp的下一个节点
768776
p = tmp; //要撤回到的位置
769777

778+
//如果有相同的坐标,直接删除一个。
779+
if ((p->y == del->y) && (p->x == del->x)) {
780+
free(del);//释放指针del的内存
781+
782+
check = 1;//可再进行撤回标识
783+
784+
return p;
785+
}
786+
770787
if ((p->box_x > 0) && (p->box_y > 0)) { //如果人物移动前有箱子📦的话
771-
//撤回人物和撤回箱子📦移动,(顺带覆盖掉了人物)
772-
// if (map[del->y][del->x] == 6) {
773-
// map[del->y][del->x] = 5;
774-
// } else map[del->y][del->x] = 3;
775788
//撤回人物的移动。
776789
if (map[p->y][p->x] == 4) {//如果被撤回的位置是目的地
777790
map[p->y][p->x] = 6;//是,则修改人人在目的地
@@ -787,7 +800,7 @@ Position *moveBack(Position *head, Position *p) {
787800
else map[p->box_y + y_][p->box_x + x_] = 0;//如果不是,则修改为空
788801

789802
//撤回箱子📦的移动
790-
if (map[p->box_y][p->box_x] == 4)//判断箱子📦撤回到的位置是否为为目的地
803+
if (map[p->box_y][p->box_x] == 4 || map[p->box_y][p->box_x] == 6)//判断箱子📦撤回到的位置是否为含有目的地
791804
map[p->box_y][p->box_x] = 5;//是,则将被撤回的位置修改为已完成✅的箱子📦
792805
else map[p->box_y][p->box_x] = 3;//如果不是,则修改为箱子📦
793806

@@ -804,7 +817,7 @@ Position *moveBack(Position *head, Position *p) {
804817
} else map[del->y][del->x] = 0;//如果不是,则修改为空白
805818
}
806819

807-
free(del);
820+
free(del);//释放指针del的内存
808821

809822
check = 1;
810823

map.txt

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
1 1 1 1 1 1 1 0
2+
1 0 0 3 0 4 1 0
3+
1 0 0 1 1 1 1 0
4+
1 0 2 1 0 0 0 0
5+
1 1 1 1 0 0 0 0
6+
0 0 0 0 0 0 0 0
7+
0 0 0 0 0 0 0 0
8+
0 0 0 0 0 0 0 0
9+
10+
1 1 1 1 1 1 1 0
11+
1 0 0 2 0 0 1 0
12+
1 0 0 0 0 0 1 0
13+
1 0 0 0 3 4 1 0
14+
1 0 0 0 0 0 1 0
15+
1 1 1 1 1 1 1 0
16+
0 0 0 0 0 0 0 0
17+
0 0 0 0 0 0 0 0
18+
19+
0 0 1 1 1 0 0 0
20+
0 0 1 4 1 0 0 0
21+
0 0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