Class: Field

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

Overview

Ein Feld des Spielfelds. Ein Spielfeld ist durch die Koordinaten eindeutig identifiziert. Das type Attribut gibt an, um welchen Feldtyp es sich handelt

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, type) ⇒ Field

Konstruktor



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

def initialize(x, y, type)
  @type = type
  @x = x
  @y = y
end

Instance Attribute Details

#typeFieldType



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

def type
  @type
end

#xInteger (readonly)



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

def x
  @x
end

#yInteger (readonly)



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

def y
  @y
end

Instance Method Details

#==(other) ⇒ Boolean

Vergleicht zwei Felder. Felder sind gleich, wenn sie gleiche Koordinaten und gleichen Typ haben.



30
31
32
33
34
# File 'lib/software_challenge_client/field.rb', line 30

def ==(other)
  type == other.type &&
    x == other.x &&
    y == other.y
end

#coordinatesCoordinates



37
38
39
# File 'lib/software_challenge_client/field.rb', line 37

def coordinates
  Coordinates.new(x, y)
end

#to_sString



42
43
44
# File 'lib/software_challenge_client/field.rb', line 42

def to_s
  "Feld (#{x},#{y}), Typ = #{type}"
end