lib/ep-codebreaker/game.rb in ep-codebreaker-0.2.0 vs lib/ep-codebreaker/game.rb in ep-codebreaker-0.2.1
- old
+ new
@@ -70,9 +70,25 @@
def high_scores(file_name = 'scores.yml')
process_file file_name
end
+ def as_json
+ {
+ result: nil,
+ hint: nil,
+ tries_left: @tries_left,
+ hints_left: @hints_left,
+ finished: finished?,
+ won: won?,
+ answer: answer
+ }
+ end
+
+ def to_json(*options)
+ as_json.to_json(*options)
+ end
+
private
def check_input(code_chars, input_chars)
num_of_pluses = LENGTH.times.count { |i| code_chars[i] == input_chars[i] }