class TicTacToe::Cursor

Constants

OutOfBounds

Attributes

field[R]

Public Class Methods

new(field = nil, board) click to toggle source
# File lib/tic_tac_toe/cursor.rb, line 7
def initialize(field = nil, board)
  @field  = field || board.fields.first
  @board  = board

  raise OutOfBounds unless @board.fields.include?(@field)
end

Public Instance Methods

move(direction) click to toggle source
# File lib/tic_tac_toe/cursor.rb, line 14
def move(direction)
  send(direction)
rescue TicTacToe::Cursor::OutOfBounds
  self
end

Private Instance Methods

down() click to toggle source
# File lib/tic_tac_toe/cursor.rb, line 26
def down
  TicTacToe::Cursor.new([x + 1, y], @board)
end
left() click to toggle source
# File lib/tic_tac_toe/cursor.rb, line 34
def left
  TicTacToe::Cursor.new([x, y - 1], @board)
end
right() click to toggle source
# File lib/tic_tac_toe/cursor.rb, line 30
def right
  TicTacToe::Cursor.new([x, y + 1], @board)
end
up() click to toggle source
# File lib/tic_tac_toe/cursor.rb, line 22
def up
  TicTacToe::Cursor.new([x - 1, y], @board)
end
x() click to toggle source
# File lib/tic_tac_toe/cursor.rb, line 38
def x; field[0]; end
y() click to toggle source
# File lib/tic_tac_toe/cursor.rb, line 39
def y; field[1]; end