每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,欢迎关注开源日报。交流QQ群:202790710;微博:https://weibo.com/openingsource;电报群 https://t.me/OpeningSourceOrg


今日推荐开源项目:《手绘图形库 Rough.js》GitHub链接

推荐理由:这个JavaScript库可以让你画出手绘画风的图形,它也内置了诸如线段和椭圆这些可能常用到的图形,或者你也可以自己使用SVG路径去画自己想要的图形。如果你想要改变页面的画风,使用这个库将是不错的选择,目前已经有一些项目使用了这个库去改变它们的画风。

手绘画风版贪吃蛇:https://www.aria.ai/snake.html


今日推荐英文原文:《How to Create your own Text Adventure》作者:Julianna Stevenson

原文链接:https://medium.com/@julianna.h.stevenson/how-to-create-your-own-text-adventure-12df36411b7f

推荐理由:这篇文章介绍了如何使用Inform来制造一个文字游戏。制作一个文字游戏并不算难,它提供了很多可以自定义的地方,让你可以重温小时候写在记事本上文字游戏的感觉。

How to Create your own Text Adventure

Unlike most people my age, I didn’t grow up playing video games; I grew up playing text adventures, or interactive fiction.

After exploring the dungeons of Zork, all 12 year old me wanted to do was to learn how to create my own game. Nine years later, I’ve finally accomplished that goal!

Text adventures are a fun, creative way to tell interactive stories, and they’re easier to make than you think!

Step 1: Download Inform

Inform is a programming language made specifically for creating text adventures.

It makes it easy for anyone to create their own, whether you know how to program or not. Unlike other programming languages, it’s mostly made of existing English words and grammar!

Download the correct version of the software onto your computer!

Step 2: Open Inform and create a new project

When you open Inform, you’ll see a welcome screen, like below. Click “Project” under “Create New” to start your text adventure. Give it a great name!

Inform Welcome Menu

Step 3: Create a room

The bulk of writing text adventures in Inform relies on three ideas: objects, descriptions, and relationships.

Every room, item, and person that is in your text adventure is defined as an object in the code. You make these objects come to life by providing descriptions of them and having them form relationships through actions.

Inform will give you a little bit of code to start out with, including the definition of your first room. It has defined “Example Location” as a room using this line of code:

Example Location is a room.

However, “Example Location” is a really boring name for a room, so instead I’m going to make it my bedroom.

Julianna's Bedroom is a room.

Step 4: Run your code

You might have guessed this already, but all you need to do to run your code is to press the big button in the top left corner that says go!

Go button in Inform

After pressing run, your code will compile and run. It should look something like this:

Running game

Since Inform was made for creating text adventures, it already has a lot of the classic text adventure commands built in! Check out this site for some ideas of commands to try out.

When you type in a command and press enter, the software will generate a response based on your code.

You, the player, are an object in the game. Since you’re the only thing in the bedroom, all you can successfully do right now is interact with yourself (try “examine me,” “kiss me,” and “rub me” ?).

Step 5: Add a room description

Being by yourself in an empty room isn’t super fun, so the next step is to create your setting. Go back to your code and add a description to your room. This is how the room will be described to the player.

For example, here is how I would define the description of my room:

Julianna's Bedroom is a room. The description is "The white walls of the room are matched by the color of the furniture. A rack of shoes sits neatly in one corner and the dresser and bedside table are clear of dust.".

The description can be as brief or long as you like.

If you run your code again, you can see the description of your room!

Step 6: Add an object

Now the player can see things in the room, but they still can’t interact with anything!

So, we’re going to add an object that the player can interact with. By default, players can pick up and drop any object that you put into the room.

Since this is my bedroom and I like to read, I’m going to put a book in the middle of my bed. To create an object, you just need to mention what it’s called and what room it’s in. You can also add a blurb about the object that will be included in the room’s description.

So, now my code reads

Julianna's Bedroom is a room. The description is "The white walls of the room are matched by the color of the furniture. A rack of shoes sits neatly in one corner and the dresser and bedside table are clear of dust.".
A book is in Julianna's Bedroom. "There is a book lying in the center of the bed."

Instead of using the name of the specific room, you can also just use “here” to refer to the most recently defined room.

Try running your code again. Now, you can pick up and drop your object!

Step 7: Add another room

Some text adventures will take place in one room, but most have multiple rooms for players to move through and explore! You can create another room the same way we created the first one — defining it and adding a description.

Since my first room is a bedroom, I’m going to add a living room. To allow the player to move from one room to another, you have to define how the two rooms are located in relation to one another using cardinal directions.

The Living Room is a room. The description is "This is a small room with a couch in the middle. On one wall there is a bookshelf.".
The Living Room is east of Julianna's Bedroom.

If I run my code and use the command “east” while I’m in the bedroom, I will move into the living room and if I use “west” while I’m in the living room, I’ll move back to the bedroom.

Try it out for yourself!

Step 8: Make a container

Since I have a book and a bookshelf, I want to be able to put my book onto the bookshelf. We can make this happen by creating a bookshelf object that is a container.

A container is a special type of object that you can put other objects into.

We can turn an object into a container using the phrase “is a container.”

A bookshelf is a container in the Living Room.

This line of code creates a bookshelf object in the living room and allows for things to be put inside of it.

To try it out, run the code and enter “pick up book” while you’re in the bedroom. Then, move to the living room and use the command “put book in bookshelf” to put the book on the bookshelf.

Step 9: Make an end state

No game is complete without and ending.

To create an ending, we’re going to use a conditional statement to check if the book is in the bookshelf. If it is, we’ll end the game.

We will want to check this condition every turn. This can be done with the following line of code:

Every turn: if the book is in the bookshelf, end the story.

Once you have an end condition, you can run and play the whole game! By default, after the game ends, the player will have the options to restart, restore a saved game, quit, or undo.

Step 10: Keep adding on!

This is just the start of what you can accomplish with Inform! You can create a whole text adventure with just the ideas from the steps above or you can dive deeper into what you can do with Inform!

Check out Inform’s book for inspiration and more examples or the Interactive Fiction Database for lots of text adventures that you can play!

Happy adventuring! ?

Complete Code:

"Demo_Project" by Julianna Stevenson
Julianna's Bedroom is a room. The description is "The white walls of the room are matched by the color of the furniture. A rack of shoes sits neatly in one corner and the dresser and bedside table are clear of dust.".
A book is in Julianna's Bedroom. "There is a book lying in the center of the bed."
The Living Room is a room. The description is "This is a small room with a couch in the middle. On one wall there is a bookshelf.".
The Living Room is east of Julianna's Bedroom.
A bookshelf is a container in the Living Room.
Every turn: if the book is in the bookshelf, end the story.

每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,欢迎关注开源日报。交流QQ群:202790710;微博:https://weibo.com/openingsource;电报群 https://t.me/OpeningSourceOrg