Class: MineField::Point
- Inherits:
-
Object
- Object
- MineField::Point
- Defined in:
- lib/mine_field/point.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#coordinate_x ⇒ Object
readonly
Returns the value of attribute coordinate_x.
-
#coordinate_y ⇒ Object
readonly
Returns the value of attribute coordinate_y.
-
#opened ⇒ Object
Returns the value of attribute opened.
Instance Method Summary collapse
-
#initialize(map, x, y, content) ⇒ Point
constructor
A new instance of Point.
- #neighbors ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(map, x, y, content) ⇒ Point
6 7 8 9 10 11 12 |
# File 'lib/mine_field/point.rb', line 6 def initialize(map, x, y, content) @coordinate_x = x @coordinate_y = y @content = content @opened = false @map = map end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
3 4 5 |
# File 'lib/mine_field/point.rb', line 3 def content @content end |
#coordinate_x ⇒ Object (readonly)
Returns the value of attribute coordinate_x.
3 4 5 |
# File 'lib/mine_field/point.rb', line 3 def coordinate_x @coordinate_x end |
#coordinate_y ⇒ Object (readonly)
Returns the value of attribute coordinate_y.
3 4 5 |
# File 'lib/mine_field/point.rb', line 3 def coordinate_y @coordinate_y end |
#opened ⇒ Object
Returns the value of attribute opened.
4 5 6 |
# File 'lib/mine_field/point.rb', line 4 def opened @opened end |
Instance Method Details
#neighbors ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mine_field/point.rb', line 14 def neighbors items = [] ((@coordinate_x - 1)..(@coordinate_x + 1)).each do |x| ((@coordinate_y - 1)..(@coordinate_y + 1)).each do |y| point = @map.get_point(x, y) items.push(point) unless point.nil? end end items end |
#to_s ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mine_field/point.rb', line 27 def to_s if @opened if @content == MINE_CHARACTER MINE_CHARACTER else neighbors.select {|p| p.content == MINE_CHARACTER}.count.to_s end else NOT_OPENED_CHARACTER end end |