Assignments Office Hours Hall of Fame Notes
Assignments Office Hours Hall of Fame Notes

Amazing Adventures

Assigned: 2019-09-12
Due Date: 2019-09-17 by 11:59PM U.S. Central Time

D*** it! So let's recap: there are four directions that I can move in and none of them work. What the f*** am I supposed to do?

— SydLexia, reviewing Mystery House
And you'd be all like, "get ye flask", and it'd say "You can't get ye flask", and you'd just have to sit there and imagine why on Earth you can't get ye flask! Because the game's certainly not going to tell you.

— Strong Bad, Homestar Runner

Sportsbridge Analytica went bankrupt. Your boss's investors weren't interested in your analysis; apparently, they wanted information about a football game, and your boss (ever the worldwide traveler) interpreted that to mean soccer!

Luckily, you've found a much better job at Fiction Interactive, an indie computer game company. They specialize in games that can run on limited hardware, games that anyone can play — even if they don't have a graphical display!

When you arrived for your first day on the job, your coworkers showed you some demo projects they were working on. All were really fun to play, but to your utter shock, they hardcoded the rooms and room descriptions with the rest of the game! That just won't do.

Having tackled the art of JSON, you're ready to roll up your sleeves and show these people how to make a dynamic, JSON-based text adventure game engine! Good luck to you!

Goals

Assignment Spec

Getting Started

Get your copy of the assignment here: https://classroom.github.com/a/qy0_Sgwo

Make sure IntelliJ recognizes the project as a Maven project. GSON and JUnit are already listed as dependencies in the pom.xml file.

The JSON describing the game world can be found here: https://courses.grainger.illinois.edu/cs126/fa2019/assignments/siebel.json

As in the previous assignment, you should avoid copy-pasting the entire JSON file into your code. You may hand-write small snippets of JSON for testing purposes and store them in your tests, or write your own JSON files and load them into your tests with the provided helper method.

Part 1: Managing the JSON

Once again, you'll be using GSON to deserialize our JSON into objects representing the game world. This time, however, we're going to require that the JSON is downloaded from the Internet at runtime when the game is started, and that the user can specify a different URL on the command line so that they can play a different JSON adventure if they wish. The JSON should not be read in from a file when the game starts, though we will provide you with the same file-reading helper method as last assignment should you wish to use it for your tests.

JSON Schema

Your project should accept the description of the game world using the following schema:

Direction := {
	directionName       : String
	room                : String 		// Name of the room this direction points to
}

Room := {
	name                : String
	description         : String
	directions          : Direction[]
}

Layout := {
	startingRoom        : String 		// The name of the start room for the game
	endingRoom          : String		// The name of the end room for the game
	rooms               : Room[]
}

Part 2: Implementing the Game Engine

Output

Starting with the startingRoom, your game should display a message describing the player's current environment. This should include three parts, with a newline separating each:

  1. The current room's description, printed verbatim
  2. If the room is the endingRoom, print a message telling the player that they've reached the final room, and exit the program.
  3. A list of directions that the player can move.

Input

Once this message is written to the console, your program should read a line of input from the user.

  1. If that line is either of the words quit or exit, then you should exit the program.
  2. If that line starts with go some_direction, and some_direction is the name of one of the directions they can travel from that room, you should move the player in that direction and repeat the output/input process. If some_direction does not match any of the possible directions, you should print I can't go some_direction!
  3. If the user inputs something that isn't one of the commands above, you should print out I don't understand , followed by what the user typed surrounded in single quotes.

Your code should be able to handle any case of input commands, but when echoing back a user's input, it should use the original capitalization.

Example

You are on Matthews, outside the Siebel Center
Your journey begins here
From here, you can go: East
> go EAST
You are in the west entry of Siebel Center. You can see the elevator, the ACM office, and hallways to the north and east.
From here, you can go: West, Northeast, North, or East
> GO NoRtH
You are in the north hallway. You can see Siebel 1105 and Siebel 1112.
From here, you can go: South
> go TO HECK!
I can’t go TO HECK!
You are in the north hallway. You can see Siebel 1105 and Siebel 1112.
From here, you can go: South
> gophers ARE tasty!
I don’t understand ’gophers ARE tasty!’
You are in the north hallway. You can see Siebel 1105 and Siebel 1112.
From here, you can go: South
> go South
You are in the west entry of Siebel Center. You can see the elevator, the ACM office, and hallways to the north and east.
From here, you can go: West, Northeast, North, or East
> EXIT

Process finished with exit code 0

Deliverables and Grading

The primary deliverable for this assignment is the game program. The requirements for the program are listed below:

  1. At run time, download and parse JSON from a URL.
  2. Correctly display the description/direction options for the current room.
  3. Handle the user-directed navigation between rooms.
  4. Start the game from the correct startingRoom, and end the game when the endingRoom is reached.
  5. Allow users to specify an alternate URL on the command line to get the room descriptions. Gracefully detect and handle the case where they're provided a bad URL.

Other things we will take into consideration:

You are still expected to write unit tests for this project. Some parts of this project might be difficult to test; therefore, your challenge is to figure out how to structure your code in such a way that much of it can be tested. That said, some things (like reading input from the user with a Scanner) are too difficult to reasonably test automatically; if in doubt, ask on Piazza whether something is considered "testable" or not.

Try to make commits at regular intervals. You want to leave a clear trail of discrete pieces of progress that you've made as you work. Commits are cheap! Make lots of them. Once again, try to involve testing in your code development process; you don't have to write all of your tests before the code, but you should try to develop your code alongside your tests and vice versa.

Use your best judgement to write the cleanest code you can; make sure you can justify any design decisions you make in code review.

This is a test of your problem-solving skills: if you don't know how to do something (for example, setting command line arguments in IntelliJ,) you should try your favorite search engine. (Make sure you follow our policy on citing online code.) If you're still stuck, consider Piazza and office hours.