[Clojure] A Room-Escape game, playing with telnet and pure-text commands - Part 2
来源:互联网 发布:mac 您没有必要的权限 编辑:程序博客网 时间:2024/05/21 15:48
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.
- [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 1
- [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 4
- How To Create A Breakout Game with Box2D and Cocos2D Tutorial: Part 2/2
- Collisions and Collectables: How To Make a Tile Based Game with Cocos2D Part 2
- How To Create A Breakout Game with Box2D and Cocos2D Tutorial: Part 1/2
- 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
- Initialization error SQL*Net not properly installed
- android ListView异步加载图片(双缓存)
- UVA11294-Wedding(2-SAT)
- Linux下cat的一些特殊用法小结
- php发送post请求
- [Clojure] A Room-Escape game, playing with telnet and pure-text commands - Part 2
- 一串首尾相连的珠子(m 个),有N 种颜色(N<=10),设计一个算法,取出其中一段,要求包含所有N 中颜色,并使长度最短。并分析时间复杂度与空间复杂度。
- opencv视频学习第三课(显示图像)笔记整理
- 裁员风暴席卷全球IT巨头 今年已至少7万人被裁
- datagrid进阶——subGrid讲解
- $().empty()和$().remove()
- ORA-00900: invalid SQL statement
- Cross Site Request Forgery (CSRF)--medium
- CCNP路由实验之十五 NAT(网络地址转换)