Dever v0.0.2

This commit is contained in:
Codex committed 2026-11-27 06:03:56 +00:00
commit e6e175ebcf
816 files changed
+120349

No files matched your search

@@ -0,0 +1 @@
负责房间探索的状态变化。状态与动作的判断见 [rule/escape.dv](rule/escape.dv),操作例子见 [项目说明](../../../README.md),符号说明见 [游戏主题](doc/game.md)。
@@ -0,0 +1,3 @@
public post play = app.play
public post step = app.step
@@ -0,0 +1,9 @@
# 逃出房间
## game.escape.app.play
按顺序执行行动,胜利或退出后停止。没有行动时返回开场状态。
## game.escape.app.step
根据当前状态和一个行动返回新状态与提示。Won/GaveUp 表示结束,不额外维护结束标志。查看、搜索、开门及退出的所有组合集中在规则表。
@@ -0,0 +1,27 @@
type Stage {
Locked
KeyFound
Won
GaveUp
}
type Action {
Look
Search
Open
Quit
}
type Turn {
stage: Stage
message: Text
}
start() (turn: Turn) {
turn = Turn { stage = Locked, message = "你醒来时,发现自己在一间上锁的房间里。" }
}
advance(action: Action, current: Turn) (acc: Turn, stop: Bool) {
acc = app.step(current.stage, action)
stop = acc.stage == Won or acc.stage == GaveUp
}
@@ -0,0 +1,318 @@
<!-- Generated by dever inspect --links. Do not edit. -->
<!-- source-sha256: 4fad8ed735126db92201e426929c78f8bf48d84df8564a20c9abc936f0fe3d3a -->
# game/escape
按源码顺序阅读。图显示静态路径;运行故障结束当前调用,不是某次执行记录。
<a id="flow-fd525ca826bf86c7ff043119fac95758e4b746975a5092aee80a5fdcd7e4aade"></a>
## POST /game/escape/web/game/play
```dever
public post play = app.play
```
[打开源码](<api/web/game.dv#L1,1>)
```mermaid
flowchart TD
n0["POST /game/escape/web/game/play"]
click n0 href "api/web/game.dv#L1,1" "打开源码"
n1["站点 Host 校验"]
click n1 href "api/web/game.dv#L1,1" "打开源码"
n2["按参数类型解码;拒绝未知、重复及缺失字段"]
click n2 href "api/web/game.dv#L1,1" "打开源码"
n3[["game.escape.app.play"]]
click n3 href "api/web/game.dv#L1,1" "打开源码"
n4["返回 code / message / data"]
click n4 href "api/web/game.dv#L1,1" "打开源码"
n5["错误响应;内部原因仅记服务日志"]
click n5 href "api/web/game.dv#L1,1" "打开源码"
n0 -->|"成功"| n1
n1 -->|"通过"| n2
n2 -->|"通过"| n3
n3 -->|"成功"| n4
n1 -->|"失败"| n5
n2 -->|"失败"| n5
n3 -->|"失败"| n5
```
- 子流程 [game.escape.app.play](<link.md#flow-9dfc359f6c8ebdac6103848e001a4dc947aed529a98b275a5f9dfa777a3a01bc>)
<a id="flow-b6a9b27b972bfe9b38dcbad1133a6131bf68c40687de7580fc8c47026d022093"></a>
## POST /game/escape/web/game/step
```dever
public post step = app.step
```
[打开源码](<api/web/game.dv#L3,1>)
```mermaid
flowchart TD
n0["POST /game/escape/web/game/step"]
click n0 href "api/web/game.dv#L3,1" "打开源码"
n1["站点 Host 校验"]
click n1 href "api/web/game.dv#L3,1" "打开源码"
n2["按参数类型解码;拒绝未知、重复及缺失字段"]
click n2 href "api/web/game.dv#L3,1" "打开源码"
n3[["game.escape.app.step"]]
click n3 href "api/web/game.dv#L3,1" "打开源码"
n4["返回 code / message / data"]
click n4 href "api/web/game.dv#L3,1" "打开源码"
n5["错误响应;内部原因仅记服务日志"]
click n5 href "api/web/game.dv#L3,1" "打开源码"
n0 -->|"成功"| n1
n1 -->|"通过"| n2
n2 -->|"通过"| n3
n3 -->|"成功"| n4
n1 -->|"失败"| n5
n2 -->|"失败"| n5
n3 -->|"失败"| n5
```
- 子流程 [game.escape.app.step](<link.md#flow-ccc70f2ace361a370d7852e76d42bae9b531f95552ecbc55fb22282d9d15444d>)
<a id="flow-65bdcbe09a4a25a28fb2c9ed48b5c8c5b9b51aa0c0d524588252aa575b3da17a"></a>
## game.escape.app.Stage
```dever
type game.escape.app.Stage
```
[打开源码](<flow/escape.dv#L1,1>)
<a id="flow-ee0c1ed77e17cae1c1ae3068f3f680f3721f3ea457dd893aac8cca0e681d7f23"></a>
## game.escape.app.Action
```dever
type game.escape.app.Action
```
[打开源码](<flow/escape.dv#L8,1>)
<a id="flow-377bd39fe59dd1973226cab9b4113f80934a5d264923a909a2c303e765e807c5"></a>
## game.escape.app.Turn
```dever
type game.escape.app.Turn
```
[打开源码](<flow/escape.dv#L15,1>)
<a id="flow-ceaf1f1b0cd7c5d3df26b5920c4686c85d1f7827a411762e7e7ccc23b1737f52"></a>
## game.escape.app.start
```dever
game.escape.app.start() (turn: Turn)
```
[打开源码](<flow/escape.dv#L20,1>)
```mermaid
flowchart TD
n0(["game.escape.app.start"])
click n0 href "flow/escape.dv#L20,1" "打开源码"
n1(["返回结果"])
n2["turn = Turn { stage = Locked, message = #34;你醒来时,发现自己在一间上锁的房间里。#34; }"]
click n2 href "flow/escape.dv#L21,10" "打开源码"
n0 --> n2
n2 --> n1
```
<a id="flow-8466c88245f19d3143112a145a76aa1cf0f8cc8565edd8dd976ae9f184ddaf4b"></a>
## game.escape.app.advance
```dever
game.escape.app.advance(action: Action, current: Turn) (acc: Turn, stop: Bool)
```
[打开源码](<flow/escape.dv#L24,1>)
```mermaid
flowchart TD
n0(["game.escape.app.advance"])
click n0 href "flow/escape.dv#L24,1" "打开源码"
n1(["返回结果"])
n2[["app.step(current.stage, action)"]]
click n2 href "flow/escape.dv#L25,9" "打开源码"
n3["acc = app.step(current.stage, action)"]
click n3 href "flow/escape.dv#L25,9" "打开源码"
n4{"acc.stage == Won"}
click n4 href "flow/escape.dv#L26,10" "打开源码"
n5["计算右侧"]
click n5 href "flow/escape.dv#L26,30" "打开源码"
n6["布尔结果"]
click n6 href "flow/escape.dv#L26,10" "打开源码"
n7["stop = acc.stage == Won or acc.stage == GaveUp"]
click n7 href "flow/escape.dv#L26,10" "打开源码"
n0 --> n2
n2 --> n3
n3 --> n4
n4 -->|"不成立"| n5
n4 -->|"成立,短路"| n6
n5 --> n6
n6 --> n7
n7 --> n1
```
- 子流程 [game.escape.app.step](<link.md#flow-ccc70f2ace361a370d7852e76d42bae9b531f95552ecbc55fb22282d9d15444d>)
<a id="flow-9dfc359f6c8ebdac6103848e001a4dc947aed529a98b275a5f9dfa777a3a01bc"></a>
## game.escape.app.play
```dever
loop game.escape.app.play(actions: List<Action>) (turn: Turn)
```
按顺序执行行动,胜利或退出后停止。没有行动时返回开场状态。
[打开源码](<loop/escape.dv#L1,1>)
```mermaid
flowchart TD
n0(["game.escape.app.play"])
click n0 href "loop/escape.dv#L1,1" "打开源码"
n1(["返回结果"])
n2[["app.start()"]]
click n2 href "loop/escape.dv#L3,23" "打开源码"
n3["初始化 current: app.start()"]
click n3 href "loop/escape.dv#L3,23" "打开源码"
n4{"全部行完成则停止,否则拉取下一元素"}
click n4 href "loop/escape.dv#L2,1" "打开源码"
n5["foldUntil(current = app.start(), app.advance(action, current))"]
click n5 href "loop/escape.dv#L3,3" "打开源码"
n6["下一输出行"]
n7{"本行是否已完成"}
click n7 href "loop/escape.dv#L3,3" "打开源码"
n8[["app.advance(action, current)"]]
click n8 href "loop/escape.dv#L3,36" "打开源码"
n9["采用新的累积状态"]
click n9 href "loop/escape.dv#L3,3" "打开源码"
n10{"stop 是否为 true"}
click n10 href "loop/escape.dv#L3,3" "打开源码"
n0 --> n2
n2 -->|"只求值一次"| n3
n3 -->|"来源只求值一次"| n4
n4 -->|"来源耗尽或全部完成"| n1
n4 --> n7
n7 -->|"已完成,跳过"| n6
n7 -->|"未完成"| n5
n5 --> n8
n8 -->|"更新成功"| n9
n9 -->|"随后判断停止"| n10
n10 -->|"是,标记本行完成"| n6
n10 -->|"否,本行继续累积"| n6
n6 -->|"继续"| n4
```
- 子流程 [game.escape.app.start](<link.md#flow-ceaf1f1b0cd7c5d3df26b5920c4686c85d1f7827a411762e7e7ccc23b1737f52>)
- 子流程 [game.escape.app.advance](<link.md#flow-8466c88245f19d3143112a145a76aa1cf0f8cc8565edd8dd976ae9f184ddaf4b>)
<a id="flow-ccc70f2ace361a370d7852e76d42bae9b531f95552ecbc55fb22282d9d15444d"></a>
## game.escape.app.step
```dever
rule game.escape.app.step(stage: Stage, action: Action) (turn: Turn)
```
根据当前状态和一个行动返回新状态与提示。Won/GaveUp 表示结束,不额外维护结束标志。查看、搜索、开门及退出的所有组合集中在规则表。
[打开源码](<rule/escape.dv#L1,1>)
```mermaid
flowchart TD
n0(["game.escape.app.step"])
click n0 href "rule/escape.dv#L1,1" "打开源码"
n1(["返回结果"])
n2{"按输入选择唯一规则行"}
click n2 href "rule/escape.dv#L1,1" "打开源码"
n3["stage: Locked 且 action: Look"]
click n3 href "rule/escape.dv#L3,3" "打开源码"
n4["turn = Turn { stage = Locked, message = #34;门锁着,桌上有一个盒子。#34; }"]
click n4 href "rule/escape.dv#L3,21" "打开源码"
n5["stage: Locked 且 action: Search"]
click n5 href "rule/escape.dv#L4,3" "打开源码"
n6["turn = Turn { stage = KeyFound, message = #34;你在盒子里找到了钥匙。#34; }"]
click n6 href "rule/escape.dv#L4,23" "打开源码"
n7["stage: Locked 且 action: Open"]
click n7 href "rule/escape.dv#L5,3" "打开源码"
n8["turn = Turn { stage = Locked, message = #34;门打不开,需要钥匙。#34; }"]
click n8 href "rule/escape.dv#L5,21" "打开源码"
n9["stage: KeyFound 且 action: Look"]
click n9 href "rule/escape.dv#L6,3" "打开源码"
n10["turn = Turn { stage = KeyFound, message = #34;你拿着钥匙,出口就在前面。#34; }"]
click n10 href "rule/escape.dv#L6,23" "打开源码"
n11["stage: KeyFound 且 action: Search"]
click n11 href "rule/escape.dv#L7,3" "打开源码"
n12["turn = Turn { stage = KeyFound, message = #34;盒子空了,钥匙在你手里。#34; }"]
click n12 href "rule/escape.dv#L7,25" "打开源码"
n13["stage: KeyFound 且 action: Open"]
click n13 href "rule/escape.dv#L8,3" "打开源码"
n14["turn = Turn { stage = Won, message = #34;门开了,你逃出了房间!#34; }"]
click n14 href "rule/escape.dv#L8,23" "打开源码"
n15["stage: Locked 且 action: Quit"]
click n15 href "rule/escape.dv#L9,3" "打开源码"
n16["turn = Turn { stage = GaveUp, message = #34;你结束了这次探索。#34; }"]
click n16 href "rule/escape.dv#L9,21" "打开源码"
n17["stage: KeyFound 且 action: Quit"]
click n17 href "rule/escape.dv#L10,3" "打开源码"
n18["turn = Turn { stage = GaveUp, message = #34;你结束了这次探索。#34; }"]
click n18 href "rule/escape.dv#L10,23" "打开源码"
n19["stage: Won"]
click n19 href "rule/escape.dv#L11,3" "打开源码"
n20["turn = Turn { stage = Won, message = #34;你已经逃出房间了。#34; }"]
click n20 href "rule/escape.dv#L11,15" "打开源码"
n21["stage: GaveUp"]
click n21 href "rule/escape.dv#L12,3" "打开源码"
n22["turn = Turn { stage = GaveUp, message = #34;这次探索已经结束。#34; }"]
click n22 href "rule/escape.dv#L12,18" "打开源码"
n0 --> n2
n2 -->|"匹配"| n3
n3 --> n4
n4 --> n1
n2 -->|"匹配"| n5
n5 --> n6
n6 --> n1
n2 -->|"匹配"| n7
n7 --> n8
n8 --> n1
n2 -->|"匹配"| n9
n9 --> n10
n10 --> n1
n2 -->|"匹配"| n11
n11 --> n12
n12 --> n1
n2 -->|"匹配"| n13
n13 --> n14
n14 --> n1
n2 -->|"匹配"| n15
n15 --> n16
n16 --> n1
n2 -->|"匹配"| n17
n17 --> n18
n18 --> n1
n2 -->|"匹配"| n19
n19 --> n20
n20 --> n1
n2 -->|"匹配"| n21
n21 --> n22
n22 --> n1
```
@@ -0,0 +1,4 @@
loop play(actions: List<Action>) (turn: Turn)
action in actions {
foldUntil(current = app.start(), app.advance(action, current))
}
@@ -0,0 +1,13 @@
rule step(stage: Stage, action: Action) (turn: Turn)
(stage, action) {
(Locked, Look) => Turn { stage = Locked, message = "门锁着,桌上有一个盒子。" }
(Locked, Search) => Turn { stage = KeyFound, message = "你在盒子里找到了钥匙。" }
(Locked, Open) => Turn { stage = Locked, message = "门打不开,需要钥匙。" }
(KeyFound, Look) => Turn { stage = KeyFound, message = "你拿着钥匙,出口就在前面。" }
(KeyFound, Search) => Turn { stage = KeyFound, message = "盒子空了,钥匙在你手里。" }
(KeyFound, Open) => Turn { stage = Won, message = "门开了,你逃出了房间!" }
(Locked, Quit) => Turn { stage = GaveUp, message = "你结束了这次探索。" }
(KeyFound, Quit) => Turn { stage = GaveUp, message = "你结束了这次探索。" }
(Won, -) => Turn { stage = Won, message = "你已经逃出房间了。" }
(GaveUp, -) => Turn { stage = GaveUp, message = "这次探索已经结束。" }
}
@@ -0,0 +1,65 @@
<!doctype html>
<html lang="zh-CN">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>逃出房间 · Dever</title>
<style>
:root { color-scheme: light dark; font-family: system-ui, sans-serif; }
body { max-width: 38rem; margin: 4rem auto; padding: 0 1.25rem; line-height: 1.7; }
h1 { font-size: 2rem; margin-bottom: .5rem; }
#story { min-height: 6rem; font-size: 1.15rem; }
fieldset { border: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .7rem; }
button { padding: .7rem 1.1rem; font: inherit; cursor: pointer; }
#status { min-height: 2rem; }
</style>
<main>
<p>DEVER · 文字游戏</p>
<h1>逃出房间</h1>
<p>看看周围,找到钥匙,再打开那扇门。</p>
<p id="story" aria-live="polite"></p>
<fieldset id="actions" disabled>
<button data-action="Look">查看房间</button>
<button data-action="Search">寻找钥匙</button>
<button data-action="Open">打开门</button>
<button data-action="Quit">结束探索</button>
</fieldset>
<p id="status" role="status"></p>
<button id="restart">重新开始</button>
</main>
<script type="module">
const story = document.querySelector('#story');
const actions = document.querySelector('#actions');
const status = document.querySelector('#status');
const restart = document.querySelector('#restart');
let stage;
async function play(operation, input) {
actions.disabled = true;
restart.disabled = true;
status.textContent = '正在进行…';
try {
const response = await fetch('/game/escape/web/game/' + operation, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(input),
});
const result = await response.json();
if (!response.ok) throw new Error(result.message);
stage = result.data.stage;
story.textContent = result.data.message;
const finished = stage === 'Won' || stage === 'GaveUp';
actions.disabled = finished;
status.textContent = finished ? '本次探索结束,可以重新开始。' : '选择下一步行动。';
} catch (error) {
status.textContent = '请求失败:' + error.message + '。请点击重新开始。';
} finally {
restart.disabled = false;
}
}
for (const button of actions.querySelectorAll('button')) {
button.addEventListener('click', () => play('step', { stage, action: button.dataset.action }));
}
restart.addEventListener('click', () => play('play', { actions: [] }));
await play('play', { actions: [] });
</script>
</html>