Coding Challenge for CE01: Implement Your Own Text Adventure

A Brief Intro To Text Adventures In General

A text adventure is a type of game dating back to the pre-graphical-UI times. It was a hugely popular genre in the 1980ies and 90ties, and some classical games from that time can still be played using browser-based emulators.

The idea is simple: The only interface to the game is your console. You find yourself in some unknown location, have to explore it, survive various threats, and solve a quest. Usually, you move in a grid: You can only go North, East, West, and South. During your quest, you need to pick up items and use them to open doors or to fight threats.

The only instructions you get are short sentences printed out on console. You type your input as command shortcuts into the console, e.g. that you want to go North, or that you want to pick up something you have found. As a reaction, the system tells you what you find as a result of your command.

A typical sequence in a classical text adventure (immediately after starting the game) could look like this:

You wake up from a long, deep sleep and find  yourself on a beach.
> go south
You can't go that way, there is the ocean.
> go west
You are still on the beach.
> go west
You are still on the beach.
> go west
In the sand you see a box.
> open box
It's locked.
> take box
Taken.
> go north
You are about to enter a dense jungle. It smells funny.
> go north
A mighty ork appears in some distance. You smell his scent of rotten meat.
> go north
The ork catches you and eats you.
GAME OVER

Your Task

To make it a bit simpler, your text adventure needs to have exactly seven commands:

Command Meaning
n go North
e go East
s go South
w go West
t <object> take <object>
d <object> drop <object>
u <object> use <object>

Anything else in the game you can design as you like. A player should be able to hold an arbitrary amount of objects. The game should have at least one successful ending (and any number of fails ...). You should tell the player in the first greeting sentences what the goal of his/her quest is.

Hint For Implementation

To make the task a bit simpler, here is some example code that you can adopt (if you want! you are not obliged to!) for the loop to read the input from console. (This part requires some familiarity with the Java input classes, and might be a big obstacle.)

package study.coco.ce01.coding_challenge;

import java.util.Scanner;

public class InputLoop {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // endless loop until user kills the program
        while (true) {
            System.out.println("Hello! Please enter a letter and some other word ... ");

            String line = scanner.nextLine();
            String[] parts = line.split("[ \t]+");
            if ((parts.length < 1 || parts.length > 2) || (parts[0].length() != 1)) {
                System.out.println ("*** Invalid input! Please try again. ***");
            }
            else {
                String outMsg = "You wrote: '" + parts[0] + "'";
                if (parts.length > 1) {
                    outMsg += "' and then the word '" + parts[1] + "'";
                }
                System.out.println(outMsg);
            }
        }
    }
}

results matching ""

    No results matching ""