Class: MM::Pegs
- Inherits:
-
Object
- Object
- MM::Pegs
- Defined in:
- lib/games/mastermind/pegs.rb
Instance Attribute Summary collapse
-
#collection_of_pegs ⇒ Object
readonly
Returns the value of attribute collection_of_pegs.
Instance Method Summary collapse
- #current_row(number_of_turns_taken) ⇒ Object
- #display_values ⇒ Object
-
#initialize(args) ⇒ Pegs
constructor
collection_of_pegs is a multi-dimensional array.
- #result_values ⇒ Object
- #retrieve_peg(row, col) ⇒ Object
Constructor Details
#initialize(args) ⇒ Pegs
collection_of_pegs is a multi-dimensional array
7 8 9 |
# File 'lib/games/mastermind/pegs.rb', line 7 def initialize(args) @collection_of_pegs = args[:collection_of_pegs] end |
Instance Attribute Details
#collection_of_pegs ⇒ Object (readonly)
Returns the value of attribute collection_of_pegs.
3 4 5 |
# File 'lib/games/mastermind/pegs.rb', line 3 def collection_of_pegs @collection_of_pegs end |
Instance Method Details
#current_row(number_of_turns_taken) ⇒ Object
19 20 21 |
# File 'lib/games/mastermind/pegs.rb', line 19 def current_row(number_of_turns_taken) collection_of_pegs[number_of_turns_taken] end |
#display_values ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/games/mastermind/pegs.rb', line 23 def display_values # reversed so that game appears to be filling itself in from top to bottom collection_of_pegs.reverse.map do |row| row.map do |peg| peg.display_value end end end |
#result_values ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/games/mastermind/pegs.rb', line 32 def result_values collection_of_pegs.reverse.map do |row| row.map do |peg| peg.result_value end end end |
#retrieve_peg(row, col) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/games/mastermind/pegs.rb', line 11 def retrieve_peg(row, col) if row >= number_of_rows || col >= number_of_cols return nil else return collection_of_pegs[row][col] end end |