[Clojure] A Room-Escape game, playing with telnet and pure-text commands - Part 3
来源:互联网 发布:有蛇精吐火的软件 编辑:程序博客网 时间:2024/05/21 10:58
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
- [Clojure] A Room-Escape game, playing with telnet and pure-text commands - Part 2
- [Clojure] A Room-Escape game, playing with telnet and pure-text commands - Part 4
- Harder Monsters and More Levels: How To Make A Simple iPhone Game with Cocos2D Part 3
- Enemies and Combat: How to Create a Tile Based Game with Cocos2D Part 3
- Playing with ptrace, Part II
- Playing with ptrace, Part I
- Playing with ptrace, Part I
- Playing with ptrace, Part II
- Playing with ptrace, Part II
- Playing with ptrace, Part I
- Playing with ptrace, Part II
- Playing with ptrace, Part II
- Playing with ptrace, Part I
- Playing with ptrace, Part II
- Playing with ptrace, Part I
- raywenderlich—Harder Monsters and More Levels: How To Make A Simple iPhone Game with Cocos2D Part 3
- UVa 450题记录
- Linux进程与多线程
- poj 3414 Pots (bfs+路径记录)
- 题目1043:Day of Week 题目7
- java中static的使用
- [Clojure] A Room-Escape game, playing with telnet and pure-text commands - Part 3
- nyoj71--独木舟上的旅行
- File Inclusion -medium
- 经典排序之快速排序
- 待解决问题
- iOS数据存储之--NSCoding
- git基础常用指令汇总
- Android Studio adb无法启动解决方案
- 【Java】【Oracle】Java操作Oracle 12c数据库基本步骤介绍——从零开始#1