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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, piece = nil, fishes = 0) ⇒ Field

Erstellt ein neues leeres Feld.



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

def initialize(x, y, piece = nil, fishes = 0)
  @piece = piece
  @fishes = fishes
  @coords = Coordinates.new(x, y)
end

Instance Attribute Details

#coordsCoordinates (readonly)



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

def coords
  @coords
end

#fishesInteger



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

def fishes
  @fishes
end

#piecePiece



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

def piece
  @piece
end

Instance Method Details

#==(other) ⇒ Boolean

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



33
34
35
# File 'lib/software_challenge_client/field.rb', line 33

def ==(other)
  !other.nil? && coords == other.coords && piece == other.piece
end

#empty?Boolean



57
58
59
# File 'lib/software_challenge_client/field.rb', line 57

def empty?
  piece.nil? && fishes == 0
end

#free?Boolean



62
63
64
# File 'lib/software_challenge_client/field.rb', line 62

def free?
  piece.nil? && fishes != 0
end

#teamTeam



48
49
50
51
52
53
54
# File 'lib/software_challenge_client/field.rb', line 48

def team
  if piece.nil?
    nil
  else
    piece.team
  end
end

#to_sString



67
68
69
# File 'lib/software_challenge_client/field.rb', line 67

def to_s
  piece.nil? ? fishes.to_s : piece.to_ss
end

#xInteger



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

def x
  coords.x
end

#yInteger



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

def y
  coords.y
end