Class: MastermindRuby::ConsoleInterface
- Inherits:
-
Object
- Object
- MastermindRuby::ConsoleInterface
- Defined in:
- lib/mastermind_ruby/console_interface.rb
Overview
Must have methods
-
:read_playername
-
:read_next_guess
-
:read_code_length
-
:display_welcome_message
-
:display_assessment
-
:display_invalid_code
Instance Method Summary collapse
-
#display_assessment(result) ⇒ Object
- Method which is called when the guess is evaluated Params:
result -
the result (e.g. BBW-, ATTENTION: Code object).
- Method which is called when the guess is evaluated Params:
-
#display_end_game(try_count) ⇒ Object
- Method which is called when the game is ended Params:
try_count -
how many times guessed until finished.
- Method which is called when the game is ended Params:
-
#display_invalid_code ⇒ Object
Method which is called when the guess was not a valid code.
-
#display_welcome_message(playername) ⇒ Object
- 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.
- Method which is called when the game is initiated to display the game has been started Params:
-
#read_code_length ⇒ Object
Method which reads the code length Return the length of the code you want as an Fixnum.
-
#read_next_guess(try_count) ⇒ Object
- Method which is called when the next turn is initiated Return next guess as Code object Params:
try_count -
what number of guess.
- Method which is called when the next turn is initiated Return next guess as Code object Params:
-
#read_playername ⇒ Object
Method which reads the playername Return the playername as string.
Instance Method Details
#display_assessment(result) ⇒ Object
Method which is called when the guess is evaluated Params:
result-
the result (e.g. BBW-, ATTENTION: Code object)
59 60 61 |
# File 'lib/mastermind_ruby/console_interface.rb', line 59 def display_assessment(result) puts (result) end |
#display_end_game(try_count) ⇒ Object
Method which is called when the game is ended Params:
try_count-
how many times guessed until finished
71 72 73 |
# 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 |
#display_invalid_code ⇒ Object
Method which is called when the guess was not a valid code
64 65 66 |
# File 'lib/mastermind_ruby/console_interface.rb', line 64 def display_invalid_code puts 'Invalid code' end |
#display_welcome_message(playername) ⇒ Object
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
51 52 53 54 |
# File 'lib/mastermind_ruby/console_interface.rb', line 51 def (playername) puts "Hello #{playername}, your code is generated!" puts "Avaliable Characters:\t#{MastermindRuby::Code::AVAILABLE_CHARACTERS.join("\t")} (Case insensitive)" end |
#read_code_length ⇒ Object
Method which reads the code length Return the length of the code you want as an Fixnum
29 30 31 32 33 34 35 36 37 |
# 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 |
#read_next_guess(try_count) ⇒ Object
Method which is called when the next turn is initiated Return next guess as Code object Params:
try_count-
what number of guess
43 44 45 46 |
# File 'lib/mastermind_ruby/console_interface.rb', line 43 def read_next_guess(try_count) print "#{try_count}: " MastermindRuby::Code.parse(gets.strip) end |
#read_playername ⇒ Object
Method which reads the playername Return the playername as string
21 22 23 24 25 |
# File 'lib/mastermind_ruby/console_interface.rb', line 21 def read_playername # User inital input print 'Please enter a name: ' gets.chomp end |