Class: JustChess::Square
- Inherits:
-
BoardGameGrid::Square
- Object
- BoardGameGrid::Square
- JustChess::Square
- Defined in:
- lib/just_chess/square.rb
Overview
Square
A Square on a checker board
Instance Method Summary collapse
-
#initialize(id:, x:, y:, piece: nil) ⇒ Square
constructor
New objects can be instantiated by passing in a hash with.
-
#last_rank(player_number) ⇒ Boolean
Is the square the last rank for the specified player?.
-
#rank_number(player_number) ⇒ Fixnum
returns the rank number of the square for the specified player.
Constructor Details
#initialize(id:, x:, y:, piece: nil) ⇒ Square
33 34 35 36 37 38 |
# File 'lib/just_chess/square.rb', line 33 def initialize(id: , x: , y: , piece: nil) @id = id @x = x @y = y @piece = PieceFactory.new(piece).build end |
Instance Method Details
#last_rank(player_number) ⇒ Boolean
Is the square the last rank for the specified player?
54 55 56 |
# File 'lib/just_chess/square.rb', line 54 def last_rank(player_number) rank_number(player_number) == 8 end |
#rank_number(player_number) ⇒ Fixnum
returns the rank number of the square for the specified player
43 44 45 46 47 48 49 |
# File 'lib/just_chess/square.rb', line 43 def rank_number(player_number) if player_number == 1 8 - @y else @y + 1 end end |