-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaces.c
205 lines (163 loc) · 4 KB
/
places.c
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "places.h"
#include <string.h>
struct _Place{
int placeID;
short is_locked;
short leavebox;
short leftbox;
int stars; /*The number of danger stars that make this room dangerous. For example, a 3 means that with 3 or more stars there is danger in the room*/
int up; /*The upper adjacent room, which is -1 when there is no upper room.*/
int down; /*The bottom adjacent room, which is... " */
int left;
int right;
char desc[1024];
char draw[3500];
};
Place* place_ini (){
Place *p;
p = (Place*) malloc(sizeof(Place));
if (!p) return NULL;
p->is_locked = 0;
p->stars=0;
p->up=-1;
p->down=-1;
p->left=-1;
p->right=-1;
return p;
}
void place_destroy (Place*p){
if (p) free(p);
return;
}
/****************************************Set Functions****************************************/
Place* place_setId (Place *p, int id){
if (!p || id < 0) return NULL;
p->placeID=id;
return p;
}
Place* place_setLock (Place *p, short lock){
if (!p || lock < 0 || lock > 1) return NULL;
p->is_locked=lock;
return p;
}
Place* place_setLeaveBox (Place *p, short box){
if (!p || box < 0 || box > 1) return NULL;
p->leavebox=box;
return p;
}
Place* place_setLeftBox (Place *p, short box){
if (!p || box < 0 || box > 1) return NULL;
p->leftbox=box;
return p;
}
Place* place_setStars (Place *p, int stars){
if (!p || stars < 0) return NULL;
p->stars=stars;
return p;
}
Place* place_setUp (Place *p, int room){
if (!p || room < -1) return NULL;
p->up=room;
return p;
}
Place* place_setDown (Place *p, int room){
if (!p || room < -1) return NULL;
p->down=room;
return p;
}
Place* place_setLeft (Place *p, int room){
if (!p || room < -1) return NULL;
p->left=room;
return p;
}
Place* place_setRight (Place *p, int room){
if (!p || room < -1) return NULL;
p->right=room;
return p;
}
Place* place_setDesc (Place *p, char* desc){
if (!p || !desc) return NULL;
strcpy(p->desc,desc);
return p;
}
Place* place_setDraw (Place *p, char* draw){
if (!p || !draw) return NULL;
strcpy(p->draw,draw);
return p;
}
/****************************************Get Functions****************************************/
int place_getId (Place *p){
if (!p) return -1;
return p->placeID;
}
short place_getLock (Place *p){
if (!p) return -1;
return p->is_locked;
}
short place_getLeaveBox (Place *p){
if (!p) return -1;
return p->leavebox;
}
short place_getLeftBox (Place *p){
if (!p) return -1;
return p->leftbox;
}
int place_getStars (Place *p){
if (!p) return -1;
return p->stars;
}
int place_getUp (Place *p){
if (!p) return -2;
return p->up;
}
int place_getDown (Place *p){
if (!p) return -2;
return p->down;
}
int place_getLeft (Place *p){
if (!p) return -2;
return p->left;
}
int place_getRight (Place *p){
if (!p) return -2;
return p->right;
}
char* place_getDesc (Place *p){
if (!p) return NULL;
return p->desc;
}
char* place_getDraw (Place *p){
if (!p) return NULL;
return p->draw;
}
/****************************************Copy Functions****************************************/
Place* place_copy (Place *src){
Place *p;
if (!src) return NULL;
p = place_ini();
if (!p) return NULL;
p->placeID = src->placeID;
p->is_locked = src->is_locked;
p->stars = src->stars;
p->leavebox = src -> leavebox;
p->leftbox = src -> leftbox;
p->up = src->up;
p->down = src->down;
p->left = src->left;
p->right = src->right;
strcpy(p->draw,src->draw);
strcpy(p->desc,src->desc);
return p;
}
/****************************************Misc Functions****************************************/
Place* place_drawchar(Place* p, int x, int y, char c){
if (!p || x<0 || y<0) return NULL;
if((y*ROWSPCOL+x-2)<2) return p;
p->draw[y * ROWSPCOL + x - 2] = c;
return p;
}
int place_blankSpace(Place* p, int x, int y){
if (!p || x<0 || y<0) return -1;
if (p->draw[y*ROWSPCOL + x - 2] == ' ') return 1;
else return 0;
}