diff --git a/hangman/.gitignore b/hangman/.gitignore new file mode 100644 index 0000000..ccb5b85 --- /dev/null +++ b/hangman/.gitignore @@ -0,0 +1,345 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/linux,macos,ruby,java,rails,node,react +# Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,ruby,java,rails,node,react + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Node ### +# Logs +logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +### Node Patch ### +# Serverless Webpack directories +.webpack/ + +# Optional stylelint cache + +# SvelteKit build / generate output +.svelte-kit + +### Rails ### +*.rbc +capybara-*.html +.rspec +/db/*.sqlite3 +/db/*.sqlite3-journal +/db/*.sqlite3-[0-9]* +/public/system +/coverage/ +/spec/tmp +*.orig +rerun.txt +pickle-email-*.html + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# TODO Comment out this rule if you are OK with secrets being uploaded to the repo +config/initializers/secret_token.rb +config/master.key + +# Only include if you have production secrets in this file, which is no longer a Rails default +# config/secrets.yml + +# dotenv, dotenv-rails +# TODO Comment out these rules if environment variables can be committed +.env*.local + +## Environment normalization: +/.bundle +/vendor/bundle + +# these should all be checked in to normalize the environment: +# Gemfile.lock, .ruby-version, .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc + +# if using bower-rails ignore default bower_components path bower.json files +/vendor/assets/bower_components +*.bowerrc +bower.json + +# Ignore pow environment settings +.powenv + +# Ignore Byebug command history file. +.byebug_history + +# Ignore node_modules + +# Ignore precompiled javascript packs +/public/packs +/public/packs-test +/public/assets + +# Ignore yarn files +/yarn-error.log + +# Ignore uploaded files in development +/storage/* +!/storage/.keep +/public/uploads + +### react ### +.DS_* +**/*.backup.* +**/*.back.* + +node_modules + +*.sublime* + +psd +thumb +sketch + +### Ruby ### +*.gem +/.config +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +# Used by dotenv library to load environment variables. +# .env + +# Ignore Byebug command history file. + +## Specific to RubyMotion: +.dat* +.repl_history +build/ +*.bridgesupport +build-iPhoneOS/ +build-iPhoneSimulator/ + +## Specific to RubyMotion (use of CocoaPods): +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# vendor/Pods/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +/.bundle/ +/lib/bundler/man/ + +# for a library or gem, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# Gemfile.lock +# .ruby-version +# .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: + +# Used by RuboCop. Remote config files pulled in from inherit_from directive. +# .rubocop-https?--* + +# End of https://www.toptal.com/developers/gitignore/api/linux,macos,ruby,java,rails,node,react \ No newline at end of file diff --git a/hangman/Loser.wav b/hangman/Loser.wav new file mode 100644 index 0000000..3bb129b Binary files /dev/null and b/hangman/Loser.wav differ diff --git a/hangman/Winner.wav b/hangman/Winner.wav new file mode 100644 index 0000000..e5c5c9e Binary files /dev/null and b/hangman/Winner.wav differ diff --git a/hangman/images/0.jpg b/hangman/images/0.jpg new file mode 100644 index 0000000..3c937d3 Binary files /dev/null and b/hangman/images/0.jpg differ diff --git a/hangman/images/1.jpg b/hangman/images/1.jpg new file mode 100644 index 0000000..1b4d981 Binary files /dev/null and b/hangman/images/1.jpg differ diff --git a/hangman/images/2.jpg b/hangman/images/2.jpg new file mode 100644 index 0000000..a79ba57 Binary files /dev/null and b/hangman/images/2.jpg differ diff --git a/hangman/images/3.jpg b/hangman/images/3.jpg new file mode 100644 index 0000000..5c942e5 Binary files /dev/null and b/hangman/images/3.jpg differ diff --git a/hangman/images/4.jpg b/hangman/images/4.jpg new file mode 100644 index 0000000..5a8d6eb Binary files /dev/null and b/hangman/images/4.jpg differ diff --git a/hangman/images/5.jpg b/hangman/images/5.jpg new file mode 100644 index 0000000..09e7d17 Binary files /dev/null and b/hangman/images/5.jpg differ diff --git a/hangman/images/6.jpg b/hangman/images/6.jpg new file mode 100644 index 0000000..032db0e Binary files /dev/null and b/hangman/images/6.jpg differ diff --git a/hangman/index.html b/hangman/index.html new file mode 100644 index 0000000..b50a80a --- /dev/null +++ b/hangman/index.html @@ -0,0 +1,38 @@ + + + + + + + + + + + Hangman + + + + + +
+

Hangman

+
Wrong Guesses: 0 of
+
+

+ Guess the New Zealand's 5 Biggest Cities:

+
+

The word to be guessed goes here

+ +
+ +
+ +
+ + + + + + \ No newline at end of file diff --git a/hangman/main.js b/hangman/main.js new file mode 100644 index 0000000..c5c7528 --- /dev/null +++ b/hangman/main.js @@ -0,0 +1,106 @@ +var newZealandCities = [ +"auckland", +"wellington", +"christchurch", +"hamilton", +"napierhastings", +] + +let answer = ''; +let maxWrong = 6; +let mistakes = 0; +let guessed = []; +let audio; +let wordStatus = null; + +function randomWord() { + answer = newZealandCities[Math.floor(Math.random() * newZealandCities.length)]; +} + + +function generateButtons() { + let buttonsHTML = 'abcdefghijklmnopqrstuvwxyz'.split('').map(letter => + ` + + `).join(''); + document.getElementById('keyboard').innerHTML = buttonsHTML; +} + + +function handleGuess(chosenLetter) { + guessed.indexOf(chosenLetter) === -1 ? guessed.push(chosenLetter) : null; + document.getElementById(chosenLetter).setAttribute('disabled', true); + + if (answer.indexOf(chosenLetter) >= 0) { + guessedWord(); + checkIfGameWon(); + } else if (answer.indexOf(chosenLetter) === -1) { + mistakes++; + updateMistakes(); + checkIfGameLost(); + updateHangmanPicture(); + } +} + + +function updateHangmanPicture() { + document.getElementById('hangmanPic').src = './images/' + mistakes + '.jpg'; +} + + +function checkIfGameWon() { + if (wordStatus === answer) { + document.getElementById('sound-win').play(); + document.getElementById('keyboard').innerHTML = ""; + document.getElementById('keyboard').innerHTML = alert("Congratulations!You won!"); + document.getElementById('keyboard').innerHTML = "Let's Play again! "; + + + } +} + + +function checkIfGameLost() { + if (mistakes === maxWrong) { + document.getElementById('sound-lose').play(); + document.getElementById('wordSpotlight').innerHTML = 'The answer was: ' + answer; + document.getElementById('keyboard').innerHTML = alert("Better luck next time... "); + document.getElementById('keyboard').innerHTML = "Let's Play again! "; + } +} + + +function guessedWord() { + wordStatus = answer.split('').map(letter => (guessed.indexOf(letter) >= 0 ? letter : " _ ")).join(''); + + document.getElementById('wordSpotlight').innerHTML = wordStatus; +} + + +function updateMistakes() { + document.getElementById('mistakes').innerHTML = mistakes; +} + + +function reset() { + mistakes = 0; + guessed = []; + document.getElementById('hangmanPic').src = './images/0.jpg'; + + randomWord(); + guessedWord(); + updateMistakes(); + generateButtons(); +} + + +document.getElementById('maxWrong').innerHTML = maxWrong; + +randomWord(); +generateButtons(); +guessedWord();