fork download
  1. class Hangman
  2. $contents = File.read("5desk.txt")
  3.  
  4. def initialize
  5. @number_of_guesses = 10
  6. @incorrect_letters = []
  7. @hidden_word = $contents.split.sample
  8. welcome
  9. display_view
  10. end
  11.  
  12. def welcome
  13. puts "Welcome to Hangman! Please pick the correct letters to win the game!"
  14. @input = gets.to_s.chomp
  15. end
  16.  
  17. def display_view
  18. @guessers_view = " _ " * @hidden_word.length
  19. puts "#{@guessers_view}"
  20. end
  21.  
  22. def check_input
  23. if @input.class = String && @input.size == 1
  24. if @hidden_word.chars.include?(@input)
  25. @guessers_view.each do |space|
  26. space.replace(@input)
  27. end
  28. else
  29. puts "Sorry that letter isn't in the word!"
  30. @incorrect_letters << @input
  31. end
  32. else
  33. puts "Sorry that is not a valid input, please try again"
  34. check_input
  35. end
  36. end
  37. end
  38.  
  39. game = Hangman.new
Runtime error #stdin #stdout #stderr 0.06s 9664KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.rb:2:in `read': No such file or directory @ rb_sysopen - 5desk.txt (Errno::ENOENT)
	from prog.rb:2:in `<class:Hangman>'
	from prog.rb:1:in `<main>'