Class: JustChess::Piece
- Inherits:
-
BoardGameGrid::Piece
- Object
- BoardGameGrid::Piece
- JustChess::Piece
- Defined in:
- lib/just_chess/pieces/piece.rb
Overview
Piece
A piece that can move on a chess board
Instance Attribute Summary collapse
-
#has_moved ⇒ Boolean
(also: #has_moved?)
readonly
Determines if the piece has moved.
Instance Method Summary collapse
-
#as_json ⇒ Hash
returns a serialized piece as a hash.
-
#has_not_moved? ⇒ TrueClass, FalseClass
Has the piece not moved yet?.
-
#initialize(id:, player_number:, type: nil, has_moved: false) ⇒ Piece
constructor
A new instance of Piece.
-
#moved ⇒ TrueClass
mark the piece as moved.
Constructor Details
#initialize(id:, player_number:, type: nil, has_moved: false) ⇒ Piece
Returns a new instance of Piece.
9 10 11 12 13 |
# File 'lib/just_chess/pieces/piece.rb', line 9 def initialize(id: , player_number: , type: nil, has_moved: false) @id = id @player_number = player_number @has_moved = has_moved end |
Instance Attribute Details
#has_moved ⇒ Boolean (readonly) Also known as: has_moved?
Returns determines if the piece has moved.
16 17 18 |
# File 'lib/just_chess/pieces/piece.rb', line 16 def has_moved @has_moved end |
Instance Method Details
#as_json ⇒ Hash
returns a serialized piece as a hash
36 37 38 39 40 41 42 43 |
# File 'lib/just_chess/pieces/piece.rb', line 36 def as_json { id: id, player_number: player_number, type: type, has_moved: has_moved? } end |
#has_not_moved? ⇒ TrueClass, FalseClass
Has the piece not moved yet?
29 30 31 |
# File 'lib/just_chess/pieces/piece.rb', line 29 def has_not_moved? !has_moved? end |
#moved ⇒ TrueClass
mark the piece as moved
22 23 24 |
# File 'lib/just_chess/pieces/piece.rb', line 22 def moved @has_moved = true end |