Class: ChessVwong::Piece

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

Direct Known Subclasses

Bishop, King, Knight, Pawn, Queen, Rook

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_space, color) ⇒ Piece

Returns a new instance of Piece.



5
6
7
8
9
# File 'lib/chess_vwong/piece.rb', line 5

def initialize(current_space, color)
  @current_space = current_space
  @color = color
  @neighbours = []  
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



3
4
5
# File 'lib/chess_vwong/piece.rb', line 3

def color
  @color
end

#current_spaceObject

Returns the value of attribute current_space.



4
5
6
# File 'lib/chess_vwong/piece.rb', line 4

def current_space
  @current_space
end

#neighboursObject

Returns the value of attribute neighbours.



4
5
6
# File 'lib/chess_vwong/piece.rb', line 4

def neighbours
  @neighbours
end

Instance Method Details

#characterObject



16
17
18
# File 'lib/chess_vwong/piece.rb', line 16

def character
  return color
end

#valid_space?(space) ⇒ Boolean

Ensuring the pieces can’t go off board

Returns:

  • (Boolean)


12
13
14
# File 'lib/chess_vwong/piece.rb', line 12

def valid_space?(space)
  true if space.all? {|coordinate| coordinate >= 1 && coordinate <9} 
end