Class: Lekanmastermind::Computer
- Inherits:
-
Object
- Object
- Lekanmastermind::Computer
- Defined in:
- lib/lekanmastermind/computer.rb
Instance Attribute Summary collapse
-
#level_colors ⇒ Object
readonly
Returns the value of attribute level_colors.
-
#number_of_character ⇒ Object
readonly
Returns the value of attribute number_of_character.
-
#number_of_colors ⇒ Object
readonly
Returns the value of attribute number_of_colors.
Instance Method Summary collapse
- #computer_guess ⇒ Object
-
#initialize(num_of_colors:, num_of_char:) ⇒ Computer
constructor
A new instance of Computer.
- #random_colour_char ⇒ Object
Constructor Details
#initialize(num_of_colors:, num_of_char:) ⇒ Computer
Returns a new instance of Computer.
4 5 6 7 8 9 |
# File 'lib/lekanmastermind/computer.rb', line 4 def initialize(num_of_colors:, num_of_char:) @number_of_colors = num_of_colors @number_of_character = num_of_char colors = %w(Red Blue Green Yellow Orange Indigo Violet Cyan Purple) @level_colors = colors.shuffle[0...@number_of_colors] end |
Instance Attribute Details
#level_colors ⇒ Object (readonly)
Returns the value of attribute level_colors.
3 4 5 |
# File 'lib/lekanmastermind/computer.rb', line 3 def level_colors @level_colors end |
#number_of_character ⇒ Object (readonly)
Returns the value of attribute number_of_character.
3 4 5 |
# File 'lib/lekanmastermind/computer.rb', line 3 def number_of_character @number_of_character end |
#number_of_colors ⇒ Object (readonly)
Returns the value of attribute number_of_colors.
3 4 5 |
# File 'lib/lekanmastermind/computer.rb', line 3 def number_of_colors @number_of_colors end |
Instance Method Details
#computer_guess ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/lekanmastermind/computer.rb', line 11 def computer_guess computer_colors = '' number_of_character.times do computer_colors << random_colour_char end computer_colors.downcase end |
#random_colour_char ⇒ Object
19 20 21 22 |
# File 'lib/lekanmastermind/computer.rb', line 19 def random_colour_char colour_index = Random.new.rand(number_of_colors) @level_colors[colour_index][0] end |