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
-
#coordinates ⇒ CubeCoordinates
readonly
Die Cube-Coordinates des Feldes.
-
#obstructed ⇒ Boolean
readonly
Ob das Feld durch eine Brombeere blockiert ist.
-
#pieces ⇒ Array<Piece>
Spielsteine auf dem Feld, beginnend beim untersten Stein.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Vergleicht zwei Felder.
- #add_piece(piece) ⇒ Object
- #color ⇒ Object
- #empty? ⇒ Boolean
- #has_owner ⇒ Object
-
#initialize(x, y, pieces = [], obstructed = false) ⇒ Field
constructor
Konstruktor.
- #obstructed? ⇒ Boolean
- #remove_piece ⇒ Object
-
#to_s ⇒ String
Textuelle Darstellung des Feldes.
- #x ⇒ Object
- #y ⇒ Object
- #z ⇒ Object
Constructor Details
#initialize(x, y, pieces = [], obstructed = false) ⇒ Field
Konstruktor
23 24 25 26 27 |
# File 'lib/software_challenge_client/field.rb', line 23 def initialize(x, y, pieces = [], obstructed = false) @pieces = pieces @coordinates = CubeCoordinates.new(x, y) @obstructed = obstructed end |
Instance Attribute Details
#coordinates ⇒ CubeCoordinates (readonly)
Returns die Cube-Coordinates des Feldes.
11 12 13 |
# File 'lib/software_challenge_client/field.rb', line 11 def coordinates @coordinates end |
#obstructed ⇒ Boolean (readonly)
Returns ob das Feld durch eine Brombeere blockiert ist.
14 15 16 |
# File 'lib/software_challenge_client/field.rb', line 14 def obstructed @obstructed end |
#pieces ⇒ Array<Piece>
Returns Spielsteine auf dem Feld, beginnend beim untersten Stein.
8 9 10 |
# File 'lib/software_challenge_client/field.rb', line 8 def pieces @pieces end |
Instance Method Details
#==(other) ⇒ Boolean
Vergleicht zwei Felder. Felder sind gleich, wenn sie gleiche Koordinaten und gleichen Typ haben.
31 32 33 34 35 |
# File 'lib/software_challenge_client/field.rb', line 31 def ==(other) coordinates == other.coordinates && obstructed == other.obstructed && pieces == other.pieces end |
#add_piece(piece) ⇒ Object
57 58 59 |
# File 'lib/software_challenge_client/field.rb', line 57 def add_piece(piece) pieces.push(piece) end |
#color ⇒ Object
65 66 67 |
# File 'lib/software_challenge_client/field.rb', line 65 def color pieces.last&.color end |
#empty? ⇒ Boolean
49 50 51 |
# File 'lib/software_challenge_client/field.rb', line 49 def empty? pieces.empty? && !obstructed end |
#has_owner ⇒ Object
69 70 71 |
# File 'lib/software_challenge_client/field.rb', line 69 def has_owner !color.nil? end |
#obstructed? ⇒ Boolean
53 54 55 |
# File 'lib/software_challenge_client/field.rb', line 53 def obstructed? obstructed end |
#remove_piece ⇒ Object
61 62 63 |
# File 'lib/software_challenge_client/field.rb', line 61 def remove_piece pieces.pop end |
#to_s ⇒ String
Returns Textuelle Darstellung des Feldes.
74 75 76 77 78 79 80 81 |
# File 'lib/software_challenge_client/field.rb', line 74 def to_s s = "Feld #{coordinates}, " if obstructed? s += 'blockiert' else s += "Steine: #{pieces.map(&:to_s).join(', ')}" end end |
#x ⇒ Object
37 38 39 |
# File 'lib/software_challenge_client/field.rb', line 37 def x coordinates.x end |
#y ⇒ Object
41 42 43 |
# File 'lib/software_challenge_client/field.rb', line 41 def y coordinates.y end |
#z ⇒ Object
45 46 47 |
# File 'lib/software_challenge_client/field.rb', line 45 def z coordinates.z end |