Method: PGN::Game#play

Defined in:
lib/pgn/game.rb

#playObject

Interactively step through the game

Use d to move forward, a to move backward, and ^C to exit.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/pgn/game.rb', line 128

def play
  index = 0
  hist = Array.new(3, '')

  loop do
    puts "\e[H\e[2J"
    puts positions[index].inspect
    hist[0..2] = (hist[1..2] << STDIN.getch)

    case hist.join
    when LEFT
      index -= 1 if index > 0
    when RIGHT
      index += 1 if index < moves.length
    when EXIT
      break
    end
  end
end