Class: EatTheOcean::Map
- Inherits:
-
Object
- Object
- EatTheOcean::Map
- Defined in:
- lib/eat_the_ocean/map.rb
Instance Attribute Summary collapse
-
#grid_array ⇒ Object
Returns the value of attribute grid_array.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #border_create ⇒ Object
- #grid_create ⇒ Object
- #grid_mark(coordinate, marker_type) ⇒ Object
-
#initialize(size) ⇒ Map
constructor
A new instance of Map.
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_array ⇒ Object
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 |
#size ⇒ Object
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_create ⇒ Object
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_create ⇒ Object
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 |