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.

最新文章

  1. IOS开发基础知识--碎片24
  2. 用JQuery的Ajax对表进行处理的一些小笔记
  3. FTP+SFTP工具类封装-springmore让开发更简单
  4. 归并排序(merge sort)
  5. SSH+Oracle10G抛Disabling contextual LOB creation as createClob() m
  6. HttpClient(4.3.5) - HttpClient Proxy Configuration
  7. mysqli扩展库操作mysql数据库
  8. “typedef int (init_fnc_t) (void);“的含义
  9. Spring的监听器ContextLoaderListener
  10. Factory and AbstractFactory ——抽象与具体的分离
  11. HDU 1828 POJ 1177 Picture
  12. 【错误】undefined reference to `boost::....的解决
  13. 【NO.6】HTTP请求-配置-POST请求-GET请求
  14. 使用定时器限制点击按钮发送短信(附源码)--JavaScript小案例
  15. LPC 语言基础
  16. [Swift]LeetCode541. 反转字符串 II | Reverse String II
  17. sql 中 联表on 和where
  18. orcFile split和读数据原理总结(hive0.13)
  19. BZOJ.1875.[SDOI2009]HH去散步(DP 矩阵乘法)
  20. Alpha阶段博客链接

热门文章

  1. solr/lucence和关系数据库的混合使用
  2. HDOJ 5409 CRB and Graph 无向图缩块
  3. php课程 11-37 类和对象的关系是什么
  4. vue使用(三)
  5. jQuery笔记---选择器(二)
  6. windows版 nginx配置反向代理实例教程 跳转tomcat和php网站
  7. 小米笔记本(13.3 I7) ubuntu14.04下网卡驱动安装
  8. 那些移动端web踩过的坑
  9. [CSS] Reduce Ambiguity in Class Names using a Naming Convention
  10. OpenStack 之 Nova Compute 的代码结构图