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
29 30 31 32 33 34 35 |
# File 'lib/software_challenge_client/connection.rb', line 29 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.
20 21 22 |
# File 'lib/software_challenge_client/connection.rb', line 20 def ownerColor @ownerColor end |
#x1 ⇒ Integer (readonly)
Returns x-coordinate starting point.
8 9 10 |
# File 'lib/software_challenge_client/connection.rb', line 8 def x1 @x1 end |
#x2 ⇒ Integer (readonly)
Returns y-coordinate starting point.
11 12 13 |
# File 'lib/software_challenge_client/connection.rb', line 11 def x2 @x2 end |
#y1 ⇒ Integer (readonly)
Returns x-coordinate ending point.
14 15 16 |
# File 'lib/software_challenge_client/connection.rb', line 14 def y1 @y1 end |
#y2 ⇒ Integer (readonly)
Returns y-coordinate ending point.
17 18 19 |
# File 'lib/software_challenge_client/connection.rb', line 17 def y2 @y2 end |
Instance Method Details
#==(another_connection) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/software_challenge_client/connection.rb', line 37 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 == c.ownerColor else return false end end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/software_challenge_client/connection.rb', line 46 def to_s return "#{self.ownerColor} : (#{self.x1}, #{self.y1}) - (#{self.x2}, #{self.y2})" end |