Answer the question
In order to leave comments, you need to log in
Program starts with error: something with 'encode' method and Windows-1251 and UTF-8 encodings in ruby on rails?
def get_letters
slovo = ARGV[0]
if (Gem.win_platform? && ARGV[0])
slovo = slovo.encode(ARGV[0].encoding, "cp1251").encode("UTF-8")
end
if (slovo == nil || slovo == "")
abort "You didn't enter a word for the game"
end
return slovo.split("")
end
def get_user_input
letter = ""
while letter == "" do
letter = STDIN.gets.encode ("UTF-8").chomp
end
return letter
end
def check_result(user_input, letters, good_letters, bad_letters)
if (good_letters.include?(user_input) ||
bad_letters.include?(user_input))
return 0
end
if letters.include? user_input
good_letters << user_input
# condition when the whole word is guessed!
if letters.uniq.size == good_letters.size
return 1
else
return 0
end
else
bad_letters << user_input
return -1
end
end
def get_word_for_print(letters, good_letters)
result = ""
for letters in letters do
if good_letters.include? letter
result += letter + " "
else
result += "__ "
end
end
return
result
end
#2.error information and already named letters
#3.errors > 7 - report defeat
#4.word guessed - report victory
def print_status(letters, good_letters, bad_letters, errors)
puts "\nWord: " + get_word_for_print(letters , good_Letters)
puts "Errors (#{errors}): #{bad_letters.join(", ")}"
if errors >= 7
puts "You lost :("
else
if letters.uniq.size == good_letters.size
puts " Congratulations! You win!\n\n"
else
puts " You have attempts left: " + (7-errors).to_s
end
end
end
def cls
system "clear"or system "cls"
end
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question