Class: JustBackgammon::Piece

Inherits:
Object
  • Object
show all
Extended by:
Common
Defined in:
lib/just_backgammon/piece.rb

Overview

Piece

A piece owned by a player that moves around the board.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

load

Constructor Details

#initialize(id:, owner:) ⇒ Piece

A new instance of Piece.

Example:

# Instantiates a new Piece
JustBackgammon::Piece.new(id: 1, owner: 1)

Parameters:

  • id (Fixnum)

    The identifier of the piece.

  • owner (Fixnum)

    The owner of the piece.



22
23
24
25
# File 'lib/just_backgammon/piece.rb', line 22

def initialize(id: , owner:)
  @id = id
  @owner = owner
end

Instance Attribute Details

#idFixnum (readonly)

Returns the identifier of the piece.

Returns:

  • (Fixnum)

    the identifier of the piece.



28
29
30
# File 'lib/just_backgammon/piece.rb', line 28

def id
  @id
end

#ownerFixnum (readonly)

Returns the owner of the piece.

Returns:

  • (Fixnum)

    the owner of the piece



31
32
33
# File 'lib/just_backgammon/piece.rb', line 31

def owner
  @owner
end

Instance Method Details

#as_jsonHash

A hashed serialized representation of the piece.

Returns:

  • (Hash)


36
37
38
# File 'lib/just_backgammon/piece.rb', line 36

def as_json
  { id: id, owner: owner }
end