Class: Field
- Inherits:
-
Object
- Object
- Field
- 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
-
#type ⇒ FieldType
Der Typ des Feldes.
-
#x ⇒ Integer
readonly
Die X-Koordinate des Feldes (0 bis 9, 0 ist ganz links, 9 ist ganz rechts).
-
#y ⇒ Integer
readonly
Die Y-Koordinate des Feldes (0 bis 9, 0 ist ganz unten, 9 ist ganz oben).
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Vergleicht zwei Felder.
-
#coordinates ⇒ Coordinates
Die Koordinaten des Feldes als Koordinatenpaar.
-
#initialize(x, y, type) ⇒ Field
constructor
Konstruktor.
-
#to_s ⇒ String
Textuelle Darstellung des Feldes.
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
#type ⇒ FieldType
Returns der Typ des Feldes.
9 10 11 |
# File 'lib/software_challenge_client/field.rb', line 9 def type @type end |
#x ⇒ Integer (readonly)
Returns die X-Koordinate des Feldes (0 bis 9, 0 ist ganz links, 9 ist ganz rechts).
12 13 14 |
# File 'lib/software_challenge_client/field.rb', line 12 def x @x end |
#y ⇒ Integer (readonly)
Returns die Y-Koordinate des Feldes (0 bis 9, 0 ist ganz unten, 9 ist ganz oben).
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 |
#coordinates ⇒ Coordinates
Returns Die Koordinaten des Feldes als Koordinatenpaar.
37 38 39 |
# File 'lib/software_challenge_client/field.rb', line 37 def coordinates Coordinates.new(x, y) end |
#to_s ⇒ String
Returns Textuelle Darstellung des Feldes.
42 43 44 |
# File 'lib/software_challenge_client/field.rb', line 42 def to_s "Feld (#{x},#{y}), Typ = #{type}" end |