[Clojure] A Room-escape game, playing with Telnet and Pure-text Commands-part 2

Source: Internet
Author: User

Code Path:

https://github.com/bluesilence/Lisp/blob/master/clojure/projects/room-escape/.


Data Model

Based on the draft, the data models can be built of 4 major units:

1. Story

It ' s the base unit of a Room-escape story. The Storyhas following members:

1) name:the name of this guest, shown in the Room-selection menu

2) description:the Description of this guest, shown in the Room-selection menu

3) starting-message:the starting message when player begins to play the This guest

4) Objects:the collection of the objects within the story, including rooms, spots and items. They all belong to the same logical type:object. Rooms, spots and items is differentiated by the [category] field:room-0, Spot-1, Item-2.


2. The

There might is more than 1-within a story. For the demo one, there are only 1. It holds a collection of spots within the class.


3. Spot

A spot is a special part of the which is worth examining. It holds a collection of items related to the spot. The Description field contains message about this spot when checked from far away or nearby.


4. Item

Items is the most interesting ones. They is the minimal unit of an object, and has some special properties:

1) Pickable:whether the item can picked by the player;

2) Description:message about the if checked from far away or nearby;

3) on-use:the function called when the player uses the item

4) Action:custom actions that is only belong to the item. Player can get the list of custom actions by typing to the game.


5. Visibility

Note that the objects is visible from the beginning. The player has to discover within the "the" to find more objects.

To implement this visibility feature, a "visible" collection was added into the player ' s context.


6. Player ' s Context

Because This was a multi-threading game which allows multiple players to play at the same time, we need an isolated context To hold the status of each players. Here's the structure of a player ' s context:

{:p layer-objects (: Objects Starting-room)            : Starting-room starting-room-index           : Current-status (Atom {: room-1                             : spot-1                             : Items #{})           : Visible (Atom #{}):           win (Atom false):           continue (Atom true)           : Last-action (Atom [])}

1) Player-objects:all the objects related to the game of the Player;

2) starting-room:the ID of the "the" player starts with;

3) Current-status:location and possessed items of the player;

4) Visible:the Collection of Visible objects in this game based on how the player played the game;

5) Win:indicate If the player has won the game;

6) Continue:indicate If the player wants to Continue the game;

7) Last-action:stores The last Action was by the player. It's used for helping the player with suggesting new actions based on the history.


Utilities

How is the game context generated? To bind the stories with the player, and throw magic on the target object The player is interacting with, I wrote a utility class to tackle with the logic:

Https://github.com/bluesilence/Lisp/blob/master/clojure/projects/room-escape/src/room_escape/util.clj


Common

The common class basically deals with the UI part, and some utility functions that cannot being extracted to the UTIL.CLJ due To dependent the "use" issue.

Https://github.com/bluesilence/Lisp/blob/master/clojure/projects/room-escape/src/room_escape/common.clj


Next chapter would narrate on what to generalize the story's script into a txt, and load it at runtime.




[Clojure] A Room-escape game, playing with Telnet and Pure-text Commands-part 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.