Class: Pugnacious::GameMap

Inherits:
Object
  • Object
show all
Defined in:
lib/pugnacious/game_map.rb

Class Method Summary collapse

Class Method Details

.generate_empty_map(number_of_lines, number_of_columns) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/pugnacious/game_map.rb', line 4

def self.generate_empty_map(number_of_lines, number_of_columns)
  game_map = []
  (number_of_columns/MOLECULE_SIZE).times do |l|
    game_map << []
    (number_of_lines/MOLECULE_SIZE).times do |c|
      game_map[l][c] = [l, c]
    end
  end
  game_map
end

.generate_molecules(map, player1, player2, number) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pugnacious/game_map.rb', line 15

def self.generate_molecules(map, player1, player2, number)
  molecules = []

  positions = map.flatten(1).sample(number)

  positions[0..(number/2)].each do |p|
    molecules << Molecule.new(
      :player    => player1,
      :rival     => player2,
      :molecules => molecules,
      :pos       => p,
      :map       => map)
  end 

  positions[(number/2)..number].each do |p|
    molecules << Molecule.new(
      :player    => player2,
      :rival     => player1,
      :molecules => molecules,
      :pos       => p,
      :map       => map)
  end
  
  map.each do |l|
    l.each_with_index do |c, index| 
      if c.kind_of?(Array)
        l[index] = :empty
      end
    end
  end

  molecules
end