Class: Pitchcar::Pieces::Straight

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

Direct Known Subclasses

Start, StraightLeftWall, StraightRightWall

Constant Summary collapse

IMAGE =
Magick::Image.read(File.expand_path('../images/straight_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



21
22
23
24
# File 'lib/pieces/straight.rb', line 21

def image
  return IMAGE.rotate(90) if north? || south?
  IMAGE
end

#next_coordinateObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pieces/straight.rb', line 9

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

#next_directionObject



5
6
7
# File 'lib/pieces/straight.rb', line 5

def next_direction
  direction
end

#to_sObject



26
27
28
# File 'lib/pieces/straight.rb', line 26

def to_s
  'S'
end