An interactive terminal game with JavaScript classes and user input
In this project, I build an interactive terminal game. The scenario is that the player has lost their hat in a field full of holes, and they must navigate back to it without falling down one of the holes or stepping outside of the field.
The project is centered on a Field class. Use a two-dimensional array representing the “field” itself. A field consists of a grid containing:
- “holes” (
O
) - one “hat” (
^
) - a neutral background character (
░
) to indicate the rest of the field itself. - The player will begin in the upper-left of the field, and the player’s path is represented by (
*
).
.generateField()
static method should at least take arguments for height and width of the field, and it should return a randomized two-dimensional array representing the field with a hat and one or more holes.
extra: add a third argument used to determine what percent of the field should be covered in holes.
The game should be playable by users:
- When a user runs main.js, they should be prompted for input and be able to indicate which direction they’d like to “move”.
- After entering an instruction, the user should see a printed result of their current field map with the tiles they have visited marked with
*
. They should be prompted for their next move.
This should continue until the user either:
- Wins by finding their hat.
- Loses by landing on (and falling in) a hole.
- Attempts to move “outside” the field.
- JavaScript
- Node.js
- prompt-sync 4 - (A sync prompt for node)
To run this project, install it locally using npm:
$ cd ../[directory]
$ npm install
$ node main.js