[Clojure] A Room-Escape game, playing with telnet and pure-text commands - Part 3
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的更多相关文章
- [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 ...
- 用Qemu模拟vexpress-a9 (七) --- 嵌入式设备上安装telnet服务
转载: http://blog.csdn.net/liuqz2009/article/details/6921789 Telnet协议是登陆远程网 络主机最简单的方法之一,只是安全性非常低.对targ ...
- JavaScript escape() 函数
JavaScript escape() 函数 JavaScript 全局对象 定义和用法 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法 escape(str ...
- (转)JavaScript escape() 函数(该方法不会对 ASCII 字母和数字进行编码,也不会对下面这些 ASCII 标点符号进行编码: * @ - _ + . / 。其他所有的字符都会被转义序列替换。)
JavaScript escape() 函数 JavaScript 全局对象参考手册 定义和用法 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法 escape ...
- 用Telnet测试服务器的端口是否开通
可以用telnet测试远程服务器的端口是否开通,格式如下: telnet <server name> <port number> 例如: Telnet tserv 3389 ...
- PHP7函数大全(4553个函数)
转载来自: http://www.infocool.net/kb/PHP/201607/168683.html a 函数 说明 abs 绝对值 acos 反余弦 acosh 反双曲余弦 addcsla ...
- net programming guid
Beej's Guide to Network Programming Using Internet Sockets Brian "Beej Jorgensen" Hallbeej ...
- 自学Zabbix3.5.3-监控项item-key
1. 温习 Zabbix server是Zabbix软件的中心进程. Server执行polling和trapping来采集数据,评估是否触发触发器,发送报警给用户.它是Zabbix agent和pr ...
- iptables工作常用操作
正确的设置iptables命令汇总 iptables -P INPUT ACCEPT iptables -F iptables -X iptables -Z iptables -I INPUT -p ...
随机推荐
- 前端面试题(VUE)
(前端面试题大全,持续更新) vue:v-model 双向绑定的原理 依赖收集 虚拟DOM的作用 vue@3.0中的preset配置? 父组件A和其子组件B/子组件C,B/C进行通信的方式(怎么通信) ...
- python3对序列求绝对值
http://www.cnblogs.com/itdyb/p/5731804.html 一开始我是这样写的,据说这样写python2是可以的: myList = [-1,2,-3,4,-5,6 ...
- leetCode 103.Binary Tree Zigzag Level Order Traversal (二叉树Z字形水平序) 解题思路和方法
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...
- JNI各种环境下编译方法及初期出错分析
转自 https://www.cnblogs.com/xyang0917/p/4172490.html 第五步.将C/C++代码编译成本地动态库文件 动态库文件名命名规则:lib+动态库文件名+后缀( ...
- 硬件——STM32 , SN74HC573锁存器
74HC573是一款高速CMOS器件: 上图中:输出使能为:OE 锁存使能为:LE 典型电路: 上图中:PWR-AL-0,PWR-AL-1,PWR-AL-2:是单片机输出的高低电平给573 对应的 ...
- mybatis+springmvc缓存设置
开始接触mybatis,本以为缓存设置好麻烦,在网上找了好多相关的资料,说得也都好复杂,经过自己亲自实践,其实很简单的. 首先引入需要的jar包,参照pom.xml配置: <!-- 缓存设置 s ...
- POJ 2546 Circular Area 几何
http://poj.org/problem?id=2546 晚上发现鼠标快不行了了!!!鼠标你肿么了,肿么突然就按键不灵了,哭,谁送我一只呀,奖励我舍友一只.哈哈.开玩笑滴~ 舍友大怒说" ...
- ATL入门
服务端代码----------------------------------------------------------------------------------------------- ...
- irms模拟数据生成及数据分析 分类: H_HISTORY 2015-03-06 14:17 212人阅读 评论(0) 收藏
一.数据准备 1.每天生成随机一个文本,每小时向文本中追加2次数据,每次10万条 随机数据生成: 2,32 * * * * bash /mnt/jediael/irms/signalGenerat ...
- css3-10 如何控制元素的显示和隐藏(display和visibility的区别是什么)
css3-10 如何控制元素的显示和隐藏(display和visibility的区别是什么) 一.总结 一句话总结:使用的时候直接在元素的样式中设置display和visibility属性即可.推荐使 ...