OOP Snowman

Snowman
You will be creating the popular game of Snowman as a JavaScript console game!
Make sure you break the problem down and timebox. You are encouraged to base your solution on the functions/objects below (You don't have to write the objects/functions in order , but make a plan on how to tackle this project in small steps and commit often)
Note: It is encouraged that you follow the basic structure/recommended functions below. But if you work out a different solution to acomplish game play that's ok! Roll with it!
words
An array called words containing words to be guessed. Start simple by just having your player guess a single word. Later on, you can refactor your code so that your player is guessing phrases. But for now keep it simple
chooseWord()
A function that returns a random word from the word array
game
An object literal that has the following attributes
guessesa number
guessedLettersan array of strings
isOver()a function that checks whether to play another round, depending if the game is won, the game is lost, or the game can still be played (not won and still less than 10 guesses)
Suggested functionality:
returns true if the word is fully guessed : run the function
isFound()(seeWordconstructor function )returns true if the number of guesses is 0
returns false if the game should still be in play
overMessage()returns "You win", if the word is completely guessed
returns "You lose", if
guessesis 0
Letter()
Letter is a class. In order to play Snowman, you will need information about each letter - what is its value? Is it hidden? You will also need a way to change its state (from hidden to not hidden), depending if the player has guessed the letter.
Object Attributes
valuea string
hiddena boolean ( should be set to true by default )
show()a function that will set
hiddento false
display()a function that will return
_if the letter is hidden and return the value if the letter is not hidden
Word()
Letter is a constructor function(ES5) or class(ES6). This constructor has a function to generate the Letter objects called getLetters and stores each letter as an object inside an array called letters.
Object Attributes
lettersan array of Letter objects
getLetters(newWord)accepts an input argument, a string. It will split the string into
Letterobjects and push them into thelettersarray
isFound()if true, call
overMessage()(fromgameobject) and return true if no letters are still hiddenreturns false if at least one letter is hidden
test(letter)accepts an input argument, a string goes through the Letters in the letter array and updates the
.hiddenvalue on the ones whose value matches the input argumentletterand returns a boolean indicating if the letter was found
render()returns the word in its "guessed state"
ex: for the word 'closure', if the letters l, s, and e have been guessed, this function should return the string
_ l _ s _ _ e
More game Attributes
game AttributesYou may find writing these functions inside the game object very challenging at first. Create them as global, get them working and as a stretch, refactor your code so these functions are inside the game object
startGame()
startGame is a funciton Suggested functionality:
set
guessesto tenreset the
guessedLettersarrayselect a random word from
wordsusing thechooseWord()function and set it to a variable namedcurrentWordcreate a
new Word, set it to a a variable namedcurrentGamecall
currentGame.getLetters(currentWord)to set up thecurrentGame.lettersarray. It should be an array ofLettersobjectscall playGame() once
playGame()
playGame is a function Suggested functionality:
using the
game.isOver()function, check if another round should be played or if the game is overuse if/if else/else to decide what should happen
If the game is not over:
prompt the player to enter a letter
test(letter)ifletterhasn't been tried already. Push thelettertried into the array ofguessedLettersdecrease the guess count each round
check if the game is over
game.isOver()if
truecall overMessage()if
falsecall playGame() caution this may cause an infinite loop without the correct logic
Hungry for More (choose any)
After the game is over, give the user the option to either quit or start a new game, and implement the necessary code for this feature to work
Hook it up to the DOM
Improve user experience - allow users to enter upperletters or lowercase letters, let a user know they entered an invalid character (number, symbol), let a user know they entered more than one character, add more informative prompts/alerts and more!
Switch from prompt/alert in the browser to an input field and display the game progress in the browser (render guessed word, show played letters, number of guesses left). We will be covering how to do this in class next week. But if you are excited to research and implement this on your own- go for it!
Implement ascii graphic which shows more of a snowman for each wrong guess hint hint :
_[]_ W (") |-(:')-< |(' )
Adapted from SEI-MAE and modified to Snowman by Taylor Darneille for SEIFX818
Last updated
Was this helpful?