First, lay out all the actions that need to take place in order for the game to function correctly.
We need:
- A prompt to ask the question
- A function that initiates the game actions and invokes other functions needed to make it work
- A function to check if it's a valid input (This will be a conditional)
- A function to check if it's a legal move (This will be a conditional)
- A function that moves the piece from one array to another(this will only run if the other conditionals return true)
- A function that checks if a win condition has been met
- A function that restarts the game
For any invalid inputs or illegal moves we need to inform the user with console.log that the move was not valid or legal, and then we reset the prompt.
- Towers of Hanoi is a simple logic game involving three stacks. The first stack has four (or more) blocks, each one bigger than the next, stacked like a pyramid. The point of the game is to move the blocks from one stack and arrange them in the same order into another stack, but never placing a larger block onto a smaller block. You can play the game here to get an idea.
Your checkpoint is really a terminal app; which is what you'll be graded on. However, you should push to use the DOM and create a GUI for this game.
- 20pts - Code Plan - Include this in a
README.md
file in your folder with comments in your code - 10pts - Move Blocks - User can move "blocks" from column to column
- 20pts - Illegal Moves - Prevents larger blocks from stacking on smaller blocks
- 20pts - Notifies winner - When all the blocks are stacked into column 2 or 1 the user is alerted they won!
- 20pts - Minimum 3 Unit Tests - Should be attached to your file the same way Tic, Tac, Toe, PigLatin or Rock Paper Scissors is done.
- 10pts - Graphical User Interface - Take this game out of the terminal by adding a User Interface that uses
towersOfHanoi()
function inindex.js
.
- Extended Practice Bonus!!
- Keeps count of moves as player plays games
- Sound Effects
- Peaceful Background
- Vertical columns
- Proportional Stones/tokens
Dissect the following game to get an insight on how to build Towers of Hanoi with a GUI
- Once you understand the game, whiteboard the logic.
- Create a list of steps your app need to do.
- Translate to psuedo code.
- Translate to JavaScript on paper
- Write 3 tests for the app.
- Build Towers of Hanoi, so it passes all the tests.
- Create a new branch called " checkpoint-1 "
- Build toward the tests.
- Use the starter code below:
- Fork and Clone Towers of Hanoi Repo
- Ensure you have installed all dependencies/packages:
npm i
- Look at the Unit Test, see what is being called, passed as input arguments, and what the expected result are.
- Ensure you know how to run the unit test:
npm test main.js
- Use a whiteboard to work out a solution to building the Pig Latin program
- Translate the broad ideas to psuedo code
- Convert the psuedo code to real JavaScript Code
- Type into your text editor the JavaScript code you've come up with one step at a time
- Work through your bugs.
- Use
node main.js
to run the game. - Achieve green checks for each of your unit tests.
- Run your unit tests first!!
- Use repl.it to write the solution code first. (its a faster environment vs using the
node main.js
command over and over again.) - Read the comments in
main.js
- Push yourself further.
- Look at your hints!
- Clone, setup, testing, and running instructions for all projects is below
-
Click the 'Fork' button (choose your account if prompted).
-
Copy HTTPS URL from your forked repository
-
In your terminal/gitBash/CommandPrompt navigate (using
cd
) into a directory where you want to start keeping your repositories. (/jsDevFolder
) -
Clone your new repository by typing
git clone <forked clone URL>
(the HTTPS URL you copied above) -
Now go into the new directory by using
cd project-repo
-
Add the base repository as an upstream
git remote add upstream https://github.com/AustinCodingAcademy/<PROJECT-REPO>.git
-
Check the configuration of your remotes with
git remote -v
, it should look very similar to this (except it'll be YOUR username)
$ git remote -v
origin [email protected]:username/javascript-workbook.git (fetch)
origin [email protected]:username/javascript-workbook.git (push)
upstream [email protected]:AustinCodingAcademy/javascript-workbook.git (fetch)
upstream [email protected]:AustinCodingAcademy/javascript-workbook.git (push)
-
From your project directory, run
npm i
to tell NPM to install all the node modules we use in this class (seepackage.json
) -
Use your textEditor (VS Code) to change your files.
-
When you're finished
git status
, stage your filegit add .
, commit your changesgit commit -m "functions working"
, and push to GitHubgit push
bash git status git add . git commit -m "Initial Commit" git push origin gh-pages
-
Now go to your forked repository on GitHub (at https://github.com/your-username/javascript-workbook). A little yellow box should have popped up asking you to make a Pull Request. Click to review.
-
Click "Create Pull Request"
-
Every time you make a change and push to GitHub, this PR will automatically update. No need to do it more than once.
-
To get the latest code/homework/test updates, be sure to have a "clean working directory" by committing or removing all of your changes. You check for a "clean working environment" by running
git status
and making sure no files show up. -
Run
git pull upstream gh-pages
Simply run node path/to/file.js
example node 01week/rockPaperScissors.js
Tests are a great way to make sure you code works the way you planned it would, and to make sure you don't break something in the future. We will be using them to test our understanding of the lesson. It's also our main way to assign grades for an assignment.
To run a the tests on a file run npm test path/to/file.js
, etc.
Simply run npm run lint
- Run
npm start
- To break out of the server, press
ctrl
+c