Class: Field
- Inherits:
-
Object
- Object
- Field
- Defined in:
- lib/software_challenge_client/field.rb
Overview
A field on the game board.
Instance Attribute Summary collapse
-
#direction ⇒ Integer
readonly
The direction of the tile which the field belongs to.
-
#index ⇒ Integer
readonly
The index of the tile which the field belongs to.
-
#points ⇒ Integer
readonly
The points awarded to a player placed on this field additionally to points for current tile and passengers.
-
#type ⇒ FieldType
The field’s type.
-
#x ⇒ Integer
readonly
The field’s x-coordinate.
-
#y ⇒ Integer
readonly
The field’s y-coordinate.
Instance Method Summary collapse
- #==(another_field) ⇒ Object
-
#blocked? ⇒ Boolean
True if the field may never be moved onto.
-
#initialize(type, x, y, index, direction, points) ⇒ Field
constructor
Initializer.
- #to_s ⇒ Object
Constructor Details
#initialize(type, x, y, index, direction, points) ⇒ Field
Initializer
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
#direction ⇒ Integer (readonly)
Returns 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 |
#index ⇒ Integer (readonly)
Returns 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 |
#points ⇒ Integer (readonly)
Returns 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 |
#type ⇒ FieldType
Returns the field’s type.
8 9 10 |
# File 'lib/software_challenge_client/field.rb', line 8 def type @type end |
#x ⇒ Integer (readonly)
Returns the field’s x-coordinate.
11 12 13 |
# File 'lib/software_challenge_client/field.rb', line 11 def x @x end |
#y ⇒ Integer (readonly)
Returns 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.
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_s ⇒ Object
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 |