Class: Pitchcar::Pieces::Right

Inherits:
Piece
  • Object
show all
Defined in:
lib/pieces/right.rb

Constant Summary collapse

IMAGE =
Magick::Image.read(File.expand_path('../images/curve_tile.png', __FILE__))[0]

Constants inherited from Piece

Piece::DIRECTIONS

Instance Attribute Summary

Attributes inherited from Piece

#direction, #type, #x, #y

Instance Method Summary collapse

Methods inherited from Piece

#coordinate, first_from_string, #initialize, #name, #to_h, type_from_string

Constructor Details

This class inherits a constructor from Pitchcar::Pieces::Piece

Instance Method Details

#imageObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pieces/right.rb', line 30

def image
  if north?
    IMAGE.rotate(90)
  elsif east?
    IMAGE.rotate(180)
  elsif west?
    IMAGE
  elsif south?
    IMAGE.rotate(270)
  end
end

#next_coordinateObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pieces/right.rb', line 18

def next_coordinate
  if north?
    { x: x + 1, y: y }
  elsif east?
    { x: x, y: y - 1 }
  elsif west?
    { x: x, y: y + 1 }
  elsif south?
    { x: x - 1, y: y }
  end
end

#next_directionObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/pieces/right.rb', line 6

def next_direction
  if north?
    DIRECTIONS[:EAST]
  elsif east?
    DIRECTIONS[:SOUTH]
  elsif west?
    DIRECTIONS[:NORTH]
  elsif south?
    DIRECTIONS[:WEST]
  end
end

#to_sObject



42
43
44
# File 'lib/pieces/right.rb', line 42

def to_s
  'R'
end