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



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

#ownerColorPlayerColor (readonly)

Returns connection’s owner’s color.

Returns:



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

def ownerColor
  @ownerColor
end

#x1Integer (readonly)

Returns x-coordinate starting point.

Returns:

  • (Integer)

    x-coordinate starting point



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

def x1
  @x1
end

#x2Integer (readonly)

Returns y-coordinate starting point.

Returns:

  • (Integer)

    y-coordinate starting point



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

def x2
  @x2
end

#y1Integer (readonly)

Returns x-coordinate ending point.

Returns:

  • (Integer)

    x-coordinate ending point



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

def y1
  @y1
end

#y2Integer (readonly)

Returns y-coordinate ending point.

Returns:

  • (Integer)

    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_sObject



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