Introduction

You work with the given project londonStart. This is yet another variant of the game of Zuul that is described in Chapter 8 of the module text book. This variant uses a different scenario, namely some parts of London. You will extend the project towards a more interesting game.

Note the difference in class structure. There is a split between the classes Game and GameMain. The latter is the textual user interface of the game, the former is the actual game independent of any particular user interface (we could use it for example with a graphical user interface where commands are selected from menus). Note that the classes Game plus Room are not dependent on any other class. Furthermore, commands are structured rather differently from the book, using lambdas. All knowledge about the command language is in the Parser. Start by familiarising yourself with the source files of the project.

The project contains assertions for some contracts and a small test class. You should never remove these (you can add to them, but this is not required). You may have to modify existing tests when adding a new functionality changes an expected result in a test.

Note that there are dependencies between the tasks given below, but it is possible to do some of them in a different order.

The assessment will be marked out of 100 and provisional marks have been associated with the individual components.

Make sure that you do not only write code, but that you also write or update appropriate comments for all classes and methods. Furthermore, you have to keep to the program style guide of the book. After marking out of 100 as indicated below, between 0% and 20% may be subtracted if you violate the style guide. In extreme cases even more than 20% can be subtracted.

Adding a Goal

The aim of the game shall be to reach the Trafalgar Square. After the player has entered Trafalgar Square a congratulatory message shall be printed and the game ends.

All your changes will be in the Game class. You will need a new field in the class. To implement the new functionality, make changes in the goRoom method.

Adding Time

Playing the game shall have a time limit. Do not use real time but instead count the number of "go" commands. The initial time limit shall be 12. If the goal has not been reached within the time limit, then the player loses. Losing means that a corresponding message is printed and the game ends.

Note that if in the last time step the player reaches the goal, then the player should win, not lose because time runs out.

Make only changes in the class Game and keep them minimal.

Adding a look Command

Add the command look to the commands that the game understands. The purpose of look is to print out the description of the room and the exits again (we "look around the room"). This could be helpful if we have entered a sequence of commands in a room so that the description has scrolled out of view and we cannot remember where the exits of the current room are.

You will have to make a small change in class Game and modify the class Parser.

Adding Items

An item has a description. In the following we assume that the description always is a single word.

To simplify future extensions, write a new enumeration class Item. This class shall use parameterised values, like the command interface described in Section 8.13.2 of our text book. The class contains the description. Its toString() method shall return the description. Define three different Item objects: SANDWICH, CRISPS and a DRINK.

Note that in the following we assume that any item appears only once in the whole game.

Adding Characters

A character has a description. In the following we assume that the description always is a single word. A character holds one or zero items.

To simplify future extensions, write a new enumeration class Character. This class shall use parameterised values, like the command interface described in Section 8.13.2 of our text book. The class contains the description and an item; the latter may be null. Its toString() method shall return the description and the description of the item that it holds (if it holds an item).

Define four different Character objects: LAURA, SALLY, ANDY and ALEX. Give each one item; one character gets no item. You can freely choose the allocation.

Additionally the class shall have a take(Item item) method, which takes the indicated item from the character, if the character has that item. Also the method returns true, if it is successful in taking the item from the character, and false otherwise.

Note that in the following we assume that any character appears only once in the whole game.

Adding Characters to Rooms

We extend the game such that each character is in a room. Extend the class Room with a field such that a room can contain zero or many characters. Add a method addCharacter that adds a character to a room. Extend the getLongDescription method to include a list of all the characters in the room (using their toString() method). Add a take(Item item) method, which takes the indicated item from any character in the room, if some character has that item. Also the method returns true, if it is successful in taking the item from a character, and false otherwise.

Finally, in the game, add the four characters to any rooms of your choice.

Adding a take Command

The player shall be able to carry any number of items.

Add a method to the class Game for the player to take an Item object from a character in the current room. If the item is not in the current room, then the take method should return an appropriate message. If the take method is successful, then it removes the item from the room and returns an appropriate message. So overall the returned message either confirms the action or states why it could not be done.

Subsequently add a take command to the whole game. By entering the command take item the player takes item in the current room. Here item shall be the description of an item.

Adding an eat Command

If the player has sandwich, crisps and a drink when the eat command is executed, then the game shall end with a congratulatory message. If not all conditions are met, then only an appropriate message is printed and the game continues.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.