Class: EmptySpace

Inherits:
Object
  • Object
show all
Defined in:
lib/space.rb

Direct Known Subclasses

NullSpace, Piece

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ EmptySpace

Returns a new instance of EmptySpace.



4
5
6
7
# File 'lib/space.rb', line 4

def initialize(x,y)
  @x, @y = x, y
  @color = :none
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



3
4
5
# File 'lib/space.rb', line 3

def color
  @color
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/space.rb', line 17

def empty?
  color == :none 
end

#enemy_of?(piece) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/space.rb', line 21

def enemy_of?(piece)
  false
end

#friend_of?(piece) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/space.rb', line 25

def friend_of?(piece)
  false
end

#place_on(board) ⇒ Object



9
10
11
# File 'lib/space.rb', line 9

def place_on(board)
  board.board[@y][@x] = self
end

#remove_from(board) ⇒ Object



13
14
15
# File 'lib/space.rb', line 13

def remove_from(board)
  board.board[@y][@x] = EmptySpace.new(@x, @y)
end

#to_coordObject



29
30
31
# File 'lib/space.rb', line 29

def to_coord
  [@x, @y]
end

#to_sObject



33
34
35
# File 'lib/space.rb', line 33

def to_s
  (@x + @y) % 2 == 0 ? "__" : "##"
end