Code Path:
Https://github.com/bluesilence/Lisp/blob/master/clojure/projects/room-escape/src/room_escape/script.clj
Extract Stories to TXT
In order to move the stories from. Clj into. txt, I leveraged Clojure ' s eval function. The steps is as follows:
1. Read the contents from the story ' s txt as string;
2. Eval each key-value pair of each hostel;
3. Sort the rooms by name.
This works, but isn't good enough. Because There is functions defined in the stories, as a story writer, you had to test your story as. CLJ, rather than. txt .
For example:
{: id 5:category 2:name ' password-panel ':d escription {:d efault-check (str "There is 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" :d escription (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 (: Locate-by-id Player-id 5)] (swap! State (Comp String/join Reverse (PA rtial 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 had entered correct password when pressing the Password-pane L.
It requires the story writer to implement the complicated status transition.
Hints
From the first trial player's feedbacks, this game isn't easy to play, because players could 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 and then type "hint" command, the server would return a message tell ing the player to try "press", as shown in the code above.
The next chapter would 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