Code Path:

https://github.com/bluesilence/Lisp/blob/master/clojure/projects/room-escape/src/room_escape/script.clj

Extract Story to TXT

In order to move the story from .clj into .txt, I leveraged Clojure's eval function. The steps are as follows:

1. Read the contents from the story's txt as string;

2. Eval each key-value pair of each room;

3. Sort the rooms by name.

This works, but is not good enough. Because there are functions defined in the story, as a story writer, you have to test your story as .clj, rather than .txt.

For example:

{:id 5
:category 2
:name "password-panel"
:description {:default-check (str "There are button 0~9 on the panel. The length of the password seems to be 4. Maybe you can " (enclose "press") " the buttons...")}
:state (atom "")
:action [{:name "press"
:description (str "Press button 0~9 on the " (enclose "password-panel"))
:usage "pr/pre/pres/press 0~9(1 digit at a time). Eg. pr 0"
:hint ["press"]
:function
#(let [player-id %1
button (parse-int %2 -1)]
(if (or (> button 9) (< button 0))
(display "Invalid button: " %2)
(let [state (:state (locate-by-id player-id 5))]
(swap! state (comp string/join reverse (partial concat %2) reverse))
(if (> (count @state) 4)
(swap! state subs 1 5))
(display "You pressed button " button)
(if (and (= @state "2048")
(not (visible? player-id 6)))
(do
(set-visible player-id 6)
(display (str "The bottom of the " (enclose "password-panel") " opened. A " (enclose "key") " fell down to the floor.")))))))}]}

The code above is the logic of determining whether the player has entered correct password when pressing the password-panel.

It requires the story writer to implement the complicated status transition.

Hints

From the first trial player's feedbacks, this game is not easy to play, because players may get stuck and don't know what's the next command that pushes the game forward. So I added this hint system, which bases on the definition
of each action and the player's last action. The player can decide which of the options to be the next step.

For example, when the player discovers the password-panel, then type "hint" command, the server will return a message telling the player to try "press", as shown in the code above.

The next chapter will give a brief introduction of the E2E process of this game.

[Clojure] A Room-Escape game, playing with telnet and pure-text commands - Part 3的更多相关文章

  1. [Clojure] A Room-Escape game, playing with telnet and pure-text commands - Part 1

    Code path: https://github.com/bluesilence/Lisp/tree/master/clojure/projects/room-escape As I have be ...

  2. 用Qemu模拟vexpress-a9 (七) --- 嵌入式设备上安装telnet服务

    转载: http://blog.csdn.net/liuqz2009/article/details/6921789 Telnet协议是登陆远程网 络主机最简单的方法之一,只是安全性非常低.对targ ...

  3. JavaScript escape() 函数

    JavaScript escape() 函数 JavaScript 全局对象 定义和用法 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法 escape(str ...

  4. (转)JavaScript escape() 函数(该方法不会对 ASCII 字母和数字进行编码,也不会对下面这些 ASCII 标点符号进行编码: * @ - _ + . / 。其他所有的字符都会被转义序列替换。)

    JavaScript escape() 函数 JavaScript 全局对象参考手册 定义和用法 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法 escape ...

  5. 用Telnet测试服务器的端口是否开通

      可以用telnet测试远程服务器的端口是否开通,格式如下: telnet <server name> <port number> 例如: Telnet tserv 3389 ...

  6. PHP7函数大全(4553个函数)

    转载来自: http://www.infocool.net/kb/PHP/201607/168683.html a 函数 说明 abs 绝对值 acos 反余弦 acosh 反双曲余弦 addcsla ...

  7. net programming guid

    Beej's Guide to Network Programming Using Internet Sockets Brian "Beej Jorgensen" Hallbeej ...

  8. 自学Zabbix3.5.3-监控项item-key

    1. 温习 Zabbix server是Zabbix软件的中心进程. Server执行polling和trapping来采集数据,评估是否触发触发器,发送报警给用户.它是Zabbix agent和pr ...

  9. iptables工作常用操作

    正确的设置iptables命令汇总 iptables -P INPUT ACCEPT iptables -F iptables -X iptables -Z iptables -I INPUT -p ...

随机推荐

  1. 早该知道的 7 个JavaScript 技巧[转]

    简洁写法 对象的简写在过去,如果你想创建一个对象,你需要这样: var car = new Object();  car.colour = 'red';  car.wheels = 4;  car.h ...

  2. HDU1969 Pie(二分搜索)

    题目大意是要办生日Party,有n个馅饼,有f个朋友.接下来是n个馅饼的半径.然后是分馅饼了, 注意咯自己也要,大家都要一样大,形状没什么要求,但都要是一整块的那种,也就是说不能从两个饼中 各割一小块 ...

  3. js中#代表什么

    js中#代表什么 一.总结 1.#号:代表id选择器  2. $('#div1'). : 常用用法,前面也有$符号 二."#"在js中代表什么 js里我不曾看到用到‘#’的代码端, ...

  4. oracle 多行转多列查询

     oracle 多行转多列查询  ---create table Fruit(id int,name varchar(20), Q1 int, Q2 int, Q3 int, Q4 int);inse ...

  5. 添加asp.net mvc到现有的asp.net web form 应用程序

    前言 asp.net mvc的前一版本为asp.net web Form(Asp.net mvc之前称为asp.net),其第一个版本与2002年年初发布.asp.net web form 属于.ne ...

  6. LED恒流设计

  7. jmeter--基本组件介绍

    一.JMeter 介绍 Apache JMeter是100%纯Java桌面应用程序,被设计为用于测试客户端/服务端结构的软件(例如web应用程序).它可以用来测试静态和动态资源的性能,例如:静态文件, ...

  8. JNI之——Can't load IA 32-bit .dll on a AMD 64-bit platform错误的解决

    转载自:http://blog.csdn.net/l1028386804/article/details/46605003 在JNI开发中,Java程序需要调用操作系统动态链接库时,报错信息:Can' ...

  9. 视频编码器评測系统:VideoCodecRank

    视频编码器领域一直有个比較复杂的问题:mpeg2.divx.xvid.mpeg4.vp8.vp9.x264.openh264.x265等等这一系列编码器究竟哪个好?而对于同一种视频编码器,又包括了各种 ...

  10. angular4开发过程中遇到的问题和知识点记录

    1. angular2中的属性有什么区别,为什么会报错呢? 元素上有两种属性:property和attribute,attribute是通过getAttribute()和setAttribute()方 ...