Class: Field

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

Overview

A field on the game board

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, x, y) ⇒ Field

Initializer

Parameters:

  • type (FieldType)

    field type

  • x (Integer)

    x-coordinate

  • y (Integer)

    y-coordinate



25
26
27
28
29
30
# File 'lib/software_challenge_client/field.rb', line 25

def initialize(type, x, y)
  self.ownerColor = PlayerColor::NONE
  self.type = type
  @x = x
  @y = y
end

Instance Attribute Details

#ownerColorPlayerColor

Returns the field’s owner’s color.

Returns:



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

def ownerColor
  @ownerColor
end

#typePlayerColor

Returns the field’s type.

Returns:



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

def type
  @type
end

#xInteger (readonly)

Returns the field’s x-coordinate.

Returns:

  • (Integer)

    the field’s x-coordinate



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

def x
  @x
end

#yInteger (readonly)

Returns the field’s y-coordinate.

Returns:

  • (Integer)

    the field’s y-coordinate



18
19
20
# File 'lib/software_challenge_client/field.rb', line 18

def y
  @y
end

Instance Method Details

#==(another_field) ⇒ Object



32
33
34
35
36
37
# File 'lib/software_challenge_client/field.rb', line 32

def ==(another_field)
  return self.ownerColor == another_field.ownerColor && 
    self.type == another_field.type && 
    self.x == another_field.x && 
    self.y == another_field.y
end

#to_sObject



39
40
41
# File 'lib/software_challenge_client/field.rb', line 39

def to_s
  return "Field: x = #{self.x}, y = #{self.y}, owner = #{self.ownerColor}, type = #{self.type}"
end