Class: Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/software_challenge_client/connection.rb

Overview

A connection between two fields owned by a specific player

Author:

  • Ralf-Tobias Diekert

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x1, y1, x2, y2, ownerColor) ⇒ Connection

Initializer

Parameters:

  • x1 (Integer)

    x-coordinate starting point

  • y1 (Integer)

    y-coordinate starting point

  • x2 (Integer)

    x-coordinate ending point

  • y2 (Integer)

    y-coordinate ending point

  • owner (PlayerColor)

    connection’s owner’s color



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

#ownerColorPlayerColor (readonly)

Returns connection’s owner’s color.

Returns:



21
22
23
# File 'lib/software_challenge_client/connection.rb', line 21

def ownerColor
  @ownerColor
end

#x1Integer (readonly)

Returns x-coordinate starting point.

Returns:

  • (Integer)

    x-coordinate starting point



9
10
11
# File 'lib/software_challenge_client/connection.rb', line 9

def x1
  @x1
end

#x2Integer (readonly)

Returns y-coordinate starting point.

Returns:

  • (Integer)

    y-coordinate starting point



12
13
14
# File 'lib/software_challenge_client/connection.rb', line 12

def x2
  @x2
end

#y1Integer (readonly)

Returns x-coordinate ending point.

Returns:

  • (Integer)

    x-coordinate ending point



15
16
17
# File 'lib/software_challenge_client/connection.rb', line 15

def y1
  @y1
end

#y2Integer (readonly)

Returns y-coordinate ending point.

Returns:

  • (Integer)

    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_sObject



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