[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 ...
随机推荐
- 前端面试题(计算机网络/http/https)
(前端面试题大全,持续更新) 输入url的一系列过程 http缓存(缓存生效的情况),拓展下 get与post的异同,POST一般可以发送什么类型的文件 jsonp有什么不好的地方 http请求头(h ...
- Thinkphp5创建控制器
今天我们就来创建一个控制器: <?php namespace app\index\controller; use think\Controller; class Test extends Con ...
- GO语言学习(十四)Go 语言数组
Go 语言数组 Go 语言提供了数组类型的数据结构. 数组是具有相同唯一类型的一组已编号且长度固定的数据项序列,这种类型可以是任意的原始类型例如整形.字符串或者自定义类型. 相对于去声明number0 ...
- maven 详细描述
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- LeetCode Algorithm 05_Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- Swiper+ ejs模板引擎+ iScroll插件知识总结
一. Swiper swiper是一个应用于移动端的动画插件,原理类似于轮播图 官网 http://www.swiper.com.cn/# html结构 <div class="swi ...
- C# is 和 as的用法
try { if (sender is Button) { Button dd ...
- 【MemSQL Start[c]UP 3.0 - Round 1 C】 Pie Rules
[链接]h在这里写链接 [题意] 在这里写题意 [题解] dp[i][0] 第i个位置,bob没有决策权 dp[i][1] 第i个位置,bob有决策权 dp[n][0] = 0 ...
- Spring拦截器和Servlet过滤器区别
http://blog.csdn.net/chenleixing/article/details/44573495
- CSS3实现的立体button
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...