I wrote a parser game in Java from scratch

The game is (very creatively) named “Escape”, and is quite short — perhaps fifteen minutes long. It’s not a very interesting game — more of a proof of concept of the java framework that I wrote than something meant to tell a good story — but it was a fun project.

The bulk of it was written in only a few weeks, so there are some interesting quirks and inefficiencies left in the code and finished game that I would have worked out if I had more time. (Aside from doing some last-minute playtesting yesterday to catch a couple unimplemented synonyms and objects before sharing it here, I haven’t changed it at all since it was originally finished last June.)

Features include: a map that updates as you go through the game! Lockable, openable doors! Recipes with ingredients and end products! Dark rooms and light sources! Machines that require other objects as fuel!

I’ve tried to make the gameplay less frustrating where I could (like by implementing synonyms for objects), but the parser is very simple — it only accepts commands of one or two words. Some commands are non-standard due to that limitation. I highly recommend reading the help text. There are also no implicit actions, so you have to type everything explicitly (e.g. opening something doesn’t automatically unlock it or look in it afterward).

Escape 1.1.zip (28.9 KB)

To play the game:

  1. Extract the files somewhere
  2. Navigate into the extracted folder in a terminal window using cd [folder/path/Escape.1.1]
  3. Run the command java World
    (If the command doesn’t work you’ll need to install java, which you can look up how to do for your operating system)

And here is the source code for anybody interested: Escape Source 1.1.zip (23.5 KB)

I’d be happy to hear what you all think. I’m sure there are plenty of things I could have done differently. : )

7 Likes

Hmm. need to update java. Might have time later.

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: World has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

I would strongly advise against downloading this file.
My Spidey-Cybersecurity senses are screaming “NO!”
I may be overly paranoid, but this is a new, hidden profile from a user with no other posts on this forum.

Best to err on the side of caution.

I have the source code if you want to look through it. It shouldn’t do anything bad. I’m not sure how to prove that the file is alright otherwise.

It’s true that I’m new. I have an old account on here from a few years ago but haven’t used it much, so it might not prove anything.

And I usually hide my public profile on websites, just out of a sense of privacy, but I didn’t realize it hid it for logged in users. I’m not very familiar with discourse. I thought the option only hid the profile for logged out users and maybe the last-active time. I’ve unhidden my profile so you can see my posts now : )

3 Likes

Apologies then. I am overly cautious when it comes to this kind of stuff.

Welcome back!

No worries, it definitely did make my account look suspicious. I’m used to forums having more subtle privacy controls than that. : )

Anybody is welcome to look through the source and compile it directly from that if they’re still worried about it and don’t trust my compiled version.

3 Likes

OK, the answer to my problems was: javac *.java Also, i added “get” which was missing.

The game plays quite well. A few problems with guessing the word. For example put coin in jukebox was pay jukebox and put battery in flashlight was fill flashlight. But the help, helped.

Some ideas for the design;

This appears to be a “verb priority” design as opposed to “object priority”. Ie, you consult the verbs with the objects rather than the objects with the verbs.

Verb priority has an interesting direction with rich world models. I can see various story specific code in the verbs. Really these should be factored out. In a verb priority design, you make a rich data model to describe the state of the world. The verbs then operate on that model. This has the advantage of having a system of operations that work automatically without coding for a new game. IN general you try to reflect all game state into the world property dataset.

Each new game is then:

  1. a new database
  2. story behaviour.

There is a need to “hook” story specific behaviour into the standard verbs.
For example.

eat cake

Will have a standard system operation that tests “edibility”. The database can include additional properties for taste and poisons. However, a cake with magic powers isn’t part of the system, it’s the story. So, eat cake needs a hook.

There are various ways to add hooks, mostly depending on implementation. Some languages make this easy, but in any case, it’s always possible.

best of luck.

3 Likes

Random “code from the internet” security 101:

You can’t tell if a binary did in fact come from a given set of source files.

A safer alternative is to have multiple people look at the source and compile them independently and compare. If an exact match with the binary can’t be made (common due to a plethora of reasons), then only binaries compiled by trusted people should be trusted, i.e. the binary is only as trustworthy as the person who compiled it. All of this assumes the source was examined closely by trusted people.

None of this is meant to impugn the original poster in any way, it’s just the reality of code.

2 Likes

I’m happy to remove the binary from my post entirely and amend my instructions to include the compilation step if people feel that would be a better alternative (assuming that somebody does inspect the source code and approves, of course).

You could also have done put into jukebox or insert into jukebox, but I left those out of the help. Technically my initial disclaimer was inaccurate, as it’s not really a two-word parser, but rather a verb-noun parser where the noun must only be one word. Attempting a more complex parser was too difficult for me to accomplish in the amount of time I had to write this, although it’s probably worth attempting at some point.

Yes, this is one of the “interesting quirks” I mentioned — that the code is an unfortunate mixture of bits that are pretending to be a framework to build games on, and bits that are pretending to be the game itself.

Thank you for the feedback! I definitely want to revisit this project at some point and try to make it more robost — maybe to the point where I can make a second game on it.

2 Likes