class JustCheckers::Piece
Game State¶ ↑
A piece that can move on a checkers board
Attributes
id[R]
@return [Fixnum] the unique id of the piece.
king[R]
@return [Boolean] set to true if the piece has been crowned.
king?[R]
@return [Boolean] set to true if the piece has been crowned.
player_number[R]
@return [Fixnum] the owner of the piece.
Public Class Methods
new(id: , player_number: , king: false)
click to toggle source
New objects can be instantiated by passing in a hash with
@param [Fixnum] id
the unique id of the piece.
@param [Fixnum] player_number
the owner of the piece.
@option [Boolean] king
set to true if the piece has been crowned.
Example:¶ ↑
# Instantiates a new Piece JustCheckers::Piece.new({ player_number: 1, king: false })
# File lib/just_checkers/piece.rb, line 24 def initialize(id: , player_number: , king: false) @id = id @player_number = player_number @king = king end
Public Instance Methods
as_json()
click to toggle source
returns a serialized piece as a hash
@return [Hash]
# File lib/just_checkers/piece.rb, line 59 def as_json { id: id, player_number: player_number, king: king } end
direction()
click to toggle source
the direction forward on the board, 1 for moving down, -1 for moving up.
@return [Fixnum]
# File lib/just_checkers/piece.rb, line 52 def direction @player_number == 1 ? 1 : -1 end
promote()
click to toggle source
promotes the piece by setting the king
attribute to true.
@return [TrueClass]
# File lib/just_checkers/piece.rb, line 44 def promote @king = true end