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, index, direction, points) ⇒ Field

Initializer

Parameters:

  • type (FieldType)

    field type

  • x (Integer)

    x-coordinate

  • y (Integer)

    y-coordinate

  • index (Integer)

    index of tile

  • direction (Integer)

    direction of tile

  • points (Integer)

    points



36
37
38
39
40
41
42
43
# File 'lib/software_challenge_client/field.rb', line 36

def initialize(type, x, y, index, direction, points)
  self.type = type
  @x = x
  @y = y
  @index = index
  @direction = direction
  @points = points
end

Instance Attribute Details

#directionInteger (readonly)

Returns the direction of the tile which the field belongs to.

Returns:

  • (Integer)

    the direction of the tile which the field belongs to



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

def direction
  @direction
end

#indexInteger (readonly)

Returns the index of the tile which the field belongs to.

Returns:

  • (Integer)

    the index of the tile which the field belongs to



22
23
24
# File 'lib/software_challenge_client/field.rb', line 22

def index
  @index
end

#pointsInteger (readonly)

Returns the points awarded to a player placed on this field additionally to points for current tile and passengers.

Returns:

  • (Integer)

    the points awarded to a player placed on this field additionally to points for current tile and passengers



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

def points
  @points
end

#typeFieldType

Returns the field’s type.

Returns:



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

def type
  @type
end

#xInteger (readonly)

Returns the field’s x-coordinate.

Returns:

  • (Integer)

    the field’s x-coordinate



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

def x
  @x
end

#yInteger (readonly)

Returns the field’s y-coordinate.

Returns:

  • (Integer)

    the field’s y-coordinate



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

def y
  @y
end

Instance Method Details

#==(another_field) ⇒ Object



45
46
47
48
49
# File 'lib/software_challenge_client/field.rb', line 45

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

#blocked?Boolean

Returns true if the field may never be moved onto.

Returns:

  • (Boolean)

    true if the field may never be moved onto.



52
53
54
55
56
57
58
59
60
# File 'lib/software_challenge_client/field.rb', line 52

def blocked?
  [FieldType::BLOCKED,
   FieldType::PASSENGER0,
   FieldType::PASSENGER1,
   FieldType::PASSENGER2,
   FieldType::PASSENGER3,
   FieldType::PASSENGER4,
   FieldType::PASSENGER5].include? type
end

#to_sObject



62
63
64
# File 'lib/software_challenge_client/field.rb', line 62

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