Compare commits

..

8 Commits

@ -0,0 +1,33 @@
用例名eat
执行者:玩家
目标:通过吃东西来补充角色的饥饿值
前置条件:
玩家拥有至少一个可食用物品
玩家处于可以吃东西的状态(例如,非战斗状态)
玩家饥饿值未满
后置条件:
食物使用后,玩家的饥饿值恢复
玩家的状态可能因食物效果而改变
主要场景:
玩家选择一个食物。
玩家点击“使用”选项。
游戏判断玩家是否满足使用该道具的条件(例如,是否饥饿,是否非战斗)。
如果满足条件,游戏将吃掉食物,并恢复饥饿值。
如果为特殊食物,赋予特殊效果
使用后食物消失
玩家可以查看食物使用后的效果和状态变化。
交互动作:
1玩家遇到特殊情况后下达命令cmd.c并apply.c执行来选择使用食物
2检查是否饥饿若饥饿则使用食物
3根据食物使用更新内存分配alloc.c并记录时间date.c参数若食物有效果则用apply.c应用效果
用例交互图
玩家
| | 选择食物 |---------->| 判断条件饥饿值是否小于90 |---------->| 显示效果 |---------->| 恢复饥饿值更新状态 |---------->| 更新UI |---------->| 反馈 |
游戏系统
| | 触发条件 |---------->| 验证玩家 |---------->| 获取道具信息|---------->| 执行效果|---------->| 更新UI |---------->| 返回结果 |

@ -17,7 +17,7 @@ NEARDATA const struct c_color_names c_color_names = {
"black", "amber", "golden", "light blue", "red", "green", "black", "amber", "golden", "light blue", "red", "green",
"silver", "blue", "purple", "white", "orange" "silver", "blue", "purple", "white", "orange"
}; };
const char *c_obj_colors[] = { //这里定义了一些物品的颜色 const char *c_obj_colors[] = {
"black", /* CLR_BLACK */ "black", /* CLR_BLACK */
"red", /* CLR_RED */ "red", /* CLR_RED */
"green", /* CLR_GREEN */ "green", /* CLR_GREEN */
@ -36,8 +36,8 @@ const char *c_obj_colors[] = { //这里定义了一些物品的颜色
"white", /* CLR_WHITE */ "white", /* CLR_WHITE */
}; };
const struct c_common_strings c_common_strings = //结构体变量中包含了一些常见的字符串,用于文本输出 const struct c_common_strings c_common_strings =
{ "Nothing happens.", //在游戏中提供反馈、描述情况,进行交互 { "Nothing happens.",
"That's enough tries!", "That's enough tries!",
"That is a silly thing to %s.", "That is a silly thing to %s.",
"shudder for a moment.", "shudder for a moment.",
@ -50,34 +50,33 @@ const struct c_common_strings c_common_strings = //结构体变量中包含了
{ "mon", "you" } { "mon", "you" }
}; };
const struct savefile_info default_sfinfo = { //定义了保存文件的默认信息 const struct savefile_info default_sfinfo = {
#ifdef NHSTDC //用于保存文件格式的标志位 #ifdef NHSTDC
0x00000000UL 0x00000000UL
#else #else
0x00000000L 0x00000000L
#endif #endif
#if defined(COMPRESS) || defined(ZLIB_COMP) //用于外部压缩标志位 #if defined(COMPRESS) || defined(ZLIB_COMP)
| SFI1_EXTERNALCOMP | SFI1_EXTERNALCOMP
#endif #endif
#if defined(ZEROCOMP) #if defined(ZEROCOMP)
| SFI1_ZEROCOMP //零压缩标志位 | SFI1_ZEROCOMP
#endif #endif
#if defined(RLECOMP) #if defined(RLECOMP)
| SFI1_RLECOMP //RLE压缩标志 | SFI1_RLECOMP
#endif #endif
, ,
#ifdef NHSTDC #ifdef NHSTDC
0x00000000UL, 0x00000000UL //保留字段 0x00000000UL, 0x00000000UL
#else #else
0x00000000L, 0x00000000L 0x00000000L, 0x00000000L
#endif #endif
}; };
const char disclosure_options[] = "iavgco"; //是一个字符数组,包含了几个选项。这些选项用于控制信息的披露程度。 const char disclosure_options[] = "iavgco";
char emptystr[] = {0}; /* non-const */ //是一个字符数组,用于表示空字符串。它是非常量数组,可以被修改。 char emptystr[] = {0}; /* non-const */
NEARDATA struct flag flags; /* extern declaration is in flag.h, not decl.h */ NEARDATA struct flag flags; /* extern declaration is in flag.h, not decl.h */
//是一个结构体变量用于存储游戏中的标志位。该变量在flag.h中有外部声明。
/* Global windowing data, defined here for multi-window-system support */ /* Global windowing data, defined here for multi-window-system support */
#ifdef WIN32 #ifdef WIN32
@ -85,28 +84,25 @@ boolean fqn_prefix_locked[PREFIX_COUNT] = { FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE }; FALSE };
//是一个布尔数组用于表示文件名前缀是否被锁定。在这段代码中它被初始化为全为FALSE。
#endif #endif
#ifdef PREFIXES_IN_USE #ifdef PREFIXES_IN_USE
const char *fqn_prefix_names[PREFIX_COUNT] = { const char *fqn_prefix_names[PREFIX_COUNT] = {
"hackdir", "leveldir", "savedir", "bonesdir", "datadir", "hackdir", "leveldir", "savedir", "bonesdir", "datadir",
"scoredir", "lockdir", "sysconfdir", "configdir", "troubledir" "scoredir", "lockdir", "sysconfdir", "configdir", "troubledir"
};//是一个字符串指针数组,包含了一些文件名前缀的名称。这些名称用于指定不同类型文件的存储路径。 };
#endif #endif
/* x/y/z deltas for the 10 movement directions (8 compass pts, 2 down/up) */ /* x/y/z deltas for the 10 movement directions (8 compass pts, 2 down/up) */
const schar xdir[N_DIRS_Z] = { -1, -1, 0, 1, 1, 1, 0, -1, 0, 0 }; const schar xdir[N_DIRS_Z] = { -1, -1, 0, 1, 1, 1, 0, -1, 0, 0 };
const schar ydir[N_DIRS_Z] = { 0, -1, -1, -1, 0, 1, 1, 1, 0, 0 }; const schar ydir[N_DIRS_Z] = { 0, -1, -1, -1, 0, 1, 1, 1, 0, 0 };
const schar zdir[N_DIRS_Z] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, -1 }; const schar zdir[N_DIRS_Z] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, -1 };
//是三个有符号字符数组分别表示十个移动方向包括八个主要方向和上下方向的x、y和z轴的增量。
/* redordered directions, cardinals first */ /* redordered directions, cardinals first */
const schar dirs_ord[N_DIRS] = const schar dirs_ord[N_DIRS] =
{ DIR_W, DIR_N, DIR_E, DIR_S, DIR_NW, DIR_NE, DIR_SE, DIR_SW }; { DIR_W, DIR_N, DIR_E, DIR_S, DIR_NW, DIR_NE, DIR_SE, DIR_SW };
//是一个有符号字符数组,表示经过重新排序的移动方向。首先是四个基本方向,然后是四个对角线方向。
NEARDATA boolean has_strong_rngseed = FALSE; //是一个布尔变量,用于表示是否具有强随机种子。 NEARDATA boolean has_strong_rngseed = FALSE;
struct engr *head_engr; struct engr *head_engr;
NEARDATA struct instance_flags iflags; //是一个结构体变量,用于存储游戏实例的标志位。 NEARDATA struct instance_flags iflags;
/* NOTE: the order of these words exactly corresponds to the /* NOTE: the order of these words exactly corresponds to the
order of oc_material values #define'd in objclass.h. */ order of oc_material values #define'd in objclass.h. */
const char *materialnm[] = { "mysterious", "liquid", "wax", "organic", const char *materialnm[] = { "mysterious", "liquid", "wax", "organic",
@ -115,35 +111,29 @@ const char *materialnm[] = { "mysterious", "liquid", "wax", "organic",
"metal", "copper", "silver", "gold", "metal", "copper", "silver", "gold",
"platinum", "mithril", "plastic", "glass", "platinum", "mithril", "plastic", "glass",
"gemstone", "stone" }; "gemstone", "stone" };
//是一个字符串指针数组包含了一些物品材质的名称。这些名称与objclass.h中定义的oc_material值的顺序完全对应。 const char quitchars[] = " \r\n\033";
NEARDATA struct savefile_info sfcap, sfrestinfo, sfsaveinfo;
const char quitchars[] = " \r\n\033";//是一个包含一些表示退出字符的字符串,包括空格、回车、换行和转义字符。 const int shield_static[SHIELD_COUNT] = {
NEARDATA struct savefile_info sfcap, sfrestinfo, sfsaveinfo; //结构体变量,用于保存文件的信息。
const int shield_static[SHIELD_COUNT] = {//是一个整型数组,包含了一些盾牌的静态符号。
S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4, /* 7 per row */ S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4, /* 7 per row */
S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4, S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4,
S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4, S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4,
}; };
NEARDATA struct you u;//结构体变量,用于表示玩家角色的状态和属性。 NEARDATA struct you u;
NEARDATA time_t ubirthday; //是一个time_t类型的变量表示玩家角色的出生时间。 NEARDATA time_t ubirthday;
NEARDATA struct u_realtime urealtime; //用于表示游戏时间的实时信息。 NEARDATA struct u_realtime urealtime;
NEARDATA struct obj *uwep, *uarm, *uswapwep, //结构体的指针变量,用于表示玩家角色的装备和物品。 NEARDATA struct obj *uwep, *uarm, *uswapwep,
*uquiver, /* quiver */ *uquiver, /* quiver */
*uarmu, /* under-wear, so to speak */ *uarmu, /* under-wear, so to speak */
*uskin, /* dragon armor, if a dragon */ *uskin, /* dragon armor, if a dragon */
*uarmc, *uarmh, *uarms, *uarmg,*uarmf, *uamul, *uarmc, *uarmh, *uarms, *uarmg,*uarmf, *uamul,
*uright, *uleft, *ublindf, *uchain, *uball; *uright, *uleft, *ublindf, *uchain, *uball;
const char vowels[] = "aeiouAEIOU"; //是一个包含元音字母的字符串,包括小写和大写的元音字母。 const char vowels[] = "aeiouAEIOU";
NEARDATA winid WIN_MESSAGE, WIN_STATUS, WIN_MAP, WIN_INVEN;//是窗口标识符winid类型变量用于表示游戏中的不同窗口。 NEARDATA winid WIN_MESSAGE, WIN_STATUS, WIN_MAP, WIN_INVEN;
const char ynchars[] = "yn"; //是包含一些表示"yes"和"no"的字符的字符串。 const char ynchars[] = "yn";
const char ynqchars[] = "ynq"; const char ynqchars[] = "ynq";
const char ynaqchars[] = "ynaq"; const char ynaqchars[] = "ynaq";
const char ynNaqchars[] = "yn#aq"; const char ynNaqchars[] = "yn#aq";
NEARDATA long yn_number = 0L; NEARDATA long yn_number = 0L;
//这些变量的定义用于实现游戏的逻辑和界面显示等功能。
//其中包括随机数种子、文本输出、文件操作、游戏状态、时间管理、玩家角色属性、装备和物品等。
#ifdef PANICTRACE #ifdef PANICTRACE
const char *ARGV0; const char *ARGV0;

@ -13,7 +13,7 @@
#define TEXT_TOMBSTONE #define TEXT_TOMBSTONE
#endif #endif
#if defined(mac) || defined(__BEOS__) #if defined(mac) || defined(__BEOS__)
#ifndef TEXT_TOMBSTONE #ifndef TEXT_TOMBSTONE//墓碑文档定义
#define TEXT_TOMBSTONE #define TEXT_TOMBSTONE
#endif #endif
#endif #endif
@ -70,7 +70,7 @@ static const char *const rip_txt[] = {
#define DEATH_LINE 8 /* *char[] line # for death description */ #define DEATH_LINE 8 /* *char[] line # for death description */
#define YEAR_LINE 12 /* *char[] line # for year */ #define YEAR_LINE 12 /* *char[] line # for year */
static void static void//将给定的文本字符串居中并放置在特定的位置。
center(int line, char *text) center(int line, char *text)
{ {
register char *ip, *op; register char *ip, *op;
@ -81,7 +81,7 @@ center(int line, char *text)
} }
void void
genl_outrip(winid tmpwin, int how, time_t when) genl_outrip(winid tmpwin, int how, time_t when)//在游戏中生成并显示一个“墓碑”文本
{ {
register char **dp; register char **dp;
register char *dpx; register char *dpx;

@ -67,7 +67,7 @@ static FILE *bw_FILE[MAXFD] = {0,0,0,0,0};
*/ */
static int static int
getidx(int fd, int flg) getidx(int fd, int flg)//保存给定的文件描述符 fd。
{ {
int i, retval = -1; int i, retval = -1;
@ -87,7 +87,7 @@ getidx(int fd, int flg)
/* Let caller know that bclose() should handle it (TRUE) */ /* Let caller know that bclose() should handle it (TRUE) */
boolean boolean
close_check(int fd) close_check(int fd)//检查给定的文件描述符 fd 是否已经存在于 bw_sticky 数组中。
{ {
int idx = getidx(fd, NOSLOT); int idx = getidx(fd, NOSLOT);
boolean retval = FALSE; boolean retval = FALSE;
@ -98,7 +98,7 @@ close_check(int fd)
} }
void void
bufon(int fd) bufon(int fd)//启用缓冲IO并将给定的文件描述符 fd 关联到一个 bw_sticky 数组中的索引。
{ {
int idx = getidx(fd, NOFLG); int idx = getidx(fd, NOFLG);
@ -119,7 +119,7 @@ bufon(int fd)
} }
void void
bufoff(int fd) bufoff(int fd)//关闭与给定文件描述符 fd 关联的缓冲IO。
{ {
int idx = getidx(fd, NOFLG); int idx = getidx(fd, NOFLG);
@ -130,7 +130,7 @@ bufoff(int fd)
} }
void void
bclose(int fd) bclose(int fd)//关闭与给定文件描述符 fd 关联的文件,并释放相关的资源。
{ {
int idx = getidx(fd, NOSLOT); int idx = getidx(fd, NOSLOT);
@ -150,7 +150,7 @@ bclose(int fd)
} }
void void
bflush(int fd) bflush(int fd)//刷新与给定文件描述符 fd 关联的缓冲区。
{ {
int idx = getidx(fd, NOFLG); int idx = getidx(fd, NOFLG);

@ -18,7 +18,7 @@
struct sysopt sysopt; struct sysopt sysopt;
void void
sys_early_init(void) sys_early_init(void)//初始化
{ {
sysopt.support = (char *) 0; sysopt.support = (char *) 0;
sysopt.recover = (char *) 0; sysopt.recover = (char *) 0;
@ -90,7 +90,7 @@ sys_early_init(void)
} }
void void
sysopt_release(void) sysopt_release(void)//系统释放
{ {
if (sysopt.support) if (sysopt.support)
free((genericptr_t) sysopt.support), sysopt.support = (char *) 0; free((genericptr_t) sysopt.support), sysopt.support = (char *) 0;

@ -12,14 +12,14 @@ static NEARDATA int utcnt, utpnt;
static NEARDATA coord utrack[UTSZ]; static NEARDATA coord utrack[UTSZ];
void void
initrack(void) initrack(void)//初始化路径
{ {
utcnt = utpnt = 0; utcnt = utpnt = 0;
} }
/* add to track */ /* add to track */
void void
settrack(void) settrack(void)//添加路径
{ {
if (utcnt < UTSZ) if (utcnt < UTSZ)
utcnt++; utcnt++;
@ -31,7 +31,7 @@ settrack(void)
} }
coord * coord *
gettrack(coordxy x, coordxy y) gettrack(coordxy x, coordxy y)//寻找路径.
{ {
register int cnt, ndist; register int cnt, ndist;
register coord *tc; register coord *tc;

@ -15,10 +15,10 @@ static void insert_rtoption(char *);
/* fill buffer with short version (so caller can avoid including date.h) */ /* fill buffer with short version (so caller can avoid including date.h) */
char * char *
version_string(char *buf, size_t bufsz) version_string(char *buf, size_t bufsz)//获取一个版本字符串并将其存储在提供的缓冲区
{ {
Snprintf(buf, bufsz, "%s", Snprintf(buf, bufsz, "%s",
((nomakedefs.version_string && nomakedefs.version_string[0]) ((nomakedefs.version_string && nomakedefs.version_string[0])//确定要复制哪个版本字符串。检查nomakedefs.version_string是否存在并且是否非空
? nomakedefs.version_string ? nomakedefs.version_string
/* in case we try to write a paniclog entry after releasing /* in case we try to write a paniclog entry after releasing
the 'nomakedefs' data */ the 'nomakedefs' data */
@ -28,7 +28,7 @@ version_string(char *buf, size_t bufsz)
/* fill and return the given buffer with the long nethack version string */ /* fill and return the given buffer with the long nethack version string */
char * char *
getversionstring(char *buf, size_t bufsz) getversionstring(char *buf, size_t bufsz)//获取并格式化一个版本字符串
{ {
Strcpy(buf, nomakedefs.version_id); Strcpy(buf, nomakedefs.version_id);
@ -209,7 +209,7 @@ doextversion(void)
} }
void void
early_version_info(boolean pastebuf) early_version_info(boolean pastebuf)//获取并打印程序版本信息
{ {
char buf1[BUFSZ], buf2[BUFSZ]; char buf1[BUFSZ], buf2[BUFSZ];
char *buf, *tmp; char *buf, *tmp;
@ -295,7 +295,7 @@ comp_times(long filetime)
#endif #endif
boolean boolean
check_version( check_version(//检查给定的文件版本信息是否与预期的版本和配置兼容
struct version_info *version_data, struct version_info *version_data,
const char *filename, const char *filename,
boolean complain, boolean complain,
@ -337,7 +337,7 @@ check_version(
/* this used to be based on file date and somewhat OS-dependant, /* this used to be based on file date and somewhat OS-dependant,
but now examines the initial part of the file's contents */ but now examines the initial part of the file's contents */
boolean boolean
uptodate(NHFILE *nhfp, const char *name, unsigned long utdflags) uptodate(NHFILE *nhfp, const char *name, unsigned long utdflags)//检查给定的文件是否与预期的版本和配置兼容。
{ {
ssize_t rlen = 0; ssize_t rlen = 0;
int cmc = 0, filecmc = 0; int cmc = 0, filecmc = 0;
@ -376,7 +376,7 @@ uptodate(NHFILE *nhfp, const char *name, unsigned long utdflags)
} }
void void
store_formatindicator(NHFILE *nhfp) store_formatindicator(NHFILE *nhfp)//在给定的文件上存储格式指示符。
{ {
char indicate = 'u'; char indicate = 'u';
int cmc = 0; int cmc = 0;
@ -391,7 +391,7 @@ store_formatindicator(NHFILE *nhfp)
} }
void void
store_version(NHFILE *nhfp) store_version(NHFILE *nhfp)//在给定的文件上存储版本信息。
{ {
struct version_info version_data = { struct version_info version_data = {
0UL, 0UL, 0UL, 0UL, 0UL 0UL, 0UL, 0UL, 0UL, 0UL
@ -424,7 +424,7 @@ const char amiga_version_string[] = AMIGA_VERSION_STRING;
#endif #endif
unsigned long unsigned long
get_feature_notice_ver(char *str) get_feature_notice_ver(char *str)//从给定的字符串中解析并提取版本号。
{ {
char buf[BUFSZ]; char buf[BUFSZ];
int ver_maj, ver_min, patch; int ver_maj, ver_min, patch;

@ -6,16 +6,16 @@
#include "hack.h" #include "hack.h"
void void
were_change(struct monst *mon) were_change(struct monst *mon)//处理角色在满月之夜变形成野兽,以及在非满月之夜变回人类的过程,并在这个过程中播放动物的叫声,唤醒附近的怪物等
{ {
if (!is_were(mon->data)) if (!is_were(mon->data))//检查角色是否具有变身能力
return; return;
if (is_human(mon->data)) { if (is_human(mon->data)) {//检查角色是否处于人类形态
if (!Protection_from_shape_changers if (!Protection_from_shape_changers//判断是否应该变身
&& !rn2(night() ? (flags.moonphase == FULL_MOON ? 3 : 30) && !rn2(night() ? (flags.moonphase == FULL_MOON ? 3 : 30)
: (flags.moonphase == FULL_MOON ? 10 : 50))) { : (flags.moonphase == FULL_MOON ? 10 : 50))) {
new_were(mon); /* change into animal form */ new_were(mon); /* 变身为野兽 */
if (!Deaf && !canseemon(mon)) { if (!Deaf && !canseemon(mon)) {
const char *howler; const char *howler;
@ -33,12 +33,12 @@ were_change(struct monst *mon)
if (howler) { if (howler) {
Soundeffect(se_canine_howl, 50); Soundeffect(se_canine_howl, 50);
You_hear("a %s howling at the moon.", howler); You_hear("a %s howling at the moon.", howler);
wake_nearto(mon->mx, mon->my, 4 * 4); wake_nearto(mon->mx, mon->my, 4 * 4);//播放动物的叫声并唤醒附近的怪物
} }
} }
} }
} else if (!rn2(30) || Protection_from_shape_changers) { } else if (!rn2(30) || Protection_from_shape_changers) {//检查是否应该变回人类
new_were(mon); /* change back into human form */ new_were(mon); /* 变回人类 */
} }
/* update innate intrinsics (mainly Drain_resistance) */ /* update innate intrinsics (mainly Drain_resistance) */
set_uasmon(); /* new_were() doesn't do this */ set_uasmon(); /* new_were() doesn't do this */

Loading…
Cancel
Save