Class: GameCreator
- Inherits:
-
Object
- Object
- GameCreator
- Defined in:
- lib/game_creator.rb
Class Method Summary collapse
- .create_matrix(positions) ⇒ Object
- .create_new_game ⇒ Object
- .random_positions(number_of_positions) ⇒ Object
Class Method Details
.create_matrix(positions) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/game_creator.rb', line 9 def self.create_matrix(positions) rows = [] 4.times { rows << [0,0,0,0] } positions.each {|position| rows[position[0]][position[1]] = rand(1..3) } Matrix.rows(rows) end |
.create_new_game ⇒ Object
4 5 6 7 |
# File 'lib/game_creator.rb', line 4 def self.create_new_game positions = random_positions(9) create_matrix(positions) end |
.random_positions(number_of_positions) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/game_creator.rb', line 20 def self.random_positions(number_of_positions) positions = [] while (positions.length < number_of_positions) candidate_position = [rand(0..3), rand(0..3)] unless positions.include?(candidate_position) positions << candidate_position end end positions end |