Info Lectures Assignments Staff Office Hours Hall of Fame Notes
Info Lectures Assignments Staff Office Hours Hall of Fame Notes

Amazing Adventures Part 2

Assigned: 2020-02-19
Due Date: 2019-02-25 by 11:59PM U.S. Central Time

Assignment

Refactor, improve, and extend the adventure game from two weeks ago to support adding and removing items from rooms. Also, build a web server to allow your game to be played from the browser.

Before you start, you will need to create a new branch on your amazing-adventures GitHub repository. We suggest naming it part-2, or something similar.

The rubric can be found here.

The user interface (UI) for Part 3 option 2 can be found here: https://courses.engr.illinois.edu/cs126/sp2020/adventure/#/.

Suggestions on how to test I/O can be found here: https://github.com/CS126SP20/NumberGuesser

Gradescope

There is no autograder for this assignment, but you still must submit your GitHub repository to Gradescope. When submitting to Gradescope, make sure you use the correct branch.

Goals

Getting Started

You will develop this assignment in the same repository as last week, using your existing code. You should a) create a new branch in your repository, and b) work, commit, and push your engine modifications to that branch (and not to the master branch). See here and here for some instructions that may help.

Part 1: Improving Your Code

Review your original Amazing Adventures feedback in Gradescope and implement the changes that your moderator suggested. Make sure you click through each section of the Gradescope rubric to see comments specific to each topic.

Part 2: Extending the Game, I

Loading the JSON

Your game engine must be able to support loading JSON either from a local file or from a URL on the Internet, and gracefully handle the situations when an error occurs. With Jackson, here is how to read from a URL:

URL url = new URL("https://courses.grainger.illinois.edu/cs126/sp2020/resources/siebel.json");
Layout layout = new ObjectMapper().readValue(url, Layout.class);

You will need to accomplish this task using command-line arguments.

Support for new commands

You will need to support the following commands:

Example

You are on Matthews, outside the Siebel Center
From here, you can go: East
Items visible: coin
> add laptop
> examine
You are on Matthews, outside the Siebel Center
From here, you can go: East
Items visible: coin, laptop
> add laptop
The item 'laptop' is already in this room.
> 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
Items visible: sweatshirt, key
> remove phone
There is no item 'phone' to remove.
> remove sweatshirt
> examine
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
Items visible: key
> go wesT
You are on Matthews, outside the Siebel Center
From here, you can go: East
Items visible: coin, laptop
...

This is just an example implementation: your game does not need to have the exact same text as shown above.

Part 3: Choose One

For part 3, you will have the option to choose one of the following extensions.

Option 1: Custom Extensions

You must extend your game engine in a substantial and interesting way. You should create your own map following the JSON schema from Amazing Adventures part 1. You are allowed to extend the JSON schema in order to make your extensions work.

The extension must be of sufficient complexity and technical difficulty; if you are unsure whether your extension meets that criteria, make a private post on Piazza. Extensions that are trivial will receive a reduced grade.

Examples of reasonable extensions include:

Be creative!

Option 2: Web Server

See the template repository here for the files you will need for the server. In particular, your project structure should look something like this:

.
├── pom.xml
├── README.md
└── src
    ├── main
    │   ├── java
    │   │   ├── Main.java
    │   │   └── student
    │   │       ├── adventure
    │   │       │   ├── Adventure.java
    │   │       │   ├── Direction.java
    │   │       │   ├── Layout.java
    │   │       │   └── Room.java
    │   │       └── server
    │   │           ├── AdventureResource.java
    │   │           ├── AdventureService.java
    │   │           ├── CS126Server.java
    │   │           ├── Requests.java
    │   │           └── Responses.java
    │   └── resources
    │       ├── client.cert
    │       ├── keystore_client
    │       ├── keystore_server
    │       ├── server.cert
    │       ├── truststore_client
    │       └── truststore_server
    └── test
        └── java
            └── student
                ├── adventure
                │   └── AdventureTest.java
                └── server
                    └── ServerTest.java

12 directories, 20 files

Don't worry if your project structure doesn't exactly match what is above. The main idea is that the new files should be placed in the correct location. After you finish adding these files and fixing any resulting compile errors, make sure to commit and push your changes.

(Optional Read) More about servers, HTTP, REST APIs, SSL, etc.

For this assignment, you will be creating an HTTPS REST server for your adventure game. The agreed upon communication is a REST API, which is detailed at the Swagger page mentioned below. This setup is very, very, ..., very common practice for any software engineering role.

The development of the Adventure UI is called frontend development: you won't need to do this for this assignment since someone else has already created the UI. The development of the Adventure server is called backend development: this is what this part is all about. If you were to develop the frontend and the backend yourself, this is called full-stack development.

Since the course website is using HTTPS, most browsers do not allow any requests using HTTP (insecure) coming from HTTPS. So your server needs SSL certificates. But most browsers only trust certificates that are signed by a trusted authority. Unfortunately, getting certificates signed by trusted sources costs money and is not really needed in the development phase. So, we created our own certificates and self-signed them. Most browsers recognize that while the HTTPS server we are implemented does have certificates, the certificates are self-signed, so you should proceed at your own risk since the communication might not be secure (private).

The server code that was given isn't thread-safe, but you need not worry about this for this assignment. If you want to know how to make it thread-safe, look into AtomicInteger, and the synchronized keyword in Java.

Also, here is the Adventure UI code, if you are curious about it. Note that looking through this code isn't required at all.


Some definitions:

  • HTTP: HyperText Transfer Protocol - a protocol for distributed information systems
  • API: Application Programming Interface - a communication protocol between different parts of a computer program
  • REST: REpresentational State Transfer - a software architectural style that defines a set of constraints to be used for creating web services
  • SSL: Secure Sockets Layer - a cryptographic protocol designed to provide communications security over a computer network
  • HTTPS: HyperText Transfer Protocol Secure - an extension of HTTP designed for secure communication using SSL
  • Server - a computer program or a device that provides functionality for other programs or devices, called clients
  • UI: User Interface - an interface to allow humans and computers to interact

After the above is complete, start the server and visit the following url: https://localhost:8080/adventure/v1/ping. This is where your server is running on your computer. You should see something saying "Your connection is not private. danger blah blah security blah blah risk blah ...". You need to click "Advanced/Show Details" and proceed to "localhost (unsafe)/Accept the risk and continue/Visit this website". Then you'll see a blank screen or some text; this means you are ready to begin testing out the UI. To see more about why your browser is warning you, see the section on "More about servers, ..., SSL, ...".

WARNING: If you are running Mac OS and facing problems, please read @405 on Piazza.

You need to utilize your Adventure game engine to implement the methods in src/main/java/student/server/AdventureService.java. You may need to change some of the code in src/main/java/student/server/AdventureResource.java to get the code to compile.

You can find descriptions about what each of the methods should do here. You will also be able to test your game engine server using that site or the Swagger UI.

To start up the server, you will need to do the following:

HttpServer server = CS126Server.createServer(AdventureResource.class);
server.start();

We have given you most of the code for the server. All that needs to be done here is to connect the web server with your Adventure game engine.

You can test different JSON files by specifying the url query parameter, like the following:

https://courses.engr.illinois.edu/cs126/sp2020/adventure/#/?url=https://pastebin.com/raw/9kX4Kidz

There are even host and port query parameters that can be used to specify the server the UI should attempt to connect to. By default, host=localhost and port=8080.

Extra Credit

Here are some suggestions for more extra credit points:

  1. Create your own adventure map that follows the schema given in the amazing-adventures assignment. Upload this JSON file to pastebin and post the raw link to Piazza under the assignment release post. For example, here is the link to the siebel.json JSON file on pastebin: https://pastebin.com/raw/4Nvtn5JV.
  2. Implement a map verifier that determines if it is always possible to get from room A to room B for any rooms A and B in the map.
  3. Write code to play and win your adventure game. You might want to look at some maze-finding algorithms.
  4. Use an API to detect foul language. For example: http://www.purgomalum.com/service/containsprofanity?text=covfefe.

Deliverables and Grading

  1. Improve your code by reading and implementing the changes your moderator suggested. Your engine still must support all of the features from last week's assignment (movement, traversing from start to finish)
  2. Add support for loading an adventure game JSON either from a URL or a local file, specifically using command-line arguments
  3. Add support for adding and removing arbitrary items
  4. Either (pick one):
    1. Add your own non-trivial extension to the game
    2. Create a web server and verify that all of the methods work so that the UI is playable

Other things we will take into consideration:

  • Is the code well-organized? Is there a logical separation of behaviors into different classes and methods?
  • Is the code tested?
  • Would the code work with a different adventure game? If we gave you an alternate JSON file (with the same schema), could your engine play that game?
  • Is indentation, whitespace, and brace placement consistent with the Google Style Guide? Are lines kept under 100 characters long?

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.

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/or Office Hours.