Skip to content

mattsteen14/findyourhat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn

Find Your Hat Node.js Game

Codecademy Full Stack Engineer path - Challenge Project
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Roadmap
  4. Contributing
  5. License
  6. Contact
  7. Acknowledgments

About The Project

Codecademy Project Brief

"In this project, you’ll be building 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.

  1. In order to start this project, you should have completed lessons at least through Classes in our Introduction to JavaScript curriculum.

In this project, you’ll be building an interactive terminal game with JavaScript classes. Because the goal involves user input, make sure you read our guide on working with user input in Node.js. If you complete this project on our platform, you can test and run your code with the command node main.js in our terminal.

  1. Your project is centered on a Field class. This and the following tasks will describe how the class should function at a high level, and it will be up to you to figure out the implementation in code. As you go, test your code by creating instances of the class and calling its methods.

The Field constructor should take a two-dimensional array representing the “field” itself. A field consists of a grid containing “holes” (O) and one “hat” (^). We use 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 *.

*░O
░O░
^

Your class should take a single argument representing the field:

const myField = new Field([
['*', '░', 'O'],
['░', 'O', '░'],
['░', '^', '░'],
]);
  1. Give your Field class a .print() method that prints the current state of the field. You can choose to format this however you want, but it will be much easier to play the game if you print out a string representation of the board instead of the raw array.

  2. Your game should be playable by users. In order to facilitate this, build out the following behavior:

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. When any of the above occur, let the user know and end the game.

  1. Add a .generateField() method to your Field class. This doesn’t need to be tied to a particular instance, so make it a static method of the class itself.

This 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. In our solution, we added a third percentage argument used to determine what percent of the field should be covered in holes."

My Comments

This was such a fun project. I don't do this very often with the Codecademy challenge/portfolio projects but I found myself getting sidetracked and playing around before I had completed all of the basic tasks. As I was working on task 4 I ended up adding functionality to the resetField helper so that the player can customise their field if they choose to play again. At one point I started playing with randomly generating the field. As I was looking at the task 7 extension tasks, I saw the 'create a hard mode' bullet point and that lead to me implementing a prompt for the player to choose their difficulty level. I will definitely have a go at the task 7 extension tasks. I've put them in my read me roadmap section. Through playing the game myself I definitely think that the field validator would be much needed. Often it generates fields that are impossible to play as it puts loads of holes around the hat, especially in the harder difficulties. So I need to sort that out.

Update - Successfully been able to get the player/pathCharacter to start on a random location, not the upper left corner. For this I made randomX & randomY consts with Math.random * width & height respectfully which I then passed in as the indexes for playerPosition & pathCharacter. Then to ensure that the holes & hat don't go on the playerPosition I changed the while conditions from checking that x & y are at 0 (top left corner) to randomX & randomY, the playerPosition/pathCharacter allocation.

(back to top)

Built With

(back to top)

Getting Started

These are instructions on setting up the project locally. To get a local copy up and running follow these simple example steps.

Prerequisites

This is an example of how to list things you need to use the software and how to install them.

  • npm
    npm install npm@latest -g

Installation

  1. Clone the repo

    git clone https://github.com/mattsteen14/ca-findyourhat.git
  2. Install NPM packages

    npm install
  3. Call the program in node to play the game

    node main.js
  4. Follow the command prompts

  5. To exit game if needed

    ctrl+C

(back to top)

Roadmap

  • Complete project as per brief.
  • Add new features to game.
  • Share on Codecademy forums for feedback.
  • Have the character start on a random location that’s not the upper-left corner.
  • Create a “hard mode” where one or more holes are added after certain turns.
  • Improve your game’s graphics and interactivity in the terminal.
  • Create a field validator to ensure that the field generated by Field.generateField() can actually be solved.
  • Testing & Debugging.
  • Use surge to deploy.

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Matt Steen-Brookes - @mattsteen14 - mattsteen14@me.com

Project Link: https://github.com/mattsteen14/ca-findyourhat

(back to top)

Acknowledgments

(back to top)

About

Interactive terminal game made with Node.js. Codecademy challenge project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors