Class: Connection
- Inherits:
-
Object
- Object
- Connection
- Defined in:
- lib/software_challenge_client/connection.rb
Overview
A connection between two fields owned by a specific player
Instance Attribute Summary collapse
-
#ownerColor ⇒ PlayerColor
readonly
Connection’s owner’s color.
-
#x1 ⇒ Integer
readonly
X-coordinate starting point.
-
#x2 ⇒ Integer
readonly
Y-coordinate starting point.
-
#y1 ⇒ Integer
readonly
X-coordinate ending point.
-
#y2 ⇒ Integer
readonly
Y-coordinate ending point.
Instance Method Summary collapse
- #==(another_connection) ⇒ Object
-
#initialize(x1, y1, x2, y2, ownerColor) ⇒ Connection
constructor
Initializer.
- #to_s ⇒ Object
Constructor Details
#initialize(x1, y1, x2, y2, ownerColor) ⇒ Connection
Initializer
30 31 32 33 34 35 36 |
# File 'lib/software_challenge_client/connection.rb', line 30 def initialize(x1, y1, x2, y2, ownerColor) @x1 = x1 @x2 = x2 @y1 = y1 @y2 = y2 @ownerColor = ownerColor end |
Instance Attribute Details
#ownerColor ⇒ PlayerColor (readonly)
Returns connection’s owner’s color.
21 22 23 |
# File 'lib/software_challenge_client/connection.rb', line 21 def ownerColor @ownerColor end |
#x1 ⇒ Integer (readonly)
Returns x-coordinate starting point.
9 10 11 |
# File 'lib/software_challenge_client/connection.rb', line 9 def x1 @x1 end |
#x2 ⇒ Integer (readonly)
Returns y-coordinate starting point.
12 13 14 |
# File 'lib/software_challenge_client/connection.rb', line 12 def x2 @x2 end |
#y1 ⇒ Integer (readonly)
Returns x-coordinate ending point.
15 16 17 |
# File 'lib/software_challenge_client/connection.rb', line 15 def y1 @y1 end |
#y2 ⇒ Integer (readonly)
Returns y-coordinate ending point.
18 19 20 |
# File 'lib/software_challenge_client/connection.rb', line 18 def y2 @y2 end |
Instance Method Details
#==(another_connection) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/software_challenge_client/connection.rb', line 38 def ==(another_connection) if (self.x1 == another_connection.x1 && self.y1 == another_connection.y1 && self.x2 == another_connection.x2 && self.y2 == another_connection.y2 || self.x1 == another_connection.x2 && self.y1 == another_connection.y2 && self.x2 == another_connection.x1 && self.y2 == another_connection.y1) return ownerColor == another_connection.ownerColor else return false end end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/software_challenge_client/connection.rb', line 53 def to_s return "#{self.ownerColor} : (#{self.x1}, #{self.y1}) - (#{self.x2}, #{self.y2})" end |