Skip to content

Instantly share code, notes, and snippets.

@bbatsche
Last active October 30, 2015 16:21
Show Gist options
  • Save bbatsche/8dbe5444b64c8d8fa030 to your computer and use it in GitHub Desktop.
Save bbatsche/8dbe5444b64c8d8fa030 to your computer and use it in GitHub Desktop.
"use strict";
var Hangman = {
words: [], // Set of words for hangman to choose from
currentWord: '', // Current word for the game
correctGuesses: [], // Correct letters the user has guesses
incorrectGuesses: [], // Wrong letters the user has guessed
maxGuesses: 0, // Maximum number of wrong guesses the user is allowed
/**
* Do all the initial game setup, register any necessary event listeners.
* This method should only be run once.
*/
init: function() {
},
/**
* Start a new game. Should be used whenever a new hangman game is begun.
*/
gameStart: function() {
},
/**
* The game has finished, do any necessary cleanup.
*/
gameEnd: function() {
},
/**
* Event handler for when a keyboard key is pressed.
*
* @param Event event - JavaScript event object
*/
keyPressHandler: function(event) {
},
/**
* Random number generator, should return an integer between min and max.
*
* @param integer min
* @param integer max
*
* @return integer
*/
getRandomInt: function(min, max) {
},
/**
* Check if the user has guessed a given letter before (either right or wrong).
*
* @param string letter - Letter the user typed
*
* @return boolean
*/
hasLetterBeenGuessed: function(letter) {
},
/**
* Return whether or not a letter is in the current word.
*
* @param string letter - Letter the user typed
*
* @return boolean
*/
isLetterInWord: function(letter) {
},
/**
* Return the indexes where a given letter occurs in the current word
* For example, if the word is "banana", and the letter passed was "a"
* then this function should return [1, 3, 5].
*
* @param string letter - Letter the user typed
*
* @return array - Array of indexes in the word
*/
findLetterInWord: function(letter) {
},
/**
* Add a letter to the array of correct guesses and handle any additional steps
*
* @param string letter - Letter the user typed
*/
addCorrectGuess: function(letter) {
},
/**
* Add a letter to the array of incorrect guesses and handle any additional steps
*
* @param string letter - Letter the user typed
*/
addIncorrectGuess: function(letter) {
},
/**
* Check whether all the letters in the word have been guessed
*
* @return boolean
*/
isGameWon: function() {
}
};
Hangman.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment