_________ |/ | _ | (_) __ _ _ __ __ _ _ _| | __ _ _ __ | \|/ / _` | '_ \ / _` | | | | |/ _` | '__| | | | (_| | | | | (_| | |_| | | (_| | | | / \ \__,_|_| |_|\__, |\__,_|_|\__,_|_| | |___/ |___ hang-man
This lab is a chance to use the skills you've developed so far and play with angular. You'll be making an in-browser hang-man game. By the end of this lesson you should be able to:
- Build a working object oriented hangman game using concepts we've already covered such as
ng-model
to get use inputng-controller
to organize your codeng-repeat
to visualize a collectionng-change
to fire an event
- clone this repo (or fork & clone)
- open index.html and app.js
- open hangman.js and read it's contents
Most of the game code itself has been given to you. Let's check it out using dev tools. Open index.html and in the browser console try the following:
hangman = new HangmanGame('test');
You should have a new instance of a game. Now try running:
hangman.guess('x');
hangman.guess('t');
hangman.isWinner();
Note what is returned, and what changes on hangman
. You'll use this inside your angular controller.
Let's get angular setup in our app.
bower install
your front-end assets- add
ng-app
in the appropriate location and set it equal to your "hangmanApp" - register a new controller with your application called "HangmanController" and use it in the view
- in the controller instantiate a new game instance,
new HangmanGame('elephant')
, and pass it to the view - a
HangmanGame
instance providesguesses
,completedWord
andtriesRemaining
properties. Add these in the appropriate parts of the html using expressions to get the values from the hangmanGame to display on the page.- Hint: You might not be able to see the guesses until you make some. We don't have
an interface for that yet, but we can add a couple of guesses right in the controller. You can try calling
.guess('f')
on your game instance inside the controller.console.log as needed
. - Note:
completedWord
is a string containing guessed characters that match, in their correct positions. E.g. if you guessed 'b' and 'r' for 'rabbit', it shows: 'r_bb__'
- Hint: You might not be able to see the guesses until you make some. We don't have
an interface for that yet, but we can add a couple of guesses right in the controller. You can try calling
- autofocus to the input field
- use
ng-model
to track the input field's value - use
ng-change
to call a function when the input changes and pass in the input's value- write a helper function in your controller that is passed into the view, i.e.
guessLetter
. - the input should be cleared after each character is typed
- write a helper function in your controller that is passed into the view, i.e.
- add the class "glyphicon-ok" to the span with class "glyphicon" if the game is won
- add the class "glyphicon-remove" to the span with class "glyphicon" if the game is lost
The guesses on the page is kinda ugly. Let's fix it.
- change the list of guesses to display using
ng-repeat
- improve the looks of anything else as desired
Accomplish the following features on your own or in a pair. User can...
- enter an uppercase word that's treated as a lower case word
- be challenged with a random word from a list of words
- restart the game after win/lose
- keep score of games won and lost
- see a drawing of the hangman as the game progresses (extra bonus)