Class: Piece

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

Overview

Ein Spielstein mit Ausrichtung, Koordinaten und Farbe

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color, kind, rotation = Rotation::NONE, is_flipped = false, position = Coordinates.origin) ⇒ Piece

Erstellt einen neuen leeren Spielstein.



28
29
30
31
32
33
34
35
36
# File 'lib/software_challenge_client/piece.rb', line 28

def initialize(color, kind, rotation = Rotation::NONE, is_flipped = false, position = Coordinates.origin)
  @color = color
  @kind = kind
  @rotation = rotation
  @is_flipped = is_flipped
  @position = position

  @coords = coords_priv
end

Instance Attribute Details

#colorColor (readonly)

Returns:



7
8
9
# File 'lib/software_challenge_client/piece.rb', line 7

def color
  @color
end

#coordsObject (readonly)

Returns the value of attribute coords.



25
26
27
# File 'lib/software_challenge_client/piece.rb', line 25

def coords
  @coords
end

#DrehungRotation (readonly)

Returns:



15
# File 'lib/software_challenge_client/piece.rb', line 15

attr_reader :rotation

#FarbeColor (readonly)

Returns:



7
# File 'lib/software_challenge_client/piece.rb', line 7

attr_reader :color

#FormPieceShape (readonly)

Returns:



11
# File 'lib/software_challenge_client/piece.rb', line 11

attr_reader :kind

#is_flippedBoolean (readonly)

Returns:

  • (Boolean)


19
20
21
# File 'lib/software_challenge_client/piece.rb', line 19

def is_flipped
  @is_flipped
end

#kindPieceShape (readonly)

Returns:



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

def kind
  @kind
end

#KoordinatenCoordinates (readonly)

Returns:



23
# File 'lib/software_challenge_client/piece.rb', line 23

attr_reader :position

#Ob der Stein an der Y-Achse gespiegelt ist(derSteinanderY-Achsegespiegeltist) ⇒ Boolean (readonly)

Returns:

  • (Boolean)


19
# File 'lib/software_challenge_client/piece.rb', line 19

attr_reader :is_flipped

#positionCoordinates (readonly)

Returns:



23
24
25
# File 'lib/software_challenge_client/piece.rb', line 23

def position
  @position
end

#rotationRotation (readonly)

Returns:



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

def rotation
  @rotation
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/software_challenge_client/piece.rb', line 38

def ==(other)
  color == other.color &&
    kind == other.kind &&
    rotation == other.rotation &&
    is_flipped == other.is_flipped &&
    position == other.position
end

#inspectObject



50
51
52
# File 'lib/software_challenge_client/piece.rb', line 50

def inspect
  to_s
end

#to_sObject



46
47
48
# File 'lib/software_challenge_client/piece.rb', line 46

def to_s
  "#{color.key} #{kind.key} at #{position} rotation #{rotation.key}#{is_flipped ? ' (flipped)' : ''}"
end