Class: GameCreator
- Inherits:
-
Object
- Object
- GameCreator
- Defined in:
- lib/threesmodel/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
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/threesmodel/game_creator.rb', line 7 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
2 3 4 5 |
# File 'lib/threesmodel/game_creator.rb', line 2 def self.create_new_game positions = random_positions(9) create_matrix(positions) end |
.random_positions(number_of_positions) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/threesmodel/game_creator.rb', line 18 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 |