Class: MastermindRuby::ConsoleInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/mastermind_ruby/console_interface.rb

Overview

Must have methods

  • :read_playername

  • :read_next_guess

  • :display_welcome_message

  • :display_assessment

  • :display_invalid_code

Instance Method Summary collapse

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)



47
48
49
# File 'lib/mastermind_ruby/console_interface.rb', line 47

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



59
60
61
# File 'lib/mastermind_ruby/console_interface.rb', line 59

def display_end_game(try_count)
  puts "Congrats! You made it with #{try_count} tries."
end

#display_invalid_codeObject

Method which is called when the guess was not a valid code



52
53
54
# File 'lib/mastermind_ruby/console_interface.rb', line 52

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



38
39
40
41
42
# File 'lib/mastermind_ruby/console_interface.rb', line 38

def display_welcome_message(playername)
  puts '-------- Mastermind Ruby Project -------'
  puts "Hello #{playername}, your code is generated!"
  puts "Avaliable Characters:\t#{MastermindRuby::Code::AVAILABLE_CHARACTERS.join("\t")}"
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



30
31
32
33
# File 'lib/mastermind_ruby/console_interface.rb', line 30

def read_next_guess(try_count)
  print "#{try_count}: "
  MastermindRuby::Code.parse(gets.strip)
end

#read_playernameObject

Method which reads the playername Return the playername as string



20
21
22
23
24
# File 'lib/mastermind_ruby/console_interface.rb', line 20

def read_playername
  # User inital input
  print 'Please enter a name: '
  gets.chomp
end