update
chore: add 3.4.6.2 chore: add 3.4.6.3 chore: add 3.4.6.4 chore: add 3.4.6.5 chore: add 3.4.6.6 chore: add 3.4.6.7 chore: add 3.4.6.8 chore: add 3.4.6.9 chore: add 3.4.6.10 docs: add 3.6.5.1
This commit is contained in:
@@ -28,11 +28,12 @@ struct object {
|
||||
- 通道总是朝一个方向运行;要双向连接两个位置,我们总是必须创建两个单独的通道。乍一看,这似乎很笨拙,但它确实给了我们很大的灵活性来完善命令“go”的行为
|
||||
- 在大地图上,你可能会发现手动创建所有通道很乏味。所以,我强烈建议你使用自定义工具<em>生成</em>地图中重复性更强的部分。这里不会介绍这一点,但您可能会在第 9 章中找到一些灵感,我们将在其中讨论自动胜场。
|
||||
|
||||
思考题:为什么创建两个通道可以使我们的程序更加灵活?
|
||||
::: warning 🤔 思考题:为什么创建两个通道可以使我们的程序更加灵活?
|
||||
:::
|
||||
|
||||
接下来我们将展开对象数组
|
||||
|
||||
# object.h
|
||||
## object.h
|
||||
|
||||
```c
|
||||
typedef struct object {
|
||||
@@ -56,7 +57,7 @@ extern OBJECT objs[];
|
||||
#define endOfObjs (objs + 8)
|
||||
```
|
||||
|
||||
# object.c
|
||||
## object.c
|
||||
|
||||
```c
|
||||
#include <stdio.h>
|
||||
@@ -76,7 +77,7 @@ OBJECT objs[] = {
|
||||
|
||||
我们将在 <em>misc.c</em> 中添加一个小的帮助函数,以确定两个给定位置之间是否存在通道。
|
||||
|
||||
# misc.h
|
||||
## misc.h
|
||||
|
||||
```c
|
||||
extern OBJECT *getPassage(OBJECT *from, OBJECT *to);
|
||||
@@ -84,7 +85,7 @@ extern OBJECT *actorHere(void);
|
||||
extern int listObjectsAtLocation(OBJECT *location);
|
||||
```
|
||||
|
||||
# misc.c
|
||||
## misc.c
|
||||
|
||||
```c
|
||||
#include <stdio.h>
|
||||
@@ -140,14 +141,14 @@ int listObjectsAtLocation(OBJECT *location)
|
||||
|
||||
我们将在命令“go”的实现中使用新功能<em>getPassage</em>来确定是否存在可以将玩家带到所需位置的通道。
|
||||
|
||||
# location.h
|
||||
## location.h
|
||||
|
||||
```c
|
||||
extern void executeLook(const char *noun);
|
||||
extern void executeGo(const char *noun);
|
||||
```
|
||||
|
||||
# location.c
|
||||
## location.c
|
||||
|
||||
```c
|
||||
#include <stdio.h>
|
||||
@@ -177,7 +178,7 @@ void executeGo(const char *noun)
|
||||
// already handled by getVisible
|
||||
}
|
||||
else if (getPassage(player->location, obj) != NULL)
|
||||
//go只会在有地方的时候才会运行起来
|
||||
//go 只会在有地方的时候才会运行起来
|
||||
{
|
||||
printf("OK.\n");
|
||||
player->location = obj;
|
||||
@@ -202,14 +203,14 @@ void executeGo(const char *noun)
|
||||
|
||||
我们还将使用新功能<em>getPassage</em>来确定从玩家站立的位置是否可以看到某个位置。未通过通道连接到当前位置的位置不被视为可见。
|
||||
|
||||
# noun.h
|
||||
## noun.h
|
||||
|
||||
```c
|
||||
extern OBJECT *getVisible(const char *intention, const char *noun);
|
||||
extern OBJECT *getPossession(OBJECT *from, const char *verb, const char *noun);
|
||||
```
|
||||
|
||||
# noun.c
|
||||
## noun.c
|
||||
|
||||
```c
|
||||
#include <stdbool.h>
|
||||
@@ -294,11 +295,12 @@ OBJECT *getPossession(OBJECT *from, const char *verb, const char *noun)
|
||||
|
||||
显然,此示例中的地图是微不足道的:只有两个位置,并且它们在两个方向上都连接在一起。第 12 章将增加第三个地点。
|
||||
|
||||
思考题:你能否绘制一张更精细的地图,并将其变成对象列表(位置和通道)
|
||||
::: warning 🤔 思考题:
|
||||
你能否绘制一张更精细的地图,并将其变成对象列表(位置和通道)
|
||||
|
||||
```
|
||||
注:不用当成任务,自行实验即可
|
||||
```
|
||||
注:不用当成任务,自行实验即可
|
||||
|
||||
:::
|
||||
|
||||
输出样例
|
||||
|
||||
|
||||
Reference in New Issue
Block a user