Welcome to App Academy Adventure! For this project, you will add different item types to a text adventure using OOP principles. Use the test specs to guide you as you work through each task described below.
- Clone the project from the starter.
- Type
node game.jsto run the project - Type
npm installto install the tests - Type
npm testto run the tests
This practice starter includes a (slightly incomplete) command line game that
you play by interacting with prompts in the terminal. First, run the game with
the command node game.js, explore the commands available, and play the game to
see how it works.
The commands are:
Controls:
Type 'h' for help
Type 'q' to quit
Type 'l' to look around
Type 'i' to check your inventory
Type 'take <item>' to take an itemIn the following phases, you will need to add functionality to the game by defining methods across multiple classes. The directions below are very brief. Use the following tips and tools to clarify the directions and better understand what you need to implement.
Browse the code that has already been defined for yu in each file in the class directory. Make sure you understand the attributes within each class.
- Look for associations between classes
- Examine the methods that have already been completed
- Note where there are methods that you will need to complete yourself
- Look for opportunities to use helper methods
The test specs themselves can help you understand the expectations. For example, look at the first test spec:
it('Item should have name and description attributes', function () {
let item = new Item("rock", "just a simple rock");
expect(item.name).to.equal("rock");
expect(item.description).to.equal("just a simple rock");
});Reading this spec should lead you to the Item class file, class/item.js.
There, you will need to define the constructor for the item class, with specific
attributes. In order for this spec to pass, you must be able to initialize a new
instance of the Item class, taking in a name and description.
If you get stuck trying to implement a method, use carefully-placed
console.log() statements to expose the values of your variables. It can be
helpful to log the value of the this keyword to better understand the context
of each method.
Your first task is to add different items to this simple adventure world by
using OOP principles. In this first phase, you will define the Item class, and
then define methods across multiple classes that refer to instances of the
Item class.
-
Fill out the constructor for the
Itemclass in class/item.js. -
Implement instance methods to get, take, and drop items. These methods should be defined within the class/room.js file and the class/player.js file.
room.getItemByName- Retrieves an item from a room by item nameplayer.getItemByName- Retrieves an item from a player's inventory by item nameplayer.takeItem- Picks up an item from the current room into the player's inventoryplayer.dropItem- Drops an item the player is holding into their current room
-
Create an edible
Foodclass that inherits from theItemclass. Make sure you are importing and exporting the appropriate modules. -
Implement the
player.eatIteminstance method to allow the player to eat food items, but not non-food items.
- Modify the
loadWorldfunction inworld.jsto create items and food items fromworld-data.js.
- A non-food item should be instantiated as an instance of the
Itemclass - A food item should be instantiated as an instance of the
Foodclass
Add new types of enemies, items and rooms. Run the game using node game.js to
see your code changes in action.# AdventureGame