-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathself_con.c
More file actions
112 lines (90 loc) · 2.36 KB
/
self_con.c
File metadata and controls
112 lines (90 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright © 2020 魏懿航
// All rights reserved.
// filename:cp_direction.c
// description:实现针对自机控制的函数
// created by 魏懿航 at 05/19/2020
// QQ:770593981
#include <string.h>
#include "PUSH.h"
#include "CONTROL.h"
#include "wasd.c"
#define TIPS 3
int row, temp;
char key;
void wasd(void);
void print_map(void);
void reset_winpoint(void);
int conditions_of_victory(void);
void reset_checkpoint(void);
int control(void)
{
reset_checkpoint();
while(1)
{
print_map();//打印地图
wasd();//检测用户的指令
if(WIN == conditions_of_victory())//胜利条件判定,所有胜利点必须均为@则返回胜利
return WIN;
//对用户提交的特殊需求进行处理
if(key=='B' || key=='b')//退出
return QUIT;
else if(key=='R' || key=='r')
reset_checkpoint();
}
}
//输出地图信息
void print_map()
{
system("cls");//刷新屏幕
for (row = 0; row <= checkpoint_info.mapsize; row++)
{//逐行打印缓存的地图
puts(map_cache[row]);
}
UI(TIPS);
row = 0;
}
//读取并对用户指令做出响应
void wasd()
{
key = getch();//读取指令
//判断用户输入的是上下左右中的哪一个
if(key=='w' || key=='W')
_w();
else if(key=='a' || key=='A')
_a();
else if(key=='s' || key=='S')
_s();
else if(key=='d' || key=='D')
_d();
reset_winpoint();//移动完之后进行一次胜利点检查来恢复*
}
//重置胜利点*
void reset_winpoint()
{//在自机和箱子离开胜利点后,将胜利点恢复成*
for(temp = 0;temp<checkpoint_info.EPsize;temp++)
{
if( map_cache[checkpoint_info.epx[temp]][checkpoint_info.epy[temp]]=='O')
map_cache[checkpoint_info.epx[temp]][checkpoint_info.epy[temp]]= '@';
if( map_cache[checkpoint_info.epx[temp]][checkpoint_info.epy[temp]]!='@' && map_cache[checkpoint_info.epx[temp]][checkpoint_info.epy[temp]]!='S')
map_cache[checkpoint_info.epx[temp]][checkpoint_info.epy[temp]]= '*';
}
}
//胜利条件判断
int conditions_of_victory()
{
int win_count = 0;
for(temp=0;temp<checkpoint_info.EPsize;temp++)
{
if(map_cache[checkpoint_info.epx[temp]][checkpoint_info.epy[temp]] == '@')
win_count++;
}
if(win_count == checkpoint_info.EPsize)
return WIN;
}
//重置关卡信息
void reset_checkpoint()
{
Spx = checkpoint_info.spx, Spy = checkpoint_info.spy;
memcpy(map_cache, checkpoint_info.Map, sizeof(map_cache));
print_map();
}