Class: ChessVwong::Piece
- Inherits:
-
Object
- Object
- ChessVwong::Piece
- Defined in:
- lib/chess_vwong/piece.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#current_space ⇒ Object
Returns the value of attribute current_space.
-
#neighbours ⇒ Object
Returns the value of attribute neighbours.
Instance Method Summary collapse
- #character ⇒ Object
-
#initialize(current_space, color) ⇒ Piece
constructor
A new instance of Piece.
-
#valid_space?(space) ⇒ Boolean
Ensuring the pieces can’t go off board.
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
#color ⇒ Object (readonly)
Returns the value of attribute color.
3 4 5 |
# File 'lib/chess_vwong/piece.rb', line 3 def color @color end |
#current_space ⇒ Object
Returns the value of attribute current_space.
4 5 6 |
# File 'lib/chess_vwong/piece.rb', line 4 def current_space @current_space end |
#neighbours ⇒ Object
Returns the value of attribute neighbours.
4 5 6 |
# File 'lib/chess_vwong/piece.rb', line 4 def neighbours @neighbours end |
Instance Method Details
#character ⇒ Object
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
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 |