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



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)



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

def direction
  @direction
end

#indexInteger (readonly)



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

def index
  @index
end

#pointsInteger (readonly)



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

def points
  @points
end

#typeFieldType



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

def type
  @type
end

#xInteger (readonly)



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

def x
  @x
end

#yInteger (readonly)



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



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