As a personal goal and to get back into programming, I spent the summer learning how to code using Ruby through App Academy Open. To get more practice, I was challenged by a friend to create this Hangman-inspired game. The game has a simple interface and is run through a Command Line Interface.
For this program, I learned about simple game design.
It also implements the knowledge I had learned in Ruby to complete several tasks:
Below is a short snippet of code for error-checking the user’s input:
#check to make sure that user entered appropriate guesses. Loops if otherwise.
def inputcheck(guess,letter_track)
guess = gets.chomp
while !Alphabet.include?(guess)
puts "Invalid input"
puts
print "Please choose a letter: "
guess = gets.chomp
end
if !is_include?(letter_track,guess)
letter_track << guess + " "
else
while is_include?(letter_track,guess) || !Alphabet.include?(guess)
puts
this = !Alphabet.include?(guess)? "Invalid input" : "You have already guessed this letter. "
puts this
print "Please try a different guess: "
guess = gets.chomp
end
letter_track << guess + " "
end
guess
end
You can view the source code at Source Code.