Created
August 17, 2014 15:39
-
-
Save foglabs/c84e86431b20a395e9e2 to your computer and use it in GitHub Desktop.
Hangman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pry' | |
#!/usr/bin/env ruby | |
wordbank = ['hundred', 'bozo', 'swag', 'lariat', 'bowler', 'ape', 'master'] | |
display_word = String.new | |
secret_word = String.new | |
guess = String.new | |
chances = 10 | |
#pull word from bank at random | |
secret_word = wordbank.shuffle[0] | |
display_word += "_" * secret_word.length | |
position = 0 | |
#prompt for input | |
puts "Welcome to Hangman Pro Master Suite!" | |
while chances > 0 do | |
puts "#{chances} Remaining!" | |
puts display_word | |
print "Enter a letter or try to guess the word: " | |
guess = gets.chomp.downcase | |
puts "" | |
if guess.length == 1 | |
if secret_word.include?(guess) | |
while position < secret_word.length | |
if secret_word[position] == guess | |
display_word[position] = guess | |
end | |
position +=1 | |
end | |
position = 0 | |
chances -= 1 | |
else | |
puts "Sorry folks... try again!" | |
chances -= 1 | |
end | |
elsif guess.length > 1 | |
if guess == secret_word | |
puts "You are the winner!\n Thanks for playing, folks!" | |
exit | |
end | |
chances -= 1 | |
end | |
if display_word.include?("_") == false | |
return puts "You win!" | |
end | |
end | |
puts "oooooooooooh so sad. out of guesses. better luck next time, folks." | |
#check if letter or word | |
#check against word | |
#if letter, compare with each | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment