Class: CubeCoordinates
- Inherits:
-
Object
- Object
- CubeCoordinates
- Defined in:
- lib/software_challenge_client/cube_coordinates.rb
Overview
CubeCoordinates erleichtern viele Berechnungen auf einem hexagonalen Spielfeld. Siehe www.redblobgames.com/grids/hexagons/#coordinates-cube
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
-
#z ⇒ Object
readonly
Returns the value of attribute z.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(x, y, z = nil) ⇒ CubeCoordinates
constructor
A new instance of CubeCoordinates.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(x, y, z = nil) ⇒ CubeCoordinates
Returns a new instance of CubeCoordinates.
7 8 9 10 11 12 |
# File 'lib/software_challenge_client/cube_coordinates.rb', line 7 def initialize(x, y, z = nil) @x = x @y = y @z = z.nil? ? -x - y : z throw InvalidArgumentException("sum of coordinates #{@x}, #{@y}, #{@z} have to be equal 0") if @x + @y + @z != 0 end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
5 6 7 |
# File 'lib/software_challenge_client/cube_coordinates.rb', line 5 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
5 6 7 |
# File 'lib/software_challenge_client/cube_coordinates.rb', line 5 def y @y end |
#z ⇒ Object (readonly)
Returns the value of attribute z.
5 6 7 |
# File 'lib/software_challenge_client/cube_coordinates.rb', line 5 def z @z end |
Instance Method Details
#==(other) ⇒ Object
14 15 16 |
# File 'lib/software_challenge_client/cube_coordinates.rb', line 14 def ==(other) x == other.x && y == other.y && z == other.z end |
#inspect ⇒ Object
22 23 24 |
# File 'lib/software_challenge_client/cube_coordinates.rb', line 22 def inspect to_s end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/software_challenge_client/cube_coordinates.rb', line 18 def to_s "(#{x}, #{y}, #{z})" end |