Class: EatTheOcean::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/eat_the_ocean/map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ Map

Returns a new instance of Map.



5
6
7
8
9
10
11
# File 'lib/eat_the_ocean/map.rb', line 5

def initialize(size)
  @size = size
  @grid_array = []
  @num_of_spaces = "  " * @size
  self.grid_create
  self.border_create
end

Instance Attribute Details

#grid_arrayObject

Returns the value of attribute grid_array.



3
4
5
# File 'lib/eat_the_ocean/map.rb', line 3

def grid_array
  @grid_array
end

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'lib/eat_the_ocean/map.rb', line 3

def size
  @size
end

Instance Method Details

#border_createObject



25
26
27
28
29
30
31
32
# File 'lib/eat_the_ocean/map.rb', line 25

def border_create
  border_string = ""
  (@size+1).times do |x|
    border_string << "🌊 "
  end
  @grid_array[0] = border_string
  @grid_array[size + 2] = border_string
end

#grid_createObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/eat_the_ocean/map.rb', line 13

def grid_create
  @grid_array[1] = "🌞 1"
  (@size - 1).times do |x|
    @grid_array[1] << " " + @grid_array[1][-1].next
  end

  @grid_array[2] = "A" + @num_of_spaces
  3.upto(3 + @size - 1) do |x|
    @grid_array[x] = @grid_array[x-1][0].next + @num_of_spaces
  end
end

#grid_mark(coordinate, marker_type) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/eat_the_ocean/map.rb', line 34

def grid_mark(coordinate, marker_type)
  @grid_array.each do |x|
    if coordinate[0] == x[0]
      x[coordinate[1].to_i * 2] = marker_type
    end
  end  
end