[Clojure] A Room-Escape game, playing with telnet and pure-text commands - Part 2

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 room, shown in the room-selection menu

2) description: the description of this room, shown in the room-selection menu

3) starting-message: the starting message when player begins to play this room

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


2. Room

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


3. Spot

A spot is a special part of the room 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 are the most interesting ones. They are the minimal unit of an object, and have some special properties:

1) pickable: whether the item can be picked by the player;

2) description: message about this item when checked from far away or nearby;

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

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


5. Visibility

Note that not all objects are visible from the beginning. The player has to discover within the room to find more objects.

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


6. Player's Context

Because this is 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:

 {:player-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 room 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 did 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 story 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 be extracted to the util.clj due to dependent "use" issue.

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


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




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值