Class: MM::Pegs

Inherits:
Object
  • Object
show all
Defined in:
lib/games/mastermind/pegs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pegsObject (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_valuesObject



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_valuesObject



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