class MastermindRuby::ConsoleInterface
Must have methods
-
:read_playername
-
:read_next_guess
-
:read_code_length
-
:display_welcome_message
-
:display_assessment
-
:display_invalid_code
Public Instance Methods
Method which is called when the guess is evaluated Params:
result
-
the result (e.g. BBW-, ATTENTION:
Code
object)
# File lib/mastermind_ruby/console_interface.rb, line 59 def display_assessment(result) puts (result) end
Method which is called when the game is ended Params:
try_count
-
how many times guessed until finished
# File lib/mastermind_ruby/console_interface.rb, line 71 def display_end_game(try_count) puts "Congrats! You made it with #{try_count} tries." end
Method which is called when the guess was not a valid code
# File lib/mastermind_ruby/console_interface.rb, line 64 def display_invalid_code(code) puts 'Invalid code' end
Method which is called when the game is initiated to display the game has been started Params:
playername
-
the playername which was read before with :read_playername
# File lib/mastermind_ruby/console_interface.rb, line 51 def display_welcome_message(playername) puts "Hello #{playername}, your code is generated!" puts "Avaliable Characters:\t#{MastermindRuby::Code::AVAILABLE_CHARACTERS.join("\t")} (Case insensitive)" end
Method which reads the code length Return the length of the code you want as an Fixnum
# File lib/mastermind_ruby/console_interface.rb, line 29 def read_code_length print 'How long should the code be (Hit enter for default): ' code = gets.strip.to_i if code != 0 code else 4 end end
Method which is called when the next turn is initiated Return next guess as Code
object Params:
try_count
-
what number of guess
# File lib/mastermind_ruby/console_interface.rb, line 43 def read_next_guess(try_count) print "#{try_count}: " MastermindRuby::Code.parse(gets.strip) end
Method which reads the playername Return the playername as string
# File lib/mastermind_ruby/console_interface.rb, line 21 def read_playername # User inital input print 'Please enter a name: ' gets.chomp end