TEXT-BASED ADVENTURE

 

 

INTRO

 

One of your options is to create a text-based adventure game.  There are many different approached that can be used to create such a game.  The programmer can focus on character stats and skills or on a complex storyline.  Of course, the best games find a balance between those aspects as well as others such as fighting, quests, rewards systems and so on…

 

Your job is to create a fully functional text-based game.  You are highly encouraged to use object oriented programming to do this.

 

Below is an example game that was developed:

 

EXAMPLE

 

In this example, we will look at the steps used to create a simple text-based adventure game.

 

STEP 1 – A STARTING MAP

 

One important aspect for the game is to remain very organized.  Since my game will have the character move from location to location, a map helps keep things organized.  The map below shows all of the possible locations in the game and the lines show the possible pathways that can be followed.

 

 

STEP 2 – GAMEPLAY

 

We now need to figure out how we will move from location to location and solve quests.  I am opting to make the game a little easier by providing a description of the location with keywords that are capitalized.  The keywords are the possible input values that the user can use.

 

Below is my first location description.  The player's choices are DRINK, OLDHOUSE, BRIDGE and FARM.

 

You wake up with a sharp headache.  You are confused.  Uncertain of who or where you are.  You see a well nearby.  You consider taking a DRINK.  There is also an OLDHOUSE in the north.  To the south, you see a path that leads to a BRIDGE.  To west, there seems to be a FARM.  And to the east, a MINE.

 

STEP 3 – GAME STATE

 

It will be important to keep track different things such as items acquired, conversations that have taken place and locations that I have visited.  I will simply keep a variable for each of these and set it to true or false as required.  All of these variables will be stored as data fields inside a single class called GameState.

 

For example, at one point, I will need sword, I will need to get training permission and I will need to get the actual training for it.  All three of these are going to have their own variable as such:

 

   public boolean hasSword = false;

   public boolean canTrain = false;

   public boolean hasSwordTraining = false;

 

STEP 4 – GAME LOOP

 

The loop is quite simple.  Using the game's state, we display the appropriate location description.  Then, we wait for the user's response and use it to update the game state.

 

Here is pseudocode the main method in the main game class.

 

   Loop

   {

      Display description based on state

      Get user input and update state (end game if necessary)

   }

 

STEP 5 – START BUILDING

 

Now we simply start developing each possible location adding to the game's state possibilities as needed.  Of course, this can take hours and hours to do and each addition adds a lot of the game's complexity – so remain organized!

 

 

THE RESULT

 

Unfortunately, not the entire map was used as time was limited.  The part of the map that was incorporated is circled below:

 

 

THE CODE

 

The entire game is contained in three classes.  For this website, they are in text documents in order for easier sharing.  You need to copy and paste this content to corresponding classes in Eclipse.

 

   Game.java

   GameState.java

   Loc.java

 

ZIPPED PROJECT

 

Click here to get a zip file of the Eclipse project.  It is probably easier to use the files above instead.