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. crm翻译导航栏

    在crm里面怎样翻译导航栏? 过程例如以下: 1 先新建一个解决方式.把网站地图加进去 2: 然后把这个解决方式到出来来,解压文件: 3:编辑第二个文件: watermark/2/text/aHR0c ...

  2. amazeui学习笔记--css(基本样式3)--文字排版Typography

    amazeui学习笔记--css(基本样式3)--文字排版Typography 一.总结 1.字体:amaze默认非 衬线字体(sans-serif) 2.引用块blockquote和定义列表:引用块 ...

  3. 观察者模式 VS 责任链模式

    为什么要把观察者模式和责任链模式放在一起对比呢?这两个模式没有太多的相似性呀,真没有嘛?有相似性,我们在观察者模式中也提到了触发链(也叫做观察者链)的问题,一个具体的角色既可以是观察者,也可以是被观察 ...

  4. CSS笔记 - fgm练习 2-10 - 提示框效果 (清除子元素浮动高度塌陷的影响)

    CSS清除浮动方法参考: https://blog.csdn.net/promiseCao/article/details/52771856 <style> *{ margin: 0; p ...

  5. echarts同一页面四个图表切换的js数据交互

    需求:点击tab页,切换四个不同的图表,ajax向后台请求数据,展示在四个不同的图表中. 其余的就不多说,直接上js代码了 $(function() { $("#heart").o ...

  6. SpringBoot 使用yml配置 mybatis+pagehelper+druid+freemarker实例

    SpringBoot 使用yml配置 mybatis+pagehelper+druid+freemarker实例 这是一个简单的SpringBoot整合实例 这里是项目的结构目录 首先是pom.xml ...

  7. [D3] Create DOM Elements with D3 v4

    Change is good, but creating from scratch is even better. This lesson shows you how to create DOM el ...

  8. [React Intl] Get locale value from intl injector

    Get 'injectIntl' from  'react-intl', it is a high order componet. We need to wrap our component into ...

  9. 每日技术总结:flex,选项卡,classList,

    1.Flex布局子元素垂直居中 给父元素添加以下样式: .parent { display: flex; align-items: center; } 2.js面向对象的选项卡 见另一篇文章 js面向 ...

  10. 基于element ui的图片预览插件

    写插件很简单,满足两个条件即可,一.基本的逻辑思路,二.熟悉插件语法要求.本次Vue插件也比较简单,点击“查看图片”用轮播的方式限制用户上传的图片,如图: 项目采用的是vue-element-admi ...